Skip to content

Commit c38f480

Browse files
committed
Fixed pause/resume time incompatibilities (RAF time and Date.now() can't be mixed) which has fixed the problem with tweens disappearing when paused.
1 parent 497e919 commit c38f480

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

src/time/Time.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -279,8 +279,8 @@ Phaser.Time.prototype = {
279279
this.elapsed = this.timeCap;
280280
}
281281

282-
// Calculate physics elapsed, ensure it's > 0, use 1/this.desiredFps as a fallback
283-
this.physicsElapsed = this.elapsed / 1000 || 1 / this.desiredFps;
282+
// Set the physics elapsed time... this will always be 1 / this.desiredFps because we're using fixed time steps in game.update now
283+
this.physicsElapsed = 1 / this.desiredFps;
284284

285285
if (this.deltaCap > 0 && this.physicsElapsed > this.deltaCap)
286286
{
@@ -339,7 +339,9 @@ Phaser.Time.prototype = {
339339
*/
340340
gamePaused: function () {
341341

342-
this._pauseStarted = this.now;
342+
// use Date.now (instead of time.now) because the gameResumed function uses Date.now and the two values must be compatible
343+
// (time.now may not be updated while the game is paused so we can't use that in both places)
344+
this._pauseStarted = Date.now();
343345

344346
this.events.pause();
345347

@@ -360,10 +362,13 @@ Phaser.Time.prototype = {
360362
*/
361363
gameResumed: function () {
362364

365+
// TODO: check if this is needed. It won't work if the game is using RAF timing
366+
// (Date.now() values can't mix with RAF times) but the deltaCap should do the same thing anyway and the new fixed step timing will also help.
367+
363368
// Level out the elapsed timer to avoid spikes
364-
this.time = this.now = Date.now();
369+
// this.time = this.now = Date.now();
365370

366-
this.pauseDuration = this.now - this._pauseStarted;
371+
this.pauseDuration = Date.now() - this._pauseStarted;
367372

368373
this.events.resume();
369374

0 commit comments

Comments
 (0)