Repository navigation
HTML5: Game time / animations speed up after repeated tab switching (3.x, worked in 2.4.x) #19138
Replies: 1 comment
|
I dug through the 3.8.3 web pacer and What the engine already does on tab switch. First, check whether it's more ticks or bigger ticks. Drop this into any component: import { _decorator, Component, game } from 'cc';
const { ccclass } = _decorator;
@ccclass('TickProbe')
export class TickProbe extends Component {
private _ticks = 0;
onLoad() {
const raf = () => {
if (this._ticks > 1) console.warn('update ran', this._ticks, 'times in one browser frame');
this._ticks = 0;
requestAnimationFrame(raf);
};
requestAnimationFrame(raf);
}
update(dt: number) {
this._ticks++;
if (dt > 0.05) console.log('large dt', dt, 'game.deltaTime', game.deltaTime);
}
}
The usual culprits in the second case:
If the probe shows more than one update per frame in an empty project with only |
Uh oh!
There was an error while loading. Please reload this page.
Creator version: 3.8.3
Platform: Web / Browser (Chrome, Edge)
Regression: Yes (worked in 2.4.12)
Issue:
After repeatedly switching browser tabs (hide → show), the entire game gradually speeds up.
This affects:
Tweens
Click animations
UI feedback
Any animation using engine time
This is not limited to a specific tween or script. Even unrelated animations (e.g. clicking another piece) appear faster after several tab switches.
What I tried:
director.pause() / director.resume() on EVENT_HIDE / EVENT_SHOW
Restarting tweens
setTimeScale(1)
FPS locking
Refactoring animations
None of these prevent the speed-up.
Expected behavior:
Game timing should remain consistent after tab switching (same as 2.4.x behavior).
Actual behavior:
Engine time appears to accelerate after each tab switch.
Notes:
This did not happen in Cocos Creator 2.4.12 with the same logic.
Is this a known limitation or a regression in the Web scheduler / tween timing in 3.x?
All reactions