Explicitly paused Timer continues if you un-focus and focus the browser window.

Added TimerEvent.pendingDelete and checks in Timer.update, so that removing an event in a callback no longer throws an exception.
This commit is contained in:
photonstorm
2014-02-05 22:35:35 +00:00
parent eddce653e9
commit 68d5c73fea
4 changed files with 65 additions and 27 deletions
+33 -11
View File
@@ -245,7 +245,7 @@ Phaser.Timer.prototype = {
{
if (this.events[i] === event)
{
this.events.splice(i, 1);
this.events[i].pendingDelete = true;
return true;
}
}
@@ -308,6 +308,21 @@ Phaser.Timer.prototype = {
this._len = this.events.length;
this._i = 0;
while (this._i < this._len)
{
if (this.events[this._i].pendingDelete)
{
this.events.splice(this._i, 1);
this._len--;
}
this._i++;
}
this._len = this.events.length;
if (this.running && this._now >= this.nextTick && this._len > 0)
{
this._i = 0;
@@ -371,9 +386,12 @@ Phaser.Timer.prototype = {
*/
pause: function () {
this._pauseStarted = this.game.time.now;
if (this.running && !this.expired)
{
this._pauseStarted = this.game.time.now;
this.paused = true;
this.paused = true;
}
},
@@ -383,17 +401,20 @@ Phaser.Timer.prototype = {
*/
resume: function () {
var pauseDuration = this.game.time.now - this._pauseStarted;
for (var i = 0; i < this.events.length; i++)
if (this.running && !this.expired)
{
this.events[i].tick += pauseDuration;
var pauseDuration = this.game.time.now - this._pauseStarted;
for (var i = 0; i < this.events.length; i++)
{
this.events[i].tick += pauseDuration;
}
this.nextTick += pauseDuration;
this.paused = false;
}
this.nextTick += pauseDuration;
this.paused = false;
},
/**
@@ -405,6 +426,7 @@ Phaser.Timer.prototype = {
this.onComplete.removeAll();
this.running = false;
this.events = [];
this._i = this._len;
}
+6
View File
@@ -62,6 +62,12 @@ Phaser.TimerEvent = function (timer, delay, tick, repeatCount, loop, callback, c
*/
this.args = args;
/**
* @property {boolean} pendingDelete - A flag that controls if the TimerEvent is pending deletion.
* @protected
*/
this.pendingDelete = false;
};
Phaser.TimerEvent.prototype.constructor = Phaser.TimerEvent;