cocos creator 3.2 tween.bezierTo还有吗?

cocos creator 3.2 tween.bezierTo还有吗?

2赞
/**
 *  二阶贝塞尔曲线 运动
 * @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);
}

调用

 TweenUtils.bezierTo(this.spNode,2,v2(-200,-200),v2(200,0),v3(350,400,0),null).start()

找了很久 没有找到 3.0 的 自己查资料封装了一个简单的 先用着吧

参考地址 :贝塞尔曲线算法之JS获取点

12赞

好东西,顶一下。。。。

给大佬点赞,太强了。

太关键了。。

赞13456

没有进onUpdate函数啊

···
const jumpH = 100;

        const startPos = this.node.position.clone();

        //  jump 二阶贝塞尔

        const cp = new Vec2((pos.x + startPos.x) / 2, (pos.y + startPos.y) / 2 + jumpH);

        let tx = tween(this.node.position).to(dt / this.speedScale, { x: pos.x }, {

            progress: (start: number, end: number, current: number, ratio: number) => {

                current = (1 - ratio) * (1 - ratio) * start + 2 * ratio * (1 - ratio) * cp.x + ratio * ratio * end;

                return current

            }

        })

        let ty = tween(this.node.position).to(dt / this.speedScale, { y: pos.y }, {

            progress: (start: number, end: number, current: number, ratio: number) => {

                current = (1 - ratio) * (1 - ratio) * start + 2 * ratio * (1 - ratio) * cp.y + ratio * ratio * end;

                return current

            }

        })

        tween(this.node.position)

            .parallel(tx, ty)

            .call(() => {

                this.node.emit(fightEvent.State_Input, FightInputType.idle);

                resolve(this);

            })

            .start();

···

大佬这个有点看不懂