【源码分享】我仿佛听到有人在说cc.Tween不好用?那就来一份仿照cc.Action的3D动作脚本吧

很久很久以前,在我还不知道有cc.Tween的时候,我发现cocos没有了针对3D节点的动作系统,于是就自己写了这个玩意。

刚刚翻帖,看到有人在吐槽cc.Tween,反正闲着也是闲着,不如就把这个玩意分享出来吧。

因为当时我只用到了几个简单的位移旋转缩放回调,所以也只做了这几种动作,以及队列,同步,缓动等。需要新的动作可以对照着添加。反正方法名、参数和cc.Action一样。

唯一不同的是,没法node.runAction(action),创建完action后,要Action3dManager.runAction(node,action),然后在某个脚本的update里执行Action3dManager.update(dt)。

话说回来,虽然cc.Action已经用的很习惯了,我还是觉得cc.Tween比cc.Action更灵活。

Action3dManager.rar (2.4 KB)

1赞

不知道是哪出问题,没产生效果,3d版本1.0.4

let array = [];
for (let i = 1; i < this.bestMap.length; i++) {
array.push(cc.delayTime(0.1));
array.push(cc.callFunc(function() {
let pos = this.bestMap[i];
this.setLandFrame(pos.row, pos.col, boxType.HERO);
let lastPos = this.bestMap[i - 1];
this.setLandFrame(lastPos.row, lastPos.col, this.palace[lastPos.row][lastPos.col]);

            this.curStepNum += 1;
            Utils.getAudioManager().playEffect("move.mp3");
            // 刷新步数
            this.setCurNum();
        }, this));
    }
    array.push(cc.callFunc(function() {
        // 刷新人物所在位置
        this.heroRow = this.end.row;
        this.heroCol = this.end.col;
        this.savePlayBackData();
        // 设置地图是否可点击
        this.setLandEnable(true);
    }, this));

    // 避免出错
    if(array.length >= 2) {
        this.node.runAction(cc.sequence(array));

个人感觉tween用起来方便点,不需要调用run之类的api, tween就to和from 也好理解。

请问这种怎么用tween写