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

Cannot persist a chain tween after stop #7048

Open
FranciscoCaetano88 opened this issue Feb 17, 2025 · 1 comment
Open

Cannot persist a chain tween after stop #7048

FranciscoCaetano88 opened this issue Feb 17, 2025 · 1 comment

Comments

@FranciscoCaetano88
Copy link

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

@SBCGames
Copy link

SBCGames commented Feb 28, 2025

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;
        });

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

No branches or pull requests

2 participants