Skip to content

Commit

Permalink
Game Pause / Resume Timer issues resolved. Doing a commit with all th…
Browse files Browse the repository at this point in the history
…e debugging in so I can roll-back if needed.
  • Loading branch information
photonstorm committed Apr 28, 2014
1 parent 1d48b3c commit 174bfa9
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 19 deletions.
8 changes: 4 additions & 4 deletions src/time/Time.js
Original file line number Diff line number Diff line change
Expand Up @@ -328,12 +328,12 @@ Phaser.Time.prototype = {

this.events.resume();

// var i = this._timers.length;
var i = this._timers.length;

// while (i--)
// {
while (i--)
{
// this._timers[i]._resume();
// }
}


},
Expand Down
40 changes: 25 additions & 15 deletions src/time/Timer.js
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,7 @@ Phaser.Timer.prototype = {

/**
* Resumes the Timer and updates all pending events.
*
* @method Phaser.Timer#resume
*/
resume: function () {
Expand All @@ -513,9 +514,9 @@ Phaser.Timer.prototype = {
return;
}

var durationBeforePause = this.duration;
// var durationBeforePause = this.duration;

console.log('old duration', durationBeforePause);
// console.log('old duration', durationBeforePause);

this._pauseTotal += this.game.time.pauseDuration;
this._now = this.game.time.time;
Expand All @@ -526,27 +527,36 @@ Phaser.Timer.prototype = {
{
if (!this.events[i].pendingDelete)
{
var t = 0;
var d = 0;
// Work out how long there would have been from when the game paused until the events next tick
var t = this.events[i].tick - this._pauseStarted;

if (this.events[i].tick > this._now)
{
// event was going to tick in the future
d = this.events[i].tick - this._now;
t = d;
}
else
if (t < 0)
{
// event tick time has elapsed due to pause
d = this._now - this.events[i].tick;
t = this.game.time.pauseDuration - d;
t = 0;
}

// Add the difference on to the time now
this.events[i].tick = this._now + t;

console.log('event increased by', t);
}
}

this.nextTick = this._now + durationBeforePause;
// this.nextTick = this._now + durationBeforePause;

var d = this.nextTick - this._pauseStarted;

if (d < 0)
{
this.nextTick = this._now;
}
else
{
this.nextTick = this._now + d;
}

console.log('nextTick +', d);


// if (this.nextTick > this._now)
// {
Expand Down

0 comments on commit 174bfa9

Please sign in to comment.