如何通过Tween旋转一个物体(已解决)

如题所示。

1赞

这种问题是不是照抄下文档的代码

抄了呀

来自官方大佬“Cocos-jiaxin”的爱,他专门写了代码给我,现在分享给大家。
代码如下:

import { _decorator, Component, Node, Vec3, tweenUtil, tween, Quat, quat } from "cc";
const { ccclass, property } = _decorator;
declare const TWEEN: any;

@ccclass("tween-test")
export class tweentest extends Component {

    _wpos: Vec3 = new Vec3(0, 0, 0);
    _wscale: Vec3 = new Vec3(1, 1, 1);

    elu: Quat = new Quat(0, 0, 0);
    _leuler: Vec3 = new Vec3(0, 0, 0);
    _lquat: Quat = new Quat();

    start() {

     

        Vec3.copy(this._leuler, this.node.eulerAngles);

        tweenUtil(this._leuler)
            .to(6, new Vec3(90, 90, 90), { easing: 'Bounce-InOut' })
            .to(6, new Vec3(0, 0, 0), { easing: 'Elastic-Out' })
            .union()
            .repeat(Infinity)
            .start();

        // Quat.copy(this._lquat, this.node.rotation);

        // const quat1 = new Quat();
        // Quat.fromEuler(quat1, 90, 90, 90);
        // const quat2 = new Quat();
        // Quat.fromEuler(quat2, 0, 0, 0);
        // tweenUtil(this._lquat)
        //     .to(6, quat1, { easing: 'Bounce-InOut' })
        //     .to(6, quat2, { easing: 'Elastic-Out' })
        //     .union()
        //     .repeat(Infinity)
        //     .start();

     

        //#region
        // Your initialization goes here.
        /** 
        Vec3.copy(this._wpos, this.node.worldPosition);

        tweenUtil(this._wpos)
            .to(3, new Vec3(10, 10, 10), { easing: 'Bounce-InOut' })
            .to(3, new Vec3(0, 0, 0), { easing: 'Elastic-Out' })
            .union()
            .repeat(-1)
            .start();

        Vec3.copy(this._wscale, this.node.worldScale);

        tween(this._wscale)
            .to(3, new Vec3(3, 3, 3), { easing: 'Bounce-InOut' })
            .to(3, new Vec3(1, 1, 1), { easing: 'Elastic-Out' })
            .union()
            .repeat(-1)
            .start();
            */

        //#endregion

        TWEEN.update();

    }

    update(deltaTime: number) {
        // Your update function goes here.
        this.node.worldPosition = this._wpos;
        this.node.worldScale = this._wscale;

        this.node.eulerAngles = this._leuler;

        // this.node.rotation = this._lquat;
    }
}
1赞

只能在update里面调用吗? 不能控制什么时候执行?

旋转了,但是怎么还缩放了一下?

tweenUtil已经废弃了,用tween如何实现图片的旋转?

查看文档,或者自己配合生命周期递归实现一个。