mirror of
https://github.com/wassname/phaser.git
synced 2026-08-18 12:20:33 +08:00
Active animations now monitor if the game pauses, and resume normally when the game un-pauses (fixes #179)
This commit is contained in:
@@ -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);
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
@@ -251,7 +251,7 @@ Phaser.AnimationManager.prototype = {
|
||||
*/
|
||||
update: function () {
|
||||
|
||||
if (this.updateIfVisible && this.sprite.visible === false)
|
||||
if (this.updateIfVisible && !this.sprite.visible)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user