Skip to content

Commit 2d3c905

Browse files
committed
Calling Tween.play on a tween that had already finished and was pending removal will stop the tween from getting stuck in an isPlaying state and will restart the tween again from the beginning. Calling play on a Tween that is already playing does nothing. Fix phaserjs#4184
1 parent 0012ed3 commit 2d3c905

2 files changed

Lines changed: 15 additions & 5 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,8 @@ Notes:
129129
* Calling `Tween.restart` multiple times in a row would cause the tween to freeze. It will now disregard all additional calls to `restart` if it's already in a pending state (thanks @rgk)
130130
* Tween Timelines would only apply the `delay` value of a child tween once and not on loop. Fix #3841 (thanks @Edwin222 @Antriel)
131131
* `Texture.add` will no longer let you add a frame to a texture with the same name or index as one that already exists in the texture. Doing so will now return `null` instead of a Frame object, and the `frameTotal` will never be incremented. Fix #4459 (thanks @BigZaphod)
132-
* The InputPlugin will now dispatch an update event regardless, allowing the Gamepad Plugin to update itself every frame, regardless of DOM events. This allows Gamepads to work correctly again. Fix #4414 (thanks @CipSoft-Components)
132+
* The InputPlugin will now dispatch an update event regardless, allowing the Gamepad Plugin to update itself every frame, regardless of OM events. This allows Gamepads to work correctly again. Fix #4414 (thanks @CipSoft-Components)
133+
* Calling `Tween.play` on a tween that had already finished and was pending removal will stop the tween from getting stuck in an `isPlaying` state and will restart the tween again from the beginning. Calling `play` on a Tween that is already playing does nothing. Fix #4184 (thanks @SamCode)
133134

134135

135136
### Examples, Documentation and TypeScript

src/tweens/tween/Tween.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -635,25 +635,34 @@ var Tween = new Class({
635635
* Starts a Tween playing.
636636
*
637637
* You only need to call this method if you have configured the tween to be paused on creation.
638+
*
639+
* If the Tween is already playing, calling this method again will have no effect. If you wish to
640+
* restart the Tween, use `Tween.restart` instead.
641+
*
642+
* Calling this method after the Tween has completed will start the Tween playing again from the start.
643+
* This is the same as calling `Tween.seek(0)` and then `Tween.play()`.
638644
*
639645
* @method Phaser.Tweens.Tween#play
640646
* @since 3.0.0
641647
*
642-
* @param {boolean} resetFromTimeline - Is this Tween being played as part of a Timeline?
648+
* @param {boolean} [resetFromTimeline=false] - Is this Tween being played as part of a Timeline?
643649
*
644650
* @return {this} This Tween instance.
645651
*/
646652
play: function (resetFromTimeline)
647653
{
648-
if (this.state === TWEEN_CONST.ACTIVE)
654+
if (resetFromTimeline === undefined) { resetFromTimeline = false; }
655+
656+
if (this.state === TWEEN_CONST.ACTIVE || this.state === TWEEN_CONST.PENDING_ADD)
649657
{
650658
return this;
651659
}
652660
else if (this.state === TWEEN_CONST.PENDING_REMOVE || this.state === TWEEN_CONST.REMOVED)
653661
{
654-
this.init();
662+
this.seek(0);
655663
this.parent.makeActive(this);
656-
resetFromTimeline = true;
664+
665+
return this;
657666
}
658667

659668
var onStart = this.callbacks.onStart;

0 commit comments

Comments
 (0)