Skip to content

Commit 1df98d8

Browse files
committed
You can now call Tween.to again on a Tween that has already completed. This will re-use the same tween, on the original object, without having to recreate the Tween again. This allows a single tween instance to be re-used multiple times, providing they are linked to the same object (thanks InsaneHero)
1 parent 26a1a08 commit 1df98d8

2 files changed

Lines changed: 21 additions & 14 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ Version 2.1.4 - "Bethal" - in development
7777

7878
* Cache.getRenderTexture will retrieve a RenderTexture that is stored in the Phaser Cache. This method replaces Cache.getTexture which is now deprecated.
7979
* Cache.autoResolveURL is a new boolean (default `false`) that automatically builds a cached map of all loaded assets vs. their absolute URLs, for use with Cache.getURL and Cache.checkURL. Note that in 2.1.3 and earlier this was enabled by default, but has since been moved behind this property which needs to be set to `true` *before* you load any assets to enable.
80+
* You can now call Tween.to again on a Tween that has already completed. This will re-use the same tween, on the original object, without having to recreate the Tween again. This allows a single tween instance to be re-used multiple times, providing they are linked to the same object (thanks InsaneHero)
8081

8182

8283
### Updates

src/tween/Tween.js

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ Phaser.Tween.prototype = {
214214

215215
var self;
216216

217-
if (this._parent)
217+
if (this._parent && this._parent !== this)
218218
{
219219
self = this._manager.create(this._object);
220220
this._lastChild.chain(self);
@@ -240,6 +240,10 @@ Phaser.Tween.prototype = {
240240
{
241241
self._delayTime = delay;
242242
}
243+
else
244+
{
245+
self._delayTime = 0;
246+
}
243247

244248
self._yoyo = yoyo;
245249

@@ -283,10 +287,10 @@ Phaser.Tween.prototype = {
283287
},
284288

285289
/**
286-
* Starts the tween running. Can also be called by the autoStart parameter of Tween.to.
290+
* Starts the tween running. Can also be called by the autoStart parameter of `Tween.to.`
287291
*
288292
* @method Phaser.Tween#start
289-
* @return {Phaser.Tween} Itself.
293+
* @return {Phaser.Tween} This tween. Useful for method chaining.
290294
*/
291295
start: function () {
292296

@@ -325,7 +329,6 @@ Phaser.Tween.prototype = {
325329
}
326330

327331
this._valuesStartRepeat[property] = this._valuesStart[property] || 0;
328-
329332
}
330333

331334
return this;
@@ -451,16 +454,18 @@ Phaser.Tween.prototype = {
451454
},
452455

453456
/**
454-
* Stops the tween if running and removes it from the TweenManager. If there are any onComplete callbacks or events they are not dispatched.
457+
* Stops the tween if running and removes it from the TweenManager.
458+
* If called directly and there are any `onComplete` callbacks or events they are not dispatched.
455459
*
456460
* @method Phaser.Tween#stop
457-
* @return {Phaser.Tween} Itself.
461+
* @return {Phaser.Tween} This tween. Useful for method chaining.
458462
*/
459463
stop: function () {
460464

461465
this.isRunning = false;
462466

463467
this._onUpdateCallback = null;
468+
this._onStartCallbackFired = false;
464469

465470
this._manager.remove(this);
466471

@@ -473,11 +478,12 @@ Phaser.Tween.prototype = {
473478
*
474479
* @method Phaser.Tween#delay
475480
* @param {number} amount - The amount of the delay in ms.
476-
* @return {Phaser.Tween} Itself.
481+
* @return {Phaser.Tween} This tween. Useful for method chaining.
477482
*/
478483
delay: function (amount) {
479484

480485
this._delayTime = amount;
486+
481487
return this;
482488

483489
},
@@ -487,7 +493,7 @@ Phaser.Tween.prototype = {
487493
*
488494
* @method Phaser.Tween#repeat
489495
* @param {number} times - How many times to repeat.
490-
* @return {Phaser.Tween} Itself.
496+
* @return {Phaser.Tween} This tween. Useful for method chaining.
491497
*/
492498
repeat: function (times) {
493499

@@ -503,7 +509,7 @@ Phaser.Tween.prototype = {
503509
*
504510
* @method Phaser.Tween#yoyo
505511
* @param {boolean} yoyo - Set to true to yoyo this tween.
506-
* @return {Phaser.Tween} Itself.
512+
* @return {Phaser.Tween} This tween. Useful for method chaining.
507513
*/
508514
yoyo: function(yoyo) {
509515

@@ -523,7 +529,7 @@ Phaser.Tween.prototype = {
523529
*
524530
* @method Phaser.Tween#easing
525531
* @param {function} easing - The easing function this tween will use, i.e. Phaser.Easing.Linear.None.
526-
* @return {Phaser.Tween} Itself.
532+
* @return {Phaser.Tween} This tween. Useful for method chaining.
527533
*/
528534
easing: function (easing) {
529535

@@ -538,7 +544,7 @@ Phaser.Tween.prototype = {
538544
*
539545
* @method Phaser.Tween#interpolation
540546
* @param {function} interpolation - The interpolation function to use (Phaser.Math.linearInterpolation by default)
541-
* @return {Phaser.Tween} Itself.
547+
* @return {Phaser.Tween} This tween. Useful for method chaining.
542548
*/
543549
interpolation: function (interpolation) {
544550

@@ -552,7 +558,7 @@ Phaser.Tween.prototype = {
552558
* You can pass as many tweens as you like to this function, they will each be chained in sequence.
553559
*
554560
* @method Phaser.Tween#chain
555-
* @return {Phaser.Tween} Itself.
561+
* @return {Phaser.Tween} This tween. Useful for method chaining.
556562
*/
557563
chain: function () {
558564

@@ -571,7 +577,7 @@ Phaser.Tween.prototype = {
571577
* .to({ y: 0 }, 1000, Phaser.Easing.Linear.None)
572578
* .loop();
573579
* @method Phaser.Tween#loop
574-
* @return {Phaser.Tween} Itself.
580+
* @return {Phaser.Tween} This tween. Useful for method chaining.
575581
*/
576582
loop: function() {
577583

@@ -586,7 +592,7 @@ Phaser.Tween.prototype = {
586592
* @method Phaser.Tween#onUpdateCallback
587593
* @param {function} callback - The callback to invoke each time this tween is updated.
588594
* @param {object} callbackContext - The context in which to call the onUpdate callback.
589-
* @return {Phaser.Tween} Itself.
595+
* @return {Phaser.Tween} This tween. Useful for method chaining.
590596
*/
591597
onUpdateCallback: function (callback, callbackContext) {
592598

0 commit comments

Comments
 (0)