Cocos03runAction顺序和并行执行一系列动作

51次阅读

共计 858 个字符,预计需要花费 3 分钟才能阅读完成。

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();
                });
            })
        )
    );

正文完
 0