一个时间的坑

    protected onLoad(): void {
    this.scheduleOnce(async () => {
        console.log('开始计时', this.formatNow());
        await this.setTimeOutDelayCall1(10);
        console.log(' 使用setTimeout定时结束', this.formatNow());
    }, 5);

    this.scheduleOnce(async () => {
        console.log('开始计时', this.formatNow());
        await this.tweenDealy(10, this.node);
        console.log('end 使用node定时结束', this.formatNow());
    }, 5);
}

public formatNow() {
    let date: Date = new Date();
    return date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds() + ":" + date.getMilliseconds();
}

setTimeOutDelayCall1(time: number) {
    return new Promise((resolve) => {
        let delay = (time * 1000);
        setTimeout(resolve, delay);
    })
}
public tweenDealy(delayTime: number, node: Node) {
    return new Promise((resolve, reject) => {
        tween(node).delay(delayTime).call(() => {
            resolve(null);
        }).start()
    });
}

在web测试的时候,输出 开始计时 的时候,切换其它网页.等10S左右.再切回来.
会发现两个结果输出时间不一样.
切后台后,setTimeOut还会继续计时,tween不会继续计时.
使用这两个的时候,慎重.

额tween本来就是后台不运行,动画表现基本上都用这个,切回来才继续表现效果

业务代码一律不准使用setTimeOut就能避免。setTimeOut本来就不归引擎的生命周期管。和tick无关

scheduleOnce、tween其实底层都是由引擎tick管理的,引擎切后台tick会停止,所有update都会停止。setTimeOut归nodejs环境管。

说明你们已经踩过坑了.

开发规范业务严禁写setTimeOut