0.0.1 • Published 2 years ago
redbag v0.0.1
redbag
游戏
安装
npm install redbag
使用
必须开启 "enableSkia": "true"
- json
{
"usingComponents": {
"game": "redbag/index"
}
}
- mini.project.json
{
"node_modules_es6_whitelist": [
"common-game"
]
}
- js
Page({
data: {
gameSource: {
ops: {
otherNum: 4,//其他元素数量
otherStepTime: 1000,//间隔时间(毫秒)
otherRangTime: { min: 6, max: 10 },//动画时间(秒) 调整速度
bagNum: 4,//红包元素数量
bagStepTime: 1200,//间隔时间(毫秒)
bagRangTime: { min: 4, max: 8 },//动画时间(秒) 调整速度
},
// 不可点击元素
imgs: [
{ "src": "https://img.alicdn.com/imgextra/i2/2185320355/O1CN01FdSphf1EUdMEsZLCM_!!2185320355.png", "name": "2.png", "width": "116", "height": "116", val: 1, probability: 1, },
{ "src": "https://img.alicdn.com/imgextra/i4/2185320355/O1CN018MRlZc1EUdM7BI9kM_!!2185320355.png", "name": "3.png", "width": "112", "height": "112", val: 1, probability: 1, },
{ "src": "https://img.alicdn.com/imgextra/i2/2185320355/O1CN01ugjJy01EUdM9zH387_!!2185320355.png", "name": "4.png", "width": "125", "height": "126", val: 1, probability: 1, },
{ "src": "https://img.alicdn.com/imgextra/i2/2185320355/O1CN01JLDPfY1EUdM7BHYIn_!!2185320355.png", "name": "5.png", "width": "122", "height": "122", val: 1, probability: 1, },
{ "src": "https://img.alicdn.com/imgextra/i3/2185320355/O1CN018rVamG1EUdMCvmcxH_!!2185320355.png", "name": "6.png", "width": "126", "height": "126", val: 1, probability: 1, },
{ "src": "https://img.alicdn.com/imgextra/i4/2185320355/O1CN01oteJr91EUdM3OABDr_!!2185320355.png", "name": "7.png", "width": "125", "height": "124", val: 1, probability: 1, },
{ "src": "https://img.alicdn.com/imgextra/i1/2185320355/O1CN01TmWniC1EUdMDgnfpZ_!!2185320355.png", "name": "8.png", "width": "130", "height": "130", val: 1, probability: 1, },
{ "src": "https://img.alicdn.com/imgextra/i4/2185320355/O1CN01vuspKF1EUdMDgnfpd_!!2185320355.png", "name": "9.png", "width": "116", "height": "116", val: 1, probability: 1, },
{ "src": "https://img.alicdn.com/imgextra/i3/2185320355/O1CN01gXSdlb1EUdM9zvStQ_!!2185320355.png", "name": "1.png", "width": "69", "height": "110", val: 1, probability: 1, },
{ "src": "https://img.alicdn.com/imgextra/i3/2185320355/O1CN01aVydzT1EUdMDhTQtV_!!2185320355.png", "name": "2.png", "width": "81", "height": "95", val: 1, probability: 1, },
{ "src": "https://img.alicdn.com/imgextra/i3/2185320355/O1CN01RDBqwW1EUdMCwSegv_!!2185320355.png", "name": "3.png", "width": "79", "height": "47", val: 1, probability: 1, },
{ "src": "https://img.alicdn.com/imgextra/i4/2185320355/O1CN01x0UnFJ1EUdMDhTlgt_!!2185320355.png", "name": "4.png", "width": "92", "height": "104", val: 1, probability: 1, },
{ "src": "https://img.alicdn.com/imgextra/i1/2185320355/O1CN01KWonoA1EUdM460iof_!!2185320355.png", "name": "5.png", "width": "93", "height": "104", val: 1, probability: 1, },
{ "src": "https://img.alicdn.com/imgextra/i3/2185320355/O1CN01AdAjKu1EUdM8Fd0k9_!!2185320355.png", "name": "6.png", "width": "160", "height": "188", val: 1, probability: 1, },
{ "src": "https://img.alicdn.com/imgextra/i2/2185320355/O1CN01YA87dV1EUdMBj9JnD_!!2185320355.png", "name": "7.png", "width": "74", "height": "188", val: 1, probability: 1, },
],
// 可以点击的红包对象
items: [
{
src: "https://img.alicdn.com/imgextra/i4/2185320355/O1CN01LQysJX1EUdM3OsYVu_!!2185320355.png",
val: 1,
width: 89,
height: 136,
probability: 1,//出现概率
// 爆炸动画序列帧
srcArr: [
{ "src": "https://img.alicdn.com/imgextra/i2/2185320355/O1CN01ORHxDU1EUdLwwRaFZ_!!2185320355.png", "name": "光效00.png", "width": "370", "height": "370" },
{ "src": "https://img.alicdn.com/imgextra/i4/2185320355/O1CN01qR32341EUdM449rBW_!!2185320355.png", "name": "光效01.png", "width": "370", "height": "370" },
{ "src": "https://img.alicdn.com/imgextra/i1/2185320355/O1CN013uN7Sp1EUdM6Tq34a_!!2185320355.png", "name": "光效02.png", "width": "370", "height": "370" },
{ "src": "https://img.alicdn.com/imgextra/i1/2185320355/O1CN01ItRqnF1EUdMAuMB0G_!!2185320355.png", "name": "光效03.png", "width": "370", "height": "370" },
{ "src": "https://img.alicdn.com/imgextra/i2/2185320355/O1CN01OoZLwS1EUdMDfdRDV_!!2185320355.png", "name": "光效04.png", "width": "370", "height": "370" },
{ "src": "https://img.alicdn.com/imgextra/i2/2185320355/O1CN01fL37WA1EUdM6Nj8hu_!!2185320355.png", "name": "光效05.png", "width": "370", "height": "370" },
{ "src": "https://img.alicdn.com/imgextra/i2/2185320355/O1CN01s7Pxxc1EUdM8gXdtG_!!2185320355.png", "name": "光效06.png", "width": "370", "height": "370" },
{ "src": "https://img.alicdn.com/imgextra/i4/2185320355/O1CN01GApCKa1EUdM8DheHD_!!2185320355.png", "name": "光效07.png", "width": "370", "height": "370" },
{ "src": "https://img.alicdn.com/imgextra/i4/2185320355/O1CN019On5sl1EUdLwwOpky_!!2185320355.png", "name": "光效08.png", "width": "370", "height": "370" },
{ "src": "https://img.alicdn.com/imgextra/i3/2185320355/O1CN012BWXaD1EUdM1pFVsa_!!2185320355.png", "name": "光效09.png", "width": "370", "height": "370" },
{ "src": "https://img.alicdn.com/imgextra/i4/2185320355/O1CN01GyX2X21EUdM6NjLC5_!!2185320355.png", "name": "光效10.png", "width": "370", "height": "370" },
{ "src": "https://img.alicdn.com/imgextra/i4/2185320355/O1CN014abS8r1EUdM6TqzGd_!!2185320355.png", "name": "光效11.png", "width": "370", "height": "370" },
{ "src": "https://img.alicdn.com/imgextra/i2/2185320355/O1CN01UrBnd61EUdMCudGVb_!!2185320355.png", "name": "光效12.png", "width": "370", "height": "370" },
{ "src": "https://img.alicdn.com/imgextra/i2/2185320355/O1CN01k3kQpd1EUdLwwRW6V_!!2185320355.png", "name": "光效13.png", "width": "370", "height": "370" },
{ "src": "https://img.alicdn.com/imgextra/i1/2185320355/O1CN01kRVF2d1EUdM3N3QrY_!!2185320355.png", "name": "光效14.png", "width": "370", "height": "370" },
{ "src": "https://img.alicdn.com/imgextra/i1/2185320355/O1CN01dGvKFA1EUdM6NiT8u_!!2185320355.png", "name": "光效15.png", "width": "370", "height": "370" },
{ "src": "https://img.alicdn.com/imgextra/i1/2185320355/O1CN01UdQUxY1EUdMBhHqmY_!!2185320355.png", "name": "光效16.png", "width": "370", "height": "370" },
{ "src": "https://img.alicdn.com/imgextra/i3/2185320355/O1CN01FV6IG01EUdM6NkDFf_!!2185320355.png", "name": "光效17.png", "width": "370", "height": "370" },
{ "src": "https://img.alicdn.com/imgextra/i2/2185320355/O1CN01UqNzIG1EUdMCueL0a_!!2185320355.png", "name": "光效18.png", "width": "370", "height": "370" },
{ "src": "https://img.alicdn.com/imgextra/i1/2185320355/O1CN01nN8l9b1EUdM7ABLMm_!!2185320355.png", "name": "光效19.png", "width": "370", "height": "370" },
{ "src": "https://img.alicdn.com/imgextra/i3/2185320355/O1CN0182v3PO1EUdM6ToqEL_!!2185320355.png", "name": "光效20.png", "width": "370", "height": "370" },
{ "src": "https://img.alicdn.com/imgextra/i1/2185320355/O1CN01ZySnSK1EUdM7AAKyP_!!2185320355.png", "name": "光效21.png", "width": "370", "height": "370" },
{ "src": "https://img.alicdn.com/imgextra/i4/2185320355/O1CN01xs8i3f1EUdM8DiipK_!!2185320355.png", "name": "光效22.png", "width": "370", "height": "370" },
{ "src": "https://img.alicdn.com/imgextra/i1/2185320355/O1CN01111kA31EUdM1pDEY3_!!2185320355.png", "name": "光效23.png", "width": "370", "height": "370" },
{ "src": "https://img.alicdn.com/imgextra/i2/2185320355/O1CN01toAuOY1EUdMBhHqn7_!!2185320355.png", "name": "光效24.png", "width": "370", "height": "370" },
{ "src": "https://img.alicdn.com/imgextra/i1/2185320355/O1CN01doBbqF1EUdM1pF2nA_!!2185320355.png", "name": "光效25.png", "width": "370", "height": "370" },
{ "src": "https://img.alicdn.com/imgextra/i4/2185320355/O1CN016nPpgo1EUdLwwSn9A_!!2185320355.png", "name": "光效26.png", "width": "370", "height": "370" },
{ "src": "https://img.alicdn.com/imgextra/i4/2185320355/O1CN01NHn0ld1EUdLwwQ2dQ_!!2185320355.png", "name": "光效27.png", "width": "370", "height": "370" },
{ "src": "https://img.alicdn.com/imgextra/i2/2185320355/O1CN01l3nsX91EUdMDfgBfW_!!2185320355.png", "name": "光效28.png", "width": "370", "height": "370" },
{ "src": "https://img.alicdn.com/imgextra/i4/2185320355/O1CN01O35Vla1EUdM44B8B4_!!2185320355.png", "name": "光效29.png", "width": "370", "height": "370" },
{ "src": "https://img.alicdn.com/imgextra/i2/2185320355/O1CN012UwweM1EUdMDfeiDh_!!2185320355.png", "name": "光效30.png", "width": "370", "height": "370" },
{ "src": "https://img.alicdn.com/imgextra/i1/2185320355/O1CN01uj2Jwr1EUdM9yDSZC_!!2185320355.png", "name": "光效31.png", "width": "370", "height": "370" },
{ "src": "https://img.alicdn.com/imgextra/i3/2185320355/O1CN01ktXmTg1EUdM7ABXpN_!!2185320355.png", "name": "光效32.png", "width": "370", "height": "370" },
{ "src": "https://img.alicdn.com/imgextra/i2/2185320355/O1CN01kw87br1EUdMDffNmp_!!2185320355.png", "name": "光效33.png", "width": "370", "height": "370" },
{ "src": "https://img.alicdn.com/imgextra/i1/2185320355/O1CN01sDTZeb1EUdMFf62a4_!!2185320355.png", "name": "光效34.png", "width": "370", "height": "370" },
{ "src": "https://img.alicdn.com/imgextra/i3/2185320355/O1CN01BqeBbB1EUdM8gZBV9_!!2185320355.png", "name": "光效35.png", "width": "370", "height": "370" },
{ "src": "https://img.alicdn.com/imgextra/i2/2185320355/O1CN01whVv981EUdMFf7mfH_!!2185320355.png", "name": "光效36.png", "width": "370", "height": "370" },
{ "src": "https://img.alicdn.com/imgextra/i4/2185320355/O1CN01ryjy0p1EUdM6NjCu1_!!2185320355.png", "name": "光效37.png", "width": "370", "height": "370" },
{ "src": "https://img.alicdn.com/imgextra/i1/2185320355/O1CN01fEZZqN1EUdLwwQVkP_!!2185320355.png", "name": "光效38.png", "width": "370", "height": "370" },
{ "src": "https://img.alicdn.com/imgextra/i2/2185320355/O1CN01yI7MFV1EUdMAuO3SR_!!2185320355.png", "name": "光效39.png", "width": "370", "height": "370" },
{ "src": "https://img.alicdn.com/imgextra/i4/2185320355/O1CN01i8UycV1EUdMErQa5r_!!2185320355.png", "name": "光效40.png", "width": "370", "height": "370" },
],
boomScale: 1,//爆炸动画缩放,相对精灵尺寸,默认为1
boomSpeed: 0.5,// 爆炸动画速度 值越大,速度越快
},
],
},
},
onLoad() { },
onInitDone(obj) {
this.gameComponent = obj.ref;
// my.alert({
// content: "游戏初始化完成"
// })
// this.beginFun();
},
onUpdate(img) {
// img:点中的红包对象
console.log(img)
//点中一个红包就手动结束游戏
this.overFun();
},
onGameOver(imgs) {
// imgs:本次游戏点击的所有红包对象
console.log(imgs)
},
beginFun() {
console.log("21", this.gameComponent)
this.gameComponent.onEvent("start");
},
overFun() {
this.gameComponent.onEvent("gameOver");
},
resetFun() {
this.gameComponent.onEvent("reset");
},
});
- xaml
<view class="pageBox">
<game gameSource="{{gameSource}}" onInitDone="onInitDone" onUpdate="onUpdate" onGameOver="onGameOver" />
</view>
<view onTap="beginFun" style="position:absolute;left: 100rpx;bottom: 0;">开始</view>
<view onTap="overFun" style="position:absolute;left: 200rpx;bottom: 0;">停止</view>
<view onTap="resetFun" style="position:absolute;left: 300rpx;bottom: 0;">重置</view>
0.0.1
2 years ago