@@ -78,14 +78,29 @@ Phaser.Tween = function (target, game, manager) {
7878 this . onStart = new Phaser . Signal ( ) ;
7979
8080 /**
81- * The onLoop event is fired if the Tween loops. If there are chained tweens it fires after all the child tweens have completed .
81+ * The onLoop event is fired if the Tween or any child tween loops .
8282 * It will be sent 2 parameters: the target object and this tween.
8383 * @property {Phaser.Signal } onLoop
8484 */
8585 this . onLoop = new Phaser . Signal ( ) ;
8686
8787 /**
88- * The onComplete event is fired when the Tween completes. Does not fire if the Tween is set to loop or repeatAll(-1).
88+ * The onRepeat event is fired if the Tween and all of its children repeats. If this tween has no children this will never be fired.
89+ * It will be sent 2 parameters: the target object and this tween.
90+ * @property {Phaser.Signal } onRepeat
91+ */
92+ this . onRepeat = new Phaser . Signal ( ) ;
93+
94+ /**
95+ * The onChildComplete event is fired when the Tween or any of its children completes.
96+ * Fires every time a child completes unless a child is set to repeat forever.
97+ * It will be sent 2 parameters: the target object and this tween.
98+ * @property {Phaser.Signal } onChildComplete
99+ */
100+ this . onChildComplete = new Phaser . Signal ( ) ;
101+
102+ /**
103+ * The onComplete event is fired when the Tween and all of its children completes. Does not fire if the Tween is set to loop or repeatAll(-1).
89104 * It will be sent 2 parameters: the target object and this tween.
90105 * @property {Phaser.Signal } onComplete
91106 */
@@ -646,41 +661,61 @@ Phaser.Tween.prototype = {
646661 }
647662 else if ( status === Phaser . TweenData . COMPLETE )
648663 {
664+ var complete = false ;
665+
649666 // What now?
650667 if ( this . reverse )
651668 {
652669 this . current -- ;
670+
671+ if ( this . current < 0 )
672+ {
673+ this . current = this . timeline . length - 1 ;
674+ complete = true ;
675+ }
653676 }
654677 else
655678 {
656679 this . current ++ ;
680+
681+ if ( this . current === this . timeline . length )
682+ {
683+ this . current = 0 ;
684+ complete = true ;
685+ }
657686 }
658687
659- if ( this . repeatCounter === - 1 || this . repeatCounter > 0 )
688+ if ( complete )
660689 {
661- if ( this . repeatCounter !== - 1 )
690+ // We've reached the start or end of the child tweens (depending on Tween.reverse), should we repeat it?
691+ if ( this . repeatCounter === - 1 )
662692 {
663- this . repeatCounter -- ;
693+ this . timeline [ this . current ] . start ( ) ;
694+ this . onRepeat . dispatch ( this . target , this ) ;
695+ return true ;
664696 }
665-
666- if ( this . current < 0 )
697+ else if ( this . repeatCounter > 0 )
667698 {
668- this . current = this . timeline . length - 1 ;
699+ this . repeatCounter -- ;
700+
701+ this . timeline [ this . current ] . start ( ) ;
702+ this . onRepeat . dispatch ( this . target , this ) ;
703+ return true ;
669704 }
670- else if ( this . current === this . timeline . length )
705+ else
671706 {
672- this . current = 0 ;
707+ // No more repeats and no more children, so we're done
708+ this . isRunning = false ;
709+ this . onComplete . dispatch ( this . target , this ) ;
710+ return false ;
673711 }
674-
675- this . timeline [ this . current ] . start ( ) ;
676- return true ;
677712 }
678713 else
679714 {
680- // And we're done
681- this . isRunning = false ;
682- this . onComplete . dispatch ( this . target , this ) ;
683- return false ;
715+ // We've still got some children to go
716+ this . onChildComplete . dispatch ( this . target , this ) ;
717+ this . timeline [ this . current ] . start ( ) ;
718+ return true ;
684719 }
685720 }
686721
0 commit comments