From a1bb80997e8c70ebd810641c4a3369cc0b6c47ed Mon Sep 17 00:00:00 2001 From: Shukizu Date: Sat, 1 Sep 2018 10:48:23 -0300 Subject: [PATCH 1/2] fixed play in yoyo mode, bug found by @Ben-Millions #3837 --- src/animations/Animation.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/animations/Animation.js b/src/animations/Animation.js index c26aa83c6..b7ccce4ca 100644 --- a/src/animations/Animation.js +++ b/src/animations/Animation.js @@ -583,6 +583,12 @@ var Animation = new Class({ // Yoyo? (happens before repeat) if (component._yoyo) { + if (component._reverse !== false) + { + this.completeAnimation(component); + return; + } + component.forward = false; this._updateAndGetNextTick(component, frame.prevFrame); } @@ -643,6 +649,12 @@ var Animation = new Class({ if (component._yoyo) { + if (component._reverse !== true) + { + this.completeAnimation(component); + return; + } + component.forward = true; this._updateAndGetNextTick(component, frame.nextFrame); } From 96c7a4830cb85982c8f7874a206dd88e0c60c1aa Mon Sep 17 00:00:00 2001 From: Shukizu Date: Sat, 1 Sep 2018 12:40:26 -0300 Subject: [PATCH 2/2] fixed playReverse with repeat bigger than 1 #3837 --- src/animations/Animation.js | 51 ++++++++++++++++++++++++------------- 1 file changed, 34 insertions(+), 17 deletions(-) diff --git a/src/animations/Animation.js b/src/animations/Animation.js index b7ccce4ca..89495ae6d 100644 --- a/src/animations/Animation.js +++ b/src/animations/Animation.js @@ -583,14 +583,7 @@ var Animation = new Class({ // Yoyo? (happens before repeat) if (component._yoyo) { - if (component._reverse !== false) - { - this.completeAnimation(component); - return; - } - - component.forward = false; - this._updateAndGetNextTick(component, frame.prevFrame); + this._handleYoyoFrame(component, false); } else if (component.repeatCounter > 0) { @@ -616,6 +609,37 @@ var Animation = new Class({ } }, + /** + * Handle the yoyo functionality in nextFrame and previousFrame methods. + * + * @method Phaser.Animations.Animation#_handleYoyoFrame + * @since 3.12.0 + * + * @param {Phaser.GameObjects.Components.Animation} component - The Animation Component to advance. + * @param {bool} isReverse - Is animation in reverse mode? (Default: false) + */ + _handleYoyoFrame: function (component, isReverse) + { + if (!isReverse) { isReverse = false; } + + if (component._reverse === !isReverse && component.repeatCounter > 0) + { + component.forward = isReverse; + this.repeatAnimation(component); + return; + } + + if (component._reverse !== isReverse && component.repeatCounter === 0) + { + this.completeAnimation(component); + return; + } + + component.forward = isReverse; + var frame = isReverse ? component.currentFrame.nextFrame : component.currentFrame.prevFrame; + this._updateAndGetNextTick(component, frame); + }, + /** * Returns the animation last frame. * @@ -649,21 +673,14 @@ var Animation = new Class({ if (component._yoyo) { - if (component._reverse !== true) - { - this.completeAnimation(component); - return; - } - - component.forward = true; - this._updateAndGetNextTick(component, frame.nextFrame); + this._handleYoyoFrame(component, true); } else if (component.repeatCounter > 0) { if (component._reverse && !component.forward) { component.currentFrame = this.getLastFrame(); - this._updateAndGetNextTick(component, component.currentFrame); + this.repeatAnimation(component); } else {