Skip to content

Calling tween.stop(0) runs for an additional delta before stopping, so tween isn't truly 100% "reset" #5986

@Mesonyx

Description

@Mesonyx

EDIT: I created a PR that seems to fix this issue


Version

  • Phaser Version: 3.5.5
  • Operating system: OSX Mojave 10.14.6
  • Browser: Google Chrome

Description

When calling stop() on a Tween with a resetTo param of 0 (indicating you wish to revert the tween back to its pre-tweened state), the tween actually runs for a single additional delta before stopping.

I noticed this because I'm using tweens to animate the mouths of NPC's in my game using scaleX and scaleY tweens. Although imperceptible at first, their mouths noticeably shrunk in size during a long enough run-time, despite me reverting the tween to the supposed default state with stop(0) when they were done talking.

Example Test Code

I've created a Code pen of the issue here

Clicking toggles the tween on and off with stop(0).

After starting/stopping about a dozen times, the box is definitely smaller when compared with the reference shape immediately below it.

I've also output the scaleX of the object being tweened, so we can definitively verify that the box is not actually resetting to its full, pre-tween scaleX value of 1.

Additional Information

I believe this behavior occurs because the seek() method in the Tween.js class runs with a do/while loop, so the condition is checked after the tween iterates a single delta (line 972).

From my understanding of how Tweens work from the docs/reading the code, would it work to simply skip this loop entirely if the the toPosition is equal to 0?

Metadata

Metadata

Assignees

No one assigned

    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