如题。引擎代码:
public restart (): Promise {
const endFramePromise = new Promise((resolve) => { director.once(Director.EVENT_END_FRAME, () => resolve()); });
return endFramePromise.then(() => {
director.reset();
cclegacy.Object._deferredDestroy();
this.pause();
this.resume();
this._shouldLoadLaunchScene = true;
SplashScreen.instance.curTime = 0;
this._safeEmit(Game.EVENT_RESTART);
});
}
通常情况下,立即执行会比较符合直觉吧。当需要重启时,意味着我不需要再运行任何逻辑了。
但如果在帧末执行的话,很多逻辑还会执行,例如,定时器还是在这一帧还是会触发。