Skip to content

Commit 96c7a48

Browse files
committed
fixed playReverse with repeat bigger than 1 phaserjs#3837
1 parent a1bb809 commit 96c7a48

1 file changed

Lines changed: 34 additions & 17 deletions

File tree

src/animations/Animation.js

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -583,14 +583,7 @@ var Animation = new Class({
583583
// Yoyo? (happens before repeat)
584584
if (component._yoyo)
585585
{
586-
if (component._reverse !== false)
587-
{
588-
this.completeAnimation(component);
589-
return;
590-
}
591-
592-
component.forward = false;
593-
this._updateAndGetNextTick(component, frame.prevFrame);
586+
this._handleYoyoFrame(component, false);
594587
}
595588
else if (component.repeatCounter > 0)
596589
{
@@ -616,6 +609,37 @@ var Animation = new Class({
616609
}
617610
},
618611

612+
/**
613+
* Handle the yoyo functionality in nextFrame and previousFrame methods.
614+
*
615+
* @method Phaser.Animations.Animation#_handleYoyoFrame
616+
* @since 3.12.0
617+
*
618+
* @param {Phaser.GameObjects.Components.Animation} component - The Animation Component to advance.
619+
* @param {bool} isReverse - Is animation in reverse mode? (Default: false)
620+
*/
621+
_handleYoyoFrame: function (component, isReverse)
622+
{
623+
if (!isReverse) { isReverse = false; }
624+
625+
if (component._reverse === !isReverse && component.repeatCounter > 0)
626+
{
627+
component.forward = isReverse;
628+
this.repeatAnimation(component);
629+
return;
630+
}
631+
632+
if (component._reverse !== isReverse && component.repeatCounter === 0)
633+
{
634+
this.completeAnimation(component);
635+
return;
636+
}
637+
638+
component.forward = isReverse;
639+
var frame = isReverse ? component.currentFrame.nextFrame : component.currentFrame.prevFrame;
640+
this._updateAndGetNextTick(component, frame);
641+
},
642+
619643
/**
620644
* Returns the animation last frame.
621645
*
@@ -649,21 +673,14 @@ var Animation = new Class({
649673

650674
if (component._yoyo)
651675
{
652-
if (component._reverse !== true)
653-
{
654-
this.completeAnimation(component);
655-
return;
656-
}
657-
658-
component.forward = true;
659-
this._updateAndGetNextTick(component, frame.nextFrame);
676+
this._handleYoyoFrame(component, true);
660677
}
661678
else if (component.repeatCounter > 0)
662679
{
663680
if (component._reverse && !component.forward)
664681
{
665682
component.currentFrame = this.getLastFrame();
666-
this._updateAndGetNextTick(component, component.currentFrame);
683+
this.repeatAnimation(component);
667684
}
668685
else
669686
{

0 commit comments

Comments
 (0)