mirror of
https://github.com/photonstorm/phaser
synced 2024-11-23 21:24:09 +00:00
Fixed issue with looped animations skipping last frame (or getting stuck on a single frame in 2 frame anims)
This commit is contained in:
parent
a0d57544c7
commit
f41f806b99
1 changed files with 31 additions and 21 deletions
|
@ -131,7 +131,9 @@ Phaser.Animation = function (game, parent, name, frameData, frames, frameRate, l
|
||||||
this.onStart = new Phaser.Signal();
|
this.onStart = new Phaser.Signal();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property {Phaser.Signal|null} onUpdate - This event is dispatched when the Animation changes frame. By default this event is disabled due to its intensive nature. Enable it with: `Animation.enableUpdate = true`.
|
* This event is dispatched when the Animation changes frame.
|
||||||
|
* By default this event is disabled due to its intensive nature. Enable it with: `Animation.enableUpdate = true`.
|
||||||
|
* @property {Phaser.Signal|null} onUpdate
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
this.onUpdate = null;
|
this.onUpdate = null;
|
||||||
|
@ -390,10 +392,28 @@ Phaser.Animation.prototype = {
|
||||||
// Update current state before event callback
|
// Update current state before event callback
|
||||||
this._frameIndex %= this._frames.length;
|
this._frameIndex %= this._frames.length;
|
||||||
this.currentFrame = this._frameData.getFrame(this._frames[this._frameIndex]);
|
this.currentFrame = this._frameData.getFrame(this._frames[this._frameIndex]);
|
||||||
|
|
||||||
|
// Instead of calling updateCurrentFrame we do it here instead
|
||||||
|
if (this.currentFrame)
|
||||||
|
{
|
||||||
|
this._parent.setFrame(this.currentFrame);
|
||||||
|
}
|
||||||
|
|
||||||
this.loopCount++;
|
this.loopCount++;
|
||||||
this._parent.events.onAnimationLoop$dispatch(this._parent, this);
|
this._parent.events.onAnimationLoop$dispatch(this._parent, this);
|
||||||
this.onLoop.dispatch(this._parent, this);
|
this.onLoop.dispatch(this._parent, this);
|
||||||
return this.updateCurrentFrame(true);
|
|
||||||
|
if (this.onUpdate)
|
||||||
|
{
|
||||||
|
this.onUpdate.dispatch(this, this.currentFrame);
|
||||||
|
|
||||||
|
// False if the animation was destroyed from within a callback
|
||||||
|
return !!this._frameData;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -418,9 +438,10 @@ Phaser.Animation.prototype = {
|
||||||
* Returns true if the current frame update was 'successful', false otherwise.
|
* Returns true if the current frame update was 'successful', false otherwise.
|
||||||
*
|
*
|
||||||
* @method Phaser.Animation#updateCurrentFrame
|
* @method Phaser.Animation#updateCurrentFrame
|
||||||
|
* @private
|
||||||
* @param {boolean} signalUpdate - If true the `Animation.onUpdate` signal will be dispatched.
|
* @param {boolean} signalUpdate - If true the `Animation.onUpdate` signal will be dispatched.
|
||||||
* @param {boolean} fromPlay - Was this call made from the playing of a new animation?
|
* @param {boolean} fromPlay - Was this call made from the playing of a new animation?
|
||||||
* @private
|
* @return {boolean} True if the current frame was updated, otherwise false.
|
||||||
*/
|
*/
|
||||||
updateCurrentFrame: function (signalUpdate, fromPlay) {
|
updateCurrentFrame: function (signalUpdate, fromPlay) {
|
||||||
|
|
||||||
|
@ -432,25 +453,14 @@ Phaser.Animation.prototype = {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fromPlay)
|
// Previous index
|
||||||
|
var idx = this.currentFrame.index;
|
||||||
|
|
||||||
|
this.currentFrame = this._frameData.getFrame(this._frames[this._frameIndex]);
|
||||||
|
|
||||||
|
if (this.currentFrame && (fromPlay || (!fromPlay && idx !== this.currentFrame.index)))
|
||||||
{
|
{
|
||||||
this.currentFrame = this._frameData.getFrame(this._frames[this._frameIndex]);
|
this._parent.setFrame(this.currentFrame);
|
||||||
|
|
||||||
if (this.currentFrame)
|
|
||||||
{
|
|
||||||
this._parent.setFrame(this.currentFrame);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
var idx = this.currentFrame.index;
|
|
||||||
|
|
||||||
this.currentFrame = this._frameData.getFrame(this._frames[this._frameIndex]);
|
|
||||||
|
|
||||||
if (this.currentFrame && idx !== this.currentFrame.index)
|
|
||||||
{
|
|
||||||
this._parent.setFrame(this.currentFrame);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.onUpdate && signalUpdate)
|
if (this.onUpdate && signalUpdate)
|
||||||
|
|
Loading…
Reference in a new issue