Skip to content

Commit 97a7de6

Browse files
committed
Made TweenData.start hooked to onRefresh - testing need for startCache now
1 parent 3af861b commit 97a7de6

2 files changed

Lines changed: 70 additions & 13 deletions

File tree

v3/src/tween/tween/components/ResetTweenData.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,32 @@ var ResetTweenData = function (resetFromLoop)
1313

1414
tweenData.repeatCounter = (tweenData.repeat === -1) ? 999999999999 : tweenData.repeat;
1515

16+
/*
17+
The function below is called to get the END value of the TweenData
18+
bob.x is read to get the START/CACHE value and never read again
19+
20+
targets: bob,
21+
x: function () { return 700; },
22+
onRefresh: function (target, key, previousValue, startOfTween) { return target[key]; },
23+
ease: 'Sine.easeInOut',
24+
duration: 2000
25+
26+
*/
27+
1628
if (resetFromLoop)
1729
{
30+
var onRefresh = tween.callbacks.onRefresh;
31+
32+
if (onRefresh)
33+
{
34+
tweenData.startCache = onRefresh.func.call(onRefresh.scope, tweenData.target, tweenData.key, tweenData.startCache, true);
35+
}
36+
1837
tweenData.start = tweenData.startCache;
38+
1939
tweenData.current = tweenData.start;
20-
tweenData.end = tweenData.value(tweenData.start);
40+
41+
tweenData.end = tweenData.value(tweenData.start, tweenData.target, tweenData.key);
2142

2243
tweenData.state = TWEEN_CONST.PLAYING_FORWARD;
2344
}

v3/src/tween/tween/components/UpdateTweenData.js

Lines changed: 48 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)