sequence 顺序执行
// 顺序执行两个动作node.runAction( cc.sequence( cc.moveTo(), cc.rotateTo(), cc.callFunc(() => {}) );)
spawn 并行执行
// 并行执行两个动作node.runAction( cc.spawn( cc.moveTo(), cc.rotateTo(), cc.callFunc(() => {}) );)
先定义好动作再执行
buttonShake(node) { const actionLeft = cc.moveBy(0.1, cc.v2(-5, 0)); const actionRight = cc.moveBy(0.1, cc.v2(10, 0)); const actionLeftSecond = cc.moveBy(0.1, cc.v2(-10, 0)); const actionRightSecond = cc.moveBy(0.1, cc.v2(5, 0)); return new Promise(resolve => { node.runAction( cc.sequence(actionLeft, actionRight, actionLeftSecond, actionRightSecond, // 执行动作完成之后调用的方法 cc.callFunc(() => { cc.log(3333); resolve(); })) ); });},
在runAction里定义动作
this.leftTutu.runAction( cc.sequence( cc.fadeIn(0.6), cc.callFunc(() => { this.buttonShake(event.target).then(() => { cc.log(44444); this.scheduleOnce(() => { cc.log(2222222); this.buttonShake(event.target); }, 0.8); }); this.playAudio(this.rightAudio).then(() => { this.xxxx(); }); }) ) );