@@ -583,8 +583,7 @@ var Animation = new Class({
583583 // Yoyo? (happens before repeat)
584584 if ( component . _yoyo )
585585 {
586- component . forward = false ;
587- this . _updateAndGetNextTick ( component , frame . prevFrame ) ;
586+ this . _handleYoyoFrame ( component , false ) ;
588587 }
589588 else if ( component . repeatCounter > 0 )
590589 {
@@ -610,6 +609,37 @@ var Animation = new Class({
610609 }
611610 } ,
612611
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+
613643 /**
614644 * Returns the animation last frame.
615645 *
@@ -643,15 +673,14 @@ var Animation = new Class({
643673
644674 if ( component . _yoyo )
645675 {
646- component . forward = true ;
647- this . _updateAndGetNextTick ( component , frame . nextFrame ) ;
676+ this . _handleYoyoFrame ( component , true ) ;
648677 }
649678 else if ( component . repeatCounter > 0 )
650679 {
651680 if ( component . _reverse && ! component . forward )
652681 {
653682 component . currentFrame = this . getLastFrame ( ) ;
654- this . _updateAndGetNextTick ( component , component . currentFrame ) ;
683+ this . repeatAnimation ( component ) ;
655684 }
656685 else
657686 {
0 commit comments