cocos3.7tween函数不符合预期

let oriColor = this.gainProperty2DLabelNodeComp.color.clone();

        let initialAlpha = 255;    // 透明度

        let targetAlpha = 0;

        tween(this.gainProperty2DLabelNodeComp)    // 逐渐淡出,持续 1 秒

             .to(2, {color: new Color(oriColor.x, oriColor.y, oriColor.z, targetAlpha)})

             .call(() => {

                this.gainProperty2DLabelNode.active = false;

                this.gainProperty2DLabelNodeComp.color = oriColor;

             })

             .start();

问过chatgpt4了,他给出过用by,onUpdate,process等tween的接口,发现仍然不起左右。我只想实现一个简单的需求,实现Label的颜色淡出。求教大佬们怎么搞

this.gainProperty2DLabelNodeComp这是什么

之前的版本直接改color的透明度会闪,有bug,不知道3.7修复没有,可以用UIOpcity试试

我记得颜色不能用tween的,数值会转化,转化后就对不上了

添加UIOpacity组件,改变透明度

解决了,分享一下方案,手写了一个tween函数,异步调用
async fadeOutLabel(duration: number, frame: number, labelStr: string) {

    let oriColor = this.gainProperty2DLabelNodeComp.color.clone();

    let initialAlpha = 220;    // 透明度

    let targetAlpha = 0;

    const stepCount = Math.round(duration * frame);

    const alphaStep = (initialAlpha - targetAlpha) / stepCount;

    this.gainProperty2DLabelNodeComp.color = new Color(oriColor.r, oriColor.g, oriColor.b, initialAlpha);

    this.gainProperty2DLabelNodeComp.string = labelStr;

    await this.delay(600);

    for (let i = 0; i < stepCount; i++) {

        let currentAlpha = initialAlpha - alphaStep * i;

        if (i === stepCount - 1) {

            currentAlpha = 0;

        }

        this.gainProperty2DLabelNodeComp.color = new Color(oriColor.r, oriColor.g, oriColor.b, currentAlpha);

        await this.delay(1000 / frame);

    }

}

delay(dt: number) {

    return new Promise((resolve) => setTimeout(resolve, dt));

}

节点上面挂载的Label组件