Skip to content

Commit 1b1f249

Browse files
committed
Added in Tween.timeScale for scaling the time used for a single Tween.
Added in TweenManager.globalTimeScale for scaling the time used by ALL tweens currently active.
1 parent 5fe09c9 commit 1b1f249

6 files changed

Lines changed: 39 additions & 9 deletions

File tree

v3/src/checksum.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
var CHECKSUM = {
2-
build: '0c4b3280-7e8e-11e7-b40c-5d79b2507f10'
2+
build: 'afac2300-7eaf-11e7-8302-51beb5475aff'
33
};
44
module.exports = CHECKSUM;

v3/src/tween/Tween.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ var Tween = new Class({
2121
// If true then duration, delay, etc values are all frame totals
2222
this.useFrames = false;
2323

24+
// Scales the time applied to this Tween. A value of 1 runs in real-time. A value of 0.5 runs 50% slower, and so on.
25+
// Value isn't used when calculating total duration of the tween, it's a run-time delta adjustment only.
26+
this.timeScale = 1;
27+
2428
// Loop this tween? Can be -1 for an infinite loop, or an integer.
2529
// When enabled it will play through ALL TweenDatas again (use TweenData.repeat to loop a single TD)
2630
this.loop = 0;
@@ -76,6 +80,18 @@ var Tween = new Class({
7680
this.callbackScope;
7781
},
7882

83+
setTimeScale: function (value)
84+
{
85+
this.timeScale = value;
86+
87+
return this;
88+
},
89+
90+
getTimeScale: function ()
91+
{
92+
return this.timeScale;
93+
},
94+
7995
isPlaying: function ()
8096
{
8197
return (this.state === TWEEN_CONST.ACTIVE);

v3/src/tween/TweenBuilder.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,7 @@ var TweenBuilder = function (manager, config)
227227
var key = props[p].key;
228228
var value = props[p].value;
229229

230-
// console.log(key, value);
231-
230+
// Create 1 TweenData per target, per property
232231
for (var t = 0; t < targets.length; t++)
233232
{
234233
// Swap for faster getters, if they want Advanced Value style things, they can do it via their own functions
@@ -248,8 +247,6 @@ var TweenBuilder = function (manager, config)
248247
GetBoolean(value, 'flipY', flipY)
249248
);
250249

251-
// TODO: Calculate total duration
252-
253250
data.push(tweenData);
254251
}
255252
}

v3/src/tween/TweenManager.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ var TweenManager = new Class({
1111
// The Scene the Tween Manager belongs to (tweens are Scene specific, not Game global)
1212
this.scene = scene;
1313

14+
this.timeScale = 1;
15+
1416
this._add = [];
1517
this._pending = [];
1618
this._active = [];
@@ -114,6 +116,9 @@ var TweenManager = new Class({
114116
var list = this._active;
115117
var tween;
116118

119+
// Scale the delta
120+
delta *= this.timeScale;
121+
117122
for (var i = 0; i < list.length; i++)
118123
{
119124
tween = list[i];
@@ -142,14 +147,21 @@ var TweenManager = new Class({
142147
this._toProcess++;
143148
},
144149

150+
setGlobalTimeScale: function (value)
151+
{
152+
this.timeScale = value;
145153

154+
return this;
155+
},
146156

147-
148-
149-
globalTimeScale: function ()
157+
getGlobalTimeScale: function ()
150158
{
159+
return this.timeScale;
151160
},
152161

162+
163+
164+
153165
getAllTweens: function ()
154166
{
155167
},

v3/src/tween/components/Update.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ var Update = function (timestamp, delta)
1010

1111
if (this.useFrames)
1212
{
13-
delta = 1;
13+
delta = 1 * this.manager.timeScale;
1414
}
1515

16+
delta *= this.timeScale;
17+
1618
this.elapsed += delta;
1719
this.progress = Math.min(this.elapsed / this.duration, 1);
1820

v3/src/tween/components/UpdateTweenData.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ var SetStateFromEnd = function (tween, tweenData)
1414
tweenData.target.toggleFlipX();
1515
}
1616

17+
// Problem: The flip and callback and so on gets called for every TweenData that triggers it at the same time.
18+
// If you're tweening several properties it can fire for all of them, at once.
19+
1720
if (tweenData.flipY)
1821
{
1922
tweenData.target.toggleFlipY();

0 commit comments

Comments
 (0)