Skip to content

Cannot persist a chain tween after stop #7048

Closed

Description

@FranciscoCaetano88

Version

  • Phaser Version: 3.88.2
  • Operating system: MacOsx
  • Browser:

Description

I expected that using the persist flag (true) on a chain tween would prevent it from being disposed of when stopped. The documentation mentions this behaviour, but I can't make it work.

Example Test Code

class Example extends Phaser.Scene 
{
    constructor()
    {
        super();
    }

    preload()
    {
        this.load.setBaseURL('https://cdn.phaserfiles.com/v385');
        this.load.image('block', 'assets/sprites/block.png');
    }

    create()
    {
        var marker = this.add.image(100, 300, 'block').setAlpha(0.3);
        var image = this.add.image(100, 300, 'block');

        var tween = this.tweens.chain({
            paused: true,
            persist: true,
            tweens: [{
                targets: image,
                x: 700,
                delay: 1000,
                duration: 6000,
                ease: 'Power2'
            }]
        });

        var toggle = false;
        this.input.on('pointerdown', function () 
        {
            if (toggle) {
                tween.stop();
            } else {
                tween.play();
            }
            toggle = !toggle;
        });
    }
}

const config = {
    type: Phaser.AUTO,
    width: 800,
    height: 600,
    backgroundColor: '#2d2d2d',
    parent: 'phaser-example',
    scene: Example
};

const game = new Phaser.Game(config);

Additional Information

update function

Activity

  1. SBCGames commented on Feb 28, 2025

    @SBCGames
    Contributor

    I found this too. The doc says:

    A Tween that persists will not be destroyed by the Tween Manager, or when calling Tween.stop, and can be re-played as required.

    But calling the stop() destroys it.

    As a workaround, you can use pause()/resume() instead of calling stop()/play(). It will work, if you change the input handler like this:

            this.input.on('pointerdown', function () 
            {
                if (toggle) {
                    tween.pause();
                    
                } else {
                    if (tween.isFinished()){
                        image.x = 100;
                        tween.restart();
                    } else {
                        tween.resume();
                    }
                }
                toggle = !toggle;
            });
  2. zekeatchan commented on Mar 14, 2025

    @zekeatchan
    Contributor

    Hi @FranciscoCaetano88. 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.

  3. self-assigned this
    on Mar 14, 2025
  4. added a commit that references this issue on Mar 14, 2025
    780a41b
  5. locked as resolved and limited conversation to collaborators on Sep 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions