Active animations now monitor if the game pauses, and resume normally when the game un-pauses (fixes #179)

This commit is contained in:
photonstorm
2014-02-24 23:06:45 +00:00
parent 36df5516dd
commit beaac18b8f
4 changed files with 60 additions and 6 deletions
+38
View File
@@ -115,6 +115,10 @@ Phaser.Animation = function (game, parent, name, frameData, frames, delay, loope
* @property {Phaser.Frame} currentFrame - The currently displayed frame of the Animation.
*/
this.currentFrame = this._frameData.getFrame(this._frames[this._frameIndex]);
// Set-up some event listeners
this.game.onPause.add(this.onPause, this);
this.game.onResume.add(this.onResume, this);
};
@@ -162,6 +166,7 @@ Phaser.Animation.prototype = {
this.currentFrame = this._frameData.getFrame(this._frames[this._frameIndex]);
this._parent.setTexture(PIXI.TextureCache[this.currentFrame.uuid]);
// TODO: Double check if required
if (this._parent.__tilePattern)
{
this._parent.__tilePattern = false;
@@ -220,6 +225,36 @@ Phaser.Animation.prototype = {
},
/**
* Called when the Game enters a paused state.
*
* @method Phaser.Animation#onPause
* @memberof Phaser.Animation
*/
onPause: function () {
if (this.isPlaying)
{
this._frameDiff = this._timeNextFrame - this.game.time.now;
}
},
/**
* Called when the Game resumes from a paused state.
*
* @method Phaser.Animation#onResume
* @memberof Phaser.Animation
*/
onResume: function () {
if (this.isPlaying)
{
this._timeNextFrame = this.game.time.now + this._frameDiff;
}
},
/**
* Updates this animation. Called automatically by the AnimationManager.
*
@@ -318,6 +353,9 @@ Phaser.Animation.prototype = {
this.currentFrame = null;
this.isPlaying = false;
this.game.onPause.remove(this.onPause, this);
this.game.onResume.remove(this.onResume, this);
},
/**
+1 -1
View File
@@ -251,7 +251,7 @@ Phaser.AnimationManager.prototype = {
*/
update: function () {
if (this.updateIfVisible && this.sprite.visible === false)
if (this.updateIfVisible && !this.sprite.visible)
{
return false;
}