Skip to content

Commit 0d9678e

Browse files
committed
Promoted Game time loop count to protected public var. Checked in Sprite.lifespan decrement to avoid over-decreasing the lifespan (phaserjs#1358)
1 parent b3ccdf6 commit 0d9678e

2 files changed

Lines changed: 14 additions & 7 deletions

File tree

src/core/Game.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,12 @@ Phaser.Game = function (width, height, renderer, parent, state, transparent, ant
293293
*/
294294
this._deltaTime = 0;
295295

296+
/**
297+
* @property {number} count - Update iteration counter.
298+
* @protected
299+
*/
300+
this.count = 0;
301+
296302
/**
297303
* @property {number} _lastCount - remember how many 'catch-up' iterations were used on the logicUpdate last frame
298304
* @private
@@ -704,32 +710,32 @@ Phaser.Game.prototype = {
704710

705711
// call the game update logic multiple times if necessary to "catch up" with dropped frames
706712
// unless forceSingleUpdate is true
707-
var count = 0;
713+
this.count = 0;
708714

709715
while (this._deltaTime >= slowStep)
710716
{
711717
this._deltaTime -= slowStep;
712718
this.updateLogic(1.0 / this.time.desiredFps);
713-
count++;
719+
this.count++;
714720

715-
if (this.forceSingleUpdate && count === 1)
721+
if (this.forceSingleUpdate && this.count === 1)
716722
{
717723
break;
718724
}
719725
}
720726

721727
// detect spiralling (if the catch-up loop isn't fast enough, the number of iterations will increase constantly)
722-
if (count > this._lastCount)
728+
if (this.count > this._lastCount)
723729
{
724730
this._spiralling++;
725731
}
726-
else if (count < this._lastCount)
732+
else if (this.count < this._lastCount)
727733
{
728734
// looks like it caught up successfully, reset the spiral alert counter
729735
this._spiralling = 0;
730736
}
731737

732-
this._lastCount = count;
738+
this._lastCount = this.count;
733739

734740
// call the game render update exactly once every frame unless we're playing catch-up from a spiral condition
735741
this.updateRender(this._deltaTime / slowStep);

src/gameobjects/Sprite.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,8 @@ Phaser.Sprite.prototype.preUpdate = function() {
246246
return false;
247247
}
248248

249-
if (this.lifespan > 0)
249+
// Only apply lifespan decrement in the first updateLogic pass.
250+
if (this.lifespan > 0 && this.game.count === 0)
250251
{
251252
this.lifespan -= this.game.time.elapsedMS;
252253

0 commit comments

Comments
 (0)