从Action改成Tween,你方便了吗?

最近尝试接触creator 3.x
动作系统被替换成了tween

以前action 是可以构造一个对象,再调用runAction来执行

action可以作为参数传递 现在的方式不能那样用了

不知道官方能否提供下相关使用经验!?

export class TweenUtils {
public static staggerTo(targets: any[], params: any[], durations: number[], cb?: Handler) {
    const len = Math.min(targets.length, params.length, durations.length);
    let completedCount = 0;
    for (let i = 0; i < len; i++) {
        let target = targets[i];
        let param = params[i];
        let duration = durations[i];
        tween(target).to(duration, param).call(() => {
            completedCount++;
            if (completedCount === len) cb && cb.run();
        }).start();
    }
}

/**
 *  二阶贝塞尔曲线 运动
 * @param target
 * @param {number} duration
 * @param {} c1 起点坐标
 * @param {} c2 控制点
 * @param {Vec3} to 终点坐标
 * @param opts
 * @returns {any}
 */
public static bezierTo(target: any, duration: number, c1: Vec2, c2: Vec2, to: Vec3, opts: any) {
    opts = opts || Object.create(null);
    /**
     * @desc 二阶贝塞尔
     * @param {number} t 当前百分比
     * @param {} p1 起点坐标
     * @param {} cp 控制点
     * @param {} p2 终点坐标
     * @returns {any}
     */
    let twoBezier = (t:number, p1: Vec2, cp: Vec2, p2: Vec3) => {
        let x = (1 - t) * (1 - t) * p1.x + 2 * t * (1 - t) * cp.x + t * t * p2.x;
        let y = (1 - t) * (1 - t) * p1.y + 2 * t * (1 - t) * cp.y + t * t * p2.y;
        return v3(x, y, 0);
    };
    opts.onUpdate = (arg: Vec3, ratio: number) => {
        target.position = twoBezier(ratio, c1, c2, to);
    };
    return tween(target).to(duration, {}, opts);
}

}

我这边 封装了一个简单的 你看看可以用吗? staggerTo 这个方法 那个 cb 修改成 Function 类型 修改为 回调函数即可

2赞

tween不调用start()可以返回动作实力,其他地方可以把它当参数调用then

没有cc. 卟呤卟呤 了 :rofl:

cc.tween不是更好用了嘛,写代码速度也快多了

淡定,之前2.4还是什么版本就变成tween了,就是3.0+的tween里面,不能单独控制x/y/z这些节点很麻烦