Fixed issue with looped animations skipping last frame (or getting stuck on a single frame in 2 frame anims)

This commit is contained in:
photonstorm 2015-07-14 13:47:25 +01:00
parent a0d57544c7
commit f41f806b99

View file

@ -131,7 +131,9 @@ Phaser.Animation = function (game, parent, name, frameData, frames, frameRate, l
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
*/
this.onUpdate = null;
@ -390,10 +392,28 @@ Phaser.Animation.prototype = {
// Update current state before event callback
this._frameIndex %= this._frames.length;
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._parent.events.onAnimationLoop$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
{
@ -418,9 +438,10 @@ Phaser.Animation.prototype = {
* Returns true if the current frame update was 'successful', false otherwise.
*
* @method Phaser.Animation#updateCurrentFrame
* @private
* @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?
* @private
* @return {boolean} True if the current frame was updated, otherwise false.
*/
updateCurrentFrame: function (signalUpdate, fromPlay) {
@ -432,25 +453,14 @@ Phaser.Animation.prototype = {
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]);
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);
}
this._parent.setFrame(this.currentFrame);
}
if (this.onUpdate && signalUpdate)