Skip to content

Tweens with persist:true and a completeDelay are destroyed on completion and cannot be replayed #7008

Closed
@Stever1388

Description

@Stever1388

Version

  • Phaser Version: Phaser 3.87.0
  • Operating system: Windows
  • Browser: Chrome

Description

If you add persist:true and a completeDelay to a Tween, you cannot replay it later after it completes, as the tween gets destroyed. The expected behavior is that you would be able to play it again.

Example Test Code

The example below shows two tweens, one with completeDelay and one without, both with persist:true. The first tween can be replayed over and over as needed, the second one cannot, and you will get the Cannot play destroyed Tween warning in the console.

export default class PersistTweenIssue extends Phaser.Scene {
  create() {
    this.objToTween1 = this.add.circle(this.scale.width / 4,this.scale.height / 2,50,0xff0000);
    this.objToTween2 = this.add.circle(this.scale.width / 4 * 3,this.scale.height / 2,50,0xff0000);

    const persistTweenWithoutCompleteDelay = this.add.tween({ targets: this.objToTween1, duration: 500, props: { scale: 0 }, yoyo: true, persist: true });
    const persistTweenWithCompleteDelay = this.add.tween({ targets: this.objToTween2, duration: 500, props: { scale: 0 }, yoyo: true, persist: true, completeDelay: 500 });

    persistTweenWithoutCompleteDelay.on(Phaser.Tweens.Events.TWEEN_COMPLETE, () => {
      this.time.delayedCall(500, () => {
        persistTweenWithoutCompleteDelay.play();
      });
    });

    persistTweenWithCompleteDelay.on(Phaser.Tweens.Events.TWEEN_COMPLETE, () => {
      this.time.delayedCall(500, () => {
        persistTweenWithCompleteDelay.play();
      });
    });
  }
}

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions