Skip to content

Commit 49b1896

Browse files
committed
Added Tween.percent variable and tidied up the time values.
1 parent 9caa13e commit 49b1896

2 files changed

Lines changed: 33 additions & 23 deletions

File tree

src/tween/Tween.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ Phaser.Tween = function (object, game, manager) {
5959
*/
6060
this._duration = 1000;
6161

62+
/**
63+
* @property {number} percent - A value between 0 and 1 that represents how far through the duration this tween is.
64+
* @readOnly
65+
*/
66+
this.percent = 0;
67+
6268
/**
6369
* @property {number} _repeat - Private repeat counter.
6470
* @private
@@ -307,7 +313,7 @@ Phaser.Tween.prototype = {
307313

308314
// delays before the tween start are also affected by the time.slowMotion factor
309315
// TODO: if the slowMotion factor changes during the delay, this will continue to use the original value until the delay expires!
310-
this._startTime = this.game.time.now + this._delayTime * this.game.time.slowMotion;
316+
this._startTime = this.game.time.time + this._delayTime * this.game.time.slowMotion;
311317

312318
for (var property in this._valuesEnd)
313319
{
@@ -690,17 +696,16 @@ Phaser.Tween.prototype = {
690696

691697
var property;
692698

693-
694699
if (this._onStartCallbackFired === false)
695700
{
696701
this.onStart.dispatch(this._object);
697702
this._onStartCallbackFired = true;
698703
}
704+
705+
this.percent = (time - this._startTime) / (this._duration * this.game.time.slowMotion);
706+
this.percent = this.percent > 1 ? 1 : this.percent;
699707

700-
var percent = (time - this._startTime) / (this._duration * this.game.time.slowMotion);
701-
percent = percent > 1 ? 1 : percent;
702-
703-
var value = this._easingFunction(percent);
708+
var value = this._easingFunction(this.percent);
704709

705710
for (property in this._valuesEnd)
706711
{
@@ -737,7 +742,7 @@ Phaser.Tween.prototype = {
737742
}
738743
}
739744

740-
if (percent == 1)
745+
if (this.percent === 1)
741746
{
742747
if (this._repeat > 0)
743748
{

src/tween/TweenManager.js

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -70,43 +70,48 @@ Phaser.TweenManager.prototype = {
7070
},
7171

7272
/**
73-
* Remove all tweens from a specific object, array of objects or group.
73+
* Remove all tweens from a specific object, array of objects or Group.
74+
*
7475
* @method Phaser.TweenManager#removeFrom
7576
* @param {object|object[]|Phaser.Group} obj - The object you want to remove the tweens from.
76-
* @param {boolean} children - If passing a group, setting this to true will remove the tweens from all of its children instead of the group itself.
77+
* @param {boolean} [children=true] - If passing a group, setting this to true will remove the tweens from all of its children instead of the group itself.
7778
*/
78-
removeFrom: function(obj, children) {
79-
80-
var o, c, t, len;
79+
removeFrom: function (obj, children) {
8180

81+
if (typeof children === 'undefined') { children = true; }
82+
83+
var i;
84+
var len;
85+
8286
if (Array.isArray(obj))
8387
{
84-
for (o = 0, len = obj.length; o < len; o++)
88+
for (i = 0, len = obj.length; i < len; i++)
8589
{
86-
this.removeFrom(obj[o]);
90+
this.removeFrom(obj[i]);
8791
}
8892
}
8993
else if (obj.type === Phaser.GROUP && children)
9094
{
91-
for (c = 0, len = obj.children.length; c < len; c++)
95+
for (var i = 0, len = obj.children.length; i < len; i++)
9296
{
93-
this.removeFrom(obj.children[c]);
97+
this.removeFrom(obj.children[i]);
9498
}
9599
}
96100
else
97101
{
98-
for (t = 0, len = this._tweens.length; t < len; t++)
102+
for (i = 0, len = this._tweens.length; i < len; i++)
99103
{
100-
if (obj === this._tweens[t]._object)
104+
if (obj === this._tweens[i]._object)
101105
{
102-
this.remove(this._tweens[t]);
106+
this.remove(this._tweens[i]);
103107
}
104108
}
105-
for (t = 0, len = this._add.length; t < len; t++)
109+
110+
for (i = 0, len = this._add.length; i < len; i++)
106111
{
107-
if (obj === this._add[t]._object)
112+
if (obj === this._add[i]._object)
108113
{
109-
this.remove(this._add[t]);
114+
this.remove(this._add[i]);
110115
}
111116
}
112117
}
@@ -186,7 +191,7 @@ Phaser.TweenManager.prototype = {
186191

187192
while (i < numTweens)
188193
{
189-
if (this._tweens[i].update(this.game.time.now))
194+
if (this._tweens[i].update(this.game.time.time))
190195
{
191196
i++;
192197
}

0 commit comments

Comments
 (0)