Swapping between tabs will pause and resume tweens correctly, allowing their onComplete events to still fire (fixes #292)

This commit is contained in:
photonstorm 2014-02-25 03:33:47 +00:00
parent cc06a62b90
commit 8fb2f20482
4 changed files with 92 additions and 3 deletions

View file

@ -154,6 +154,7 @@ Bug Fixes:
* Fixed a bug where Sound.play wouldn't pick-up the local loop setting if not specified in the parameter.
* Active animations now monitor if the game pauses, and resume normally when the game un-pauses (fixes #179)
* Swapping between tabs will now pause the game correctly on mobile browsers (iOS7+)
* Swapping between tabs will pause and resume tweens correctly, allowing their onComplete events to still fire (fixes #292)
TO DO:

View file

@ -0,0 +1,79 @@
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render });
function preload() {
game.load.spritesheet('mummy', 'assets/sprites/metalslug_mummy37x45.png', 37, 45, 18);
}
var mummy;
var anim;
var s = [];
var t;
function create() {
game.stage.backgroundColor = 0x3d4d3d;
mummy = game.add.sprite(0, 300, 'mummy', 5);
mummy.scale.set(2);
anim = mummy.animations.add('walk');
anim.play(10, true);
game.onPause.add(paused, this);
game.onResume.add(resumed, this);
t = game.add.tween(mummy).to({x:700}, 15000, Phaser.Easing.Linear.None, true);
t.onComplete.add(tweenOver, this);
s.push('starting: ' + game.stage._hiddenVar);
}
function tweenOver() {
console.log('yay all over after 15 seconds anyway');
}
function pauseToggle() {
if (game.paused)
{
game.paused = false;
}
else
{
game.paused = true;
}
}
function paused() {
s.push('paused now: ' + game.time.now);
console.log('paused now: ' + game.time.now);
}
function resumed() {
s.push('resumed now: ' + game.time.now);
console.log('resumed now: ' + game.time.now);
s.push('pause duration: ' + game.time.pauseDuration);
}
function update() {
}
function render() {
for (var i = 0; i < s.length; i++)
{
game.debug.renderText(s[i], 16, 160 + (16 * i));
}
}

View file

@ -445,11 +445,20 @@ Phaser.Tween.prototype = {
* Resumes a paused tween.
*
* @method Phaser.Tween#resume
* @param {boolean} [fromManager=false] - Did this resume request come from the TweenManager or game code?
*/
resume: function () {
resume: function (fromManager) {
this._paused = false;
if (typeof fromManager === 'undefined' || !fromManager)
{
this._startTime += (this.game.time.now - this._pausedTime);
}
else
{
this._startTime += this.game.time.pauseDuration;
}
},

View file

@ -194,7 +194,7 @@ Phaser.TweenManager.prototype = {
for (var i = this._tweens.length - 1; i >= 0; i--)
{
this._tweens[i].resume();
this._tweens[i].resume(true);
}
}