mirror of
https://github.com/photonstorm/phaser
synced 2024-11-24 05:33:35 +00:00
AnimationManager.add no longer sets the currentFrame
property when just adding an Animation to a Sprite. The currentFrame
property is now only set when the animation begins playing. This avoids the Sprite.frame and Sprite.frameName properties from returning incorrect results after adding (but not playing) an Animation. It also allows very short animations (2 frames) to play correctly without needing to loop.
This commit is contained in:
parent
42dfe21ad7
commit
2e6af02f86
2 changed files with 34 additions and 12 deletions
|
@ -192,7 +192,7 @@ Phaser.Animation.prototype = {
|
|||
this._timeNextFrame = this.game.time.time + this.delay;
|
||||
|
||||
this._frameIndex = 0;
|
||||
this.updateCurrentFrame(false);
|
||||
this.updateCurrentFrame(false, true);
|
||||
|
||||
this._parent.events.onAnimationStart$dispatch(this._parent, this);
|
||||
|
||||
|
@ -381,6 +381,7 @@ Phaser.Animation.prototype = {
|
|||
// And what's left now?
|
||||
this._timeNextFrame = this.game.time.time + (this.delay - this._frameDiff);
|
||||
|
||||
var fi = this._frameIndex;
|
||||
this._frameIndex += this._frameSkip;
|
||||
|
||||
if (this._frameIndex >= this._frames.length)
|
||||
|
@ -418,10 +419,13 @@ Phaser.Animation.prototype = {
|
|||
* Returns true if the current frame update was 'successful', false otherwise.
|
||||
*
|
||||
* @method Phaser.Animation#updateCurrentFrame
|
||||
* @param {bool} signalUpdate - If true th onUpdate signal will be triggered.
|
||||
* @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
|
||||
*/
|
||||
updateCurrentFrame: function (signalUpdate) {
|
||||
updateCurrentFrame: function (signalUpdate, fromPlay) {
|
||||
|
||||
if (typeof fromPlay === 'undefined') { fromPlay = false; }
|
||||
|
||||
if (!this._frameData)
|
||||
{
|
||||
|
@ -429,13 +433,25 @@ Phaser.Animation.prototype = {
|
|||
return false;
|
||||
}
|
||||
|
||||
var idx = this.currentFrame.index;
|
||||
|
||||
this.currentFrame = this._frameData.getFrame(this._frames[this._frameIndex]);
|
||||
|
||||
if (this.currentFrame && idx !== this.currentFrame.index)
|
||||
if (fromPlay)
|
||||
{
|
||||
this._parent.setFrame(this.currentFrame);
|
||||
this.currentFrame = this._frameData.getFrame(this._frames[this._frameIndex]);
|
||||
|
||||
if (this.currentFrame && idx !== this.currentFrame.index)
|
||||
{
|
||||
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)
|
||||
|
|
|
@ -25,7 +25,10 @@ Phaser.AnimationManager = function (sprite) {
|
|||
this.game = sprite.game;
|
||||
|
||||
/**
|
||||
* @property {Phaser.Frame} currentFrame - The currently displayed Frame of animation, if any.
|
||||
* The currently displayed Frame of animation, if any.
|
||||
* This property is only set once an Animation starts playing. Until that point it remains set as `null`.
|
||||
*
|
||||
* @property {Phaser.Frame} currentFrame
|
||||
* @default
|
||||
*/
|
||||
this.currentFrame = null;
|
||||
|
@ -196,14 +199,16 @@ Phaser.AnimationManager.prototype = {
|
|||
}
|
||||
}
|
||||
|
||||
this._outputFrames.length = 0;
|
||||
this._outputFrames = [];
|
||||
|
||||
this._frameData.getFrameIndexes(frames, useNumericIndex, this._outputFrames);
|
||||
|
||||
this._anims[name] = new Phaser.Animation(this.game, this.sprite, name, this._frameData, this._outputFrames, frameRate, loop);
|
||||
|
||||
this.currentAnim = this._anims[name];
|
||||
this.currentFrame = this.currentAnim.currentFrame;
|
||||
|
||||
// This shouldn't be set until the Animation is played, surely?
|
||||
// this.currentFrame = this.currentAnim.currentFrame;
|
||||
|
||||
if (this.sprite.tilingTexture)
|
||||
{
|
||||
|
@ -272,6 +277,7 @@ Phaser.AnimationManager.prototype = {
|
|||
this.currentAnim.paused = false;
|
||||
return this.currentAnim.play(frameRate, loop, killOnComplete);
|
||||
}
|
||||
|
||||
return this.currentAnim;
|
||||
}
|
||||
else
|
||||
|
|
Loading…
Reference in a new issue