mirror of
https://github.com/photonstorm/phaser
synced 2025-02-25 11:57:19 +00:00
fix animations with yoyo mode (issue: #3837)
This commit is contained in:
parent
bb17c82bf9
commit
8da8fbedd1
2 changed files with 49 additions and 18 deletions
|
@ -585,17 +585,21 @@ var Animation = new Class({
|
||||||
if (component._yoyo)
|
if (component._yoyo)
|
||||||
{
|
{
|
||||||
component.forward = false;
|
component.forward = false;
|
||||||
|
this._updateAndGetNextTick(component, frame.prevFrame);
|
||||||
component.updateFrame(frame.prevFrame);
|
|
||||||
|
|
||||||
// Delay for the current frame
|
|
||||||
this.getNextTick(component);
|
|
||||||
}
|
}
|
||||||
else if (component.repeatCounter > 0)
|
else if (component.repeatCounter > 0)
|
||||||
{
|
{
|
||||||
// Repeat (happens before complete)
|
// Repeat (happens before complete)
|
||||||
|
|
||||||
|
if(component._reverse && component.forward)
|
||||||
|
{
|
||||||
|
component.forward = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
this.repeatAnimation(component);
|
this.repeatAnimation(component);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
this.completeAnimation(component);
|
this.completeAnimation(component);
|
||||||
|
@ -603,9 +607,7 @@ var Animation = new Class({
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
component.updateFrame(frame.nextFrame);
|
this._updateAndGetNextTick(component, frame.nextFrame);
|
||||||
|
|
||||||
this.getNextTick(component);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -639,18 +641,22 @@ var Animation = new Class({
|
||||||
{
|
{
|
||||||
// We're at the start of the animation
|
// We're at the start of the animation
|
||||||
|
|
||||||
if (component.repeatCounter > 0)
|
if (component._yoyo)
|
||||||
{
|
{
|
||||||
if(!component.forward)
|
component.forward = true;
|
||||||
|
this._updateAndGetNextTick(component, frame.nextFrame);
|
||||||
|
}
|
||||||
|
else if (component.repeatCounter > 0)
|
||||||
|
{
|
||||||
|
if(component._reverse && !component.forward)
|
||||||
{
|
{
|
||||||
component.currentFrame = this.getLastFrame();
|
component.currentFrame = this.getLastFrame();
|
||||||
|
this._updateAndGetNextTick(component, component.currentFrame);
|
||||||
component.updateFrame(component.currentFrame);
|
|
||||||
this.getNextTick(component);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Repeat (happens before complete)
|
// Repeat (happens before complete)
|
||||||
|
component.forward = true;
|
||||||
this.repeatAnimation(component);
|
this.repeatAnimation(component);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -661,12 +667,24 @@ var Animation = new Class({
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
component.updateFrame(frame.prevFrame);
|
this._updateAndGetNextTick(component, frame.prevFrame);
|
||||||
|
|
||||||
this.getNextTick(component);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update Frame and Wait next tick
|
||||||
|
*
|
||||||
|
* @method Phaser.Animations.Animation#_updateAndGetNextTick
|
||||||
|
*
|
||||||
|
* @param {Phaser.Animations.AnimationFrame} frame - An Animation frame
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
_updateAndGetNextTick: function (component, frame)
|
||||||
|
{
|
||||||
|
component.updateFrame(frame);
|
||||||
|
this.getNextTick(component);
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* [description]
|
* [description]
|
||||||
*
|
*
|
||||||
|
|
|
@ -208,7 +208,7 @@ var Animation = new Class({
|
||||||
this._yoyo = false;
|
this._yoyo = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Will the playhead move forwards (`true`) or in reverse (`false`)
|
* Will the playhead move forwards (`true`) or in reverse (`false`).
|
||||||
*
|
*
|
||||||
* @name Phaser.GameObjects.Components.Animation#forward
|
* @name Phaser.GameObjects.Components.Animation#forward
|
||||||
* @type {boolean}
|
* @type {boolean}
|
||||||
|
@ -217,6 +217,16 @@ var Animation = new Class({
|
||||||
*/
|
*/
|
||||||
this.forward = true;
|
this.forward = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An Internal trigger that's play the animation in reverse mode ('true') or not ('false'),
|
||||||
|
* needed because forward can be changed by yoyo feature.
|
||||||
|
*
|
||||||
|
* @name Phaser.GameObjects.Components.Animation#forward
|
||||||
|
* @type {boolean}
|
||||||
|
* @default false
|
||||||
|
*/
|
||||||
|
this._reverse = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Internal time overflow accumulator.
|
* Internal time overflow accumulator.
|
||||||
*
|
*
|
||||||
|
@ -497,6 +507,7 @@ var Animation = new Class({
|
||||||
}
|
}
|
||||||
|
|
||||||
this.forward = true;
|
this.forward = true;
|
||||||
|
this._reverse = false;
|
||||||
return this._startAnimation(key, startFrame);
|
return this._startAnimation(key, startFrame);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -523,6 +534,7 @@ var Animation = new Class({
|
||||||
}
|
}
|
||||||
|
|
||||||
this.forward = false;
|
this.forward = false;
|
||||||
|
this._reverse = true;
|
||||||
return this._startAnimation(key, startFrame);
|
return this._startAnimation(key, startFrame);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -575,6 +587,7 @@ var Animation = new Class({
|
||||||
revert: function (key)
|
revert: function (key)
|
||||||
{
|
{
|
||||||
if (!this.isPlaying || this.currentAnim.key !== key) { return this.parent; }
|
if (!this.isPlaying || this.currentAnim.key !== key) { return this.parent; }
|
||||||
|
this._reverse = !this._reverse;
|
||||||
this.forward = !this.forward;
|
this.forward = !this.forward;
|
||||||
|
|
||||||
return this.parent;
|
return this.parent;
|
||||||
|
|
Loading…
Add table
Reference in a new issue