mirror of
https://github.com/Leo501/CocosCreatorTutorial.git
synced 2026-06-03 07:59:39 +08:00
添加老虎机/水果机轮转动画
This commit is contained in:
76
HorseRaceLamp/assets/RollingMachine.js
Normal file
76
HorseRaceLamp/assets/RollingMachine.js
Normal file
@@ -0,0 +1,76 @@
|
||||
cc.Class({
|
||||
extends: cc.Component,
|
||||
|
||||
properties: {
|
||||
list: [cc.Node],
|
||||
loopTimes: 4,
|
||||
awardTime: 1,
|
||||
loopTimeList: [cc.Float]
|
||||
},
|
||||
|
||||
onLoad() {
|
||||
this.flickerTime = 0.15;
|
||||
// this.loopTimeList = [0.04, 0.04, 0.12, 0.2, 0.2];
|
||||
},
|
||||
|
||||
registerEvent() {
|
||||
|
||||
},
|
||||
|
||||
init(data) {
|
||||
|
||||
},
|
||||
|
||||
play(index, fn) {
|
||||
let seqList = [], len = this.list.length, i = 0, deltaTime = 0;
|
||||
let realTimes = len * this.loopTimes + index;
|
||||
for (i = 0; i <= realTimes; i++) {
|
||||
if (realTimes - i < 3) {
|
||||
deltaTime += this.loopTimeList[this.loopTimeList.length - 1];
|
||||
}
|
||||
let item = this.list[i % len];
|
||||
seqList.push(this.createAction(item, this.loopTimeList[Math.floor(i / len)] + deltaTime, true));
|
||||
}
|
||||
for (i = 0; i < 3; i++) {
|
||||
let item = this.list[index];
|
||||
seqList.push(this.createAction(item, this.flickerTime, false));
|
||||
seqList.push(cc.delayTime(this.flickerTime));
|
||||
}
|
||||
|
||||
seqList.push(cc.delayTime(this.awardTime));
|
||||
seqList.push(cc.callFunc(() => {
|
||||
fn && fn();
|
||||
}));
|
||||
|
||||
this.node.runAction(cc.sequence(seqList));
|
||||
},
|
||||
|
||||
createAction(item, time, isShow) {
|
||||
let seq = cc.sequence(cc.callFunc((data) => {
|
||||
item.active = isShow;
|
||||
}), cc.delayTime(time), cc.callFunc((data) => {
|
||||
item.active = !isShow;
|
||||
}));
|
||||
return seq;
|
||||
},
|
||||
|
||||
update(dt) {
|
||||
|
||||
},
|
||||
|
||||
onEnable() {
|
||||
this.registerEvent();
|
||||
},
|
||||
|
||||
onDisable() {
|
||||
this.offEvent();
|
||||
},
|
||||
|
||||
offEvent() {
|
||||
cc.emitter.offThis(this);
|
||||
},
|
||||
|
||||
onDestroy() {
|
||||
|
||||
}
|
||||
});
|
||||
9
HorseRaceLamp/assets/RollingMachine.js.meta
Normal file
9
HorseRaceLamp/assets/RollingMachine.js.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "1.0.5",
|
||||
"uuid": "1d222780-1af2-440a-8e0b-749bd8755e19",
|
||||
"isPlugin": false,
|
||||
"loadPluginInWeb": true,
|
||||
"loadPluginInNative": true,
|
||||
"loadPluginInEditor": false,
|
||||
"subMetas": {}
|
||||
}
|
||||
1445
HorseRaceLamp/assets/SlotMachine.fire
Normal file
1445
HorseRaceLamp/assets/SlotMachine.fire
Normal file
File diff suppressed because it is too large
Load Diff
7
HorseRaceLamp/assets/SlotMachine.fire.meta
Normal file
7
HorseRaceLamp/assets/SlotMachine.fire.meta
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"ver": "1.0.0",
|
||||
"uuid": "31bca123-0de6-409a-94d8-28d1b2634535",
|
||||
"asyncLoadAssets": false,
|
||||
"autoReleaseAssets": false,
|
||||
"subMetas": {}
|
||||
}
|
||||
44
HorseRaceLamp/assets/SlotMachine.js
Normal file
44
HorseRaceLamp/assets/SlotMachine.js
Normal file
@@ -0,0 +1,44 @@
|
||||
cc.Class({
|
||||
extends: cc.Component,
|
||||
|
||||
properties: {
|
||||
rolling: cc.Node,
|
||||
},
|
||||
|
||||
onLoad() {
|
||||
this.rollingMachine = this.rolling.getComponent('RollingMachine');
|
||||
},
|
||||
|
||||
registerEvent() {
|
||||
|
||||
},
|
||||
|
||||
init(data) {
|
||||
|
||||
},
|
||||
|
||||
onEventClicked_play() {
|
||||
let index = 2
|
||||
this.rollingMachine.play(index);
|
||||
},
|
||||
|
||||
update(dt) {
|
||||
|
||||
},
|
||||
|
||||
onEnable() {
|
||||
this.registerEvent();
|
||||
},
|
||||
|
||||
onDisable() {
|
||||
this.offEvent();
|
||||
},
|
||||
|
||||
offEvent() {
|
||||
cc.emitter.offThis(this);
|
||||
},
|
||||
|
||||
onDestroy() {
|
||||
|
||||
}
|
||||
});
|
||||
9
HorseRaceLamp/assets/SlotMachine.js.meta
Normal file
9
HorseRaceLamp/assets/SlotMachine.js.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "1.0.5",
|
||||
"uuid": "1af8a771-dc51-43ab-a95f-2c295b365ef0",
|
||||
"isPlugin": false,
|
||||
"loadPluginInWeb": true,
|
||||
"loadPluginInNative": true,
|
||||
"loadPluginInEditor": false,
|
||||
"subMetas": {}
|
||||
}
|
||||
Reference in New Issue
Block a user