@@ -4,7 +4,7 @@ var SetStateFromEnd = function (tween, tweenData)
44{
55 if ( tweenData . yoyo )
66 {
7- // Playing forward and we have a yoyo
7+ // We've hit the end of a Playing Forward TweenData and we have a yoyo
88
99 tweenData . progress = 0 ;
1010 tweenData . elapsed = 0 ;
@@ -32,10 +32,21 @@ var SetStateFromEnd = function (tween, tweenData)
3232 onYoyo . func . apply ( onYoyo . scope , onYoyo . params ) ;
3333 }
3434
35+ var onRefresh = tween . callbacks . onRefresh ;
36+
37+ if ( onRefresh )
38+ {
39+ tweenData . startCache = onRefresh . func . call ( onRefresh . scope , tweenData . target , tweenData . key , tweenData . startCache , false ) ;
40+ tweenData . start = tweenData . startCache ;
41+ }
42+
3543 return TWEEN_CONST . PLAYING_BACKWARD ;
3644 }
3745 else if ( tweenData . repeatCounter > 0 )
3846 {
47+ // We've hit the end of a Playing Forward TweenData and we have a Repeat.
48+ // So we're going to go right back to the start to repeat it again.
49+
3950 tweenData . repeatCounter -- ;
4051
4152 tweenData . elapsed = 0 ;
@@ -51,9 +62,6 @@ var SetStateFromEnd = function (tween, tweenData)
5162 tweenData . target . toggleFlipY ( ) ;
5263 }
5364
54- // Reset the destination value, in case it's dynamic
55- tweenData . end = tweenData . value ( tweenData . startCache ) ;
56-
5765 var onRepeat = tween . callbacks . onRepeat ;
5866
5967 if ( onRepeat )
@@ -64,6 +72,18 @@ var SetStateFromEnd = function (tween, tweenData)
6472 onRepeat . func . apply ( onRepeat . scope , onRepeat . params ) ;
6573 }
6674
75+ // Do we want to refresh the start value before we return to it?
76+ var onRefresh = tween . callbacks . onRefresh ;
77+
78+ if ( onRefresh )
79+ {
80+ tweenData . startCache = onRefresh . func . call ( onRefresh . scope , tweenData . target , tweenData . key , tweenData . startCache , false ) ;
81+ tweenData . start = tweenData . startCache ;
82+ }
83+
84+ // Reset the destination value, in case it's dynamic
85+ tweenData . end = tweenData . value ( tweenData . startCache , tweenData . target , tweenData . key ) ;
86+
6787 // Delay?
6888 if ( tweenData . repeatDelay > 0 )
6989 {
@@ -104,9 +124,6 @@ var SetStateFromStart = function (tween, tweenData)
104124 tweenData . target . toggleFlipY ( ) ;
105125 }
106126
107- // Reset the destination value, in case it's dynamic
108- tweenData . end = tweenData . value ( tweenData . startCache ) ;
109-
110127 var onRepeat = tween . callbacks . onRepeat ;
111128
112129 if ( onRepeat )
@@ -117,6 +134,18 @@ var SetStateFromStart = function (tween, tweenData)
117134 onRepeat . func . apply ( onRepeat . scope , onRepeat . params ) ;
118135 }
119136
137+ // Do we want to refresh the start value now we're sitting on it?
138+ var onRefresh = tween . callbacks . onRefresh ;
139+
140+ if ( onRefresh )
141+ {
142+ tweenData . startCache = onRefresh . func . call ( onRefresh . scope , tweenData . target , tweenData . key , tweenData . startCache , false ) ;
143+ tweenData . start = tweenData . startCache ;
144+ }
145+
146+ // Reset the destination value, in case it's dynamic
147+ tweenData . end = tweenData . value ( tweenData . startCache , tweenData . target , tweenData . key ) ;
148+
120149 // Delay?
121150 if ( tweenData . repeatDelay > 0 )
122151 {
@@ -244,14 +273,21 @@ var UpdateTweenData = function (tween, tweenData, delta)
244273
245274 case TWEEN_CONST . PENDING_RENDER :
246275
247- // Swap for function
248- tweenData . start = tweenData . target [ tweenData . key ] ;
276+ tweenData . startCache = tweenData . target [ tweenData . key ] ;
277+
278+ var onRefresh = tween . callbacks . onRefresh ;
279+
280+ if ( onRefresh )
281+ {
282+ tweenData . startCache = onRefresh . func . call ( onRefresh . scope , tweenData . target , tweenData . key , tweenData . startCache , true ) ;
283+ }
284+
285+ tweenData . start = tweenData . startCache ;
249286
250287 tweenData . current = tweenData . start ;
251- tweenData . end = tweenData . value ( tweenData . start ) ;
252-
253- tweenData . startCache = tweenData . start ;
254288
289+ tweenData . end = tweenData . value ( tweenData . start , tweenData . target , tweenData . key ) ;
290+
255291 tweenData . target [ tweenData . key ] = tweenData . current ;
256292
257293 tweenData . state = TWEEN_CONST . PLAYING_FORWARD ;
0 commit comments