Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Stever1388 opened this issue Jan 13, 2025 · 1 comment

Comments

@Stever1388
Copy link

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();
      });
    });
  }
}
@zekeatchan
Copy link
Collaborator

Hi @Stever1388. Thanks for submitting this issue. We have fixed this and pushed it to the master branch. It will be part of the next release. Do test it out and let us know if you encounter any issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants