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

Tween restart() doesn't always work #4793

Closed
spayton opened this issue Oct 8, 2019 · 1 comment
Closed

Tween restart() doesn't always work #4793

spayton opened this issue Oct 8, 2019 · 1 comment

Comments

@spayton
Copy link
Contributor

spayton commented Oct 8, 2019

Version

  • Phaser Version: 3.19.0+
  • Operating system: Win10

Description

A tween will not reliably restart using the restart() function. This appears to happen when the tween state is PENDING_REMOVE at the time the restart() is called. The PENDING_REMOVE state appears to be a transitional state, on the way to REMOVED, begun when the tween completes.

Expected behaviour would be for the restart() call to work everytime.

Example Test Code

The test case is based on the restart example using v3.19.0. The bright arrow will tween towards the dim arrow, when it gets there it should restart the animation and loop that sequence. You will see that sometimes it hangs at the beginning.

The test case was designed to trigger a tween restart() after the same period of time taken for the tween to naturally complete, sometimes it will catch the tween in the PENDING_REMOVE state and it will not retrigger.

To run the test case, launch the example, in the editor, running phaser v3.19.0, using this link:

http://labs.phaser.io/edit.html?src=src\tweens\restart.js&v=3.19.0

then replace the code with this and click the 'Run Code' button:

new Phaser.Game({
    width: 800,
    height: 600,
    backgroundColor: '#2d2d2d',
    parent: 'phaser-example',
    scene: {
        preload: preload,
        create: create,
        update: update
    }
});

var text, arrow, tween;

function preload ()
{
    this.load.image('arrow', 'assets/sprites/arrow.png');
}

function create ()
{
    text = this.add.text(30, 20, '0', { font: '16px Courier', fill: '#00ff00' });

    this.add.image(700, 300, 'arrow').setAlpha(0.5);
    arrow = this.add.image(100, 300, 'arrow');

    tween = this.tweens.add({
        targets: arrow,
        x: 700,
        ease: 'Linear',
        duration: 1000
    });

    setInterval(tween.restart.bind(tween), 1000);
}

function update ()
{
    text.setText('Progress : ' + tween.progress + '\nState    : ' + tween.state);
}
@photonstorm
Copy link
Collaborator

Thank you for submitting this issue. We have fixed this and the fix has been pushed to the master branch. It will be part of the next release. If you get time to build and test it for yourself we would appreciate that.

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