Skip to content

chained tweens cannot be stopped in onComplete callback (chained tweens start in the NEXT update after onComplete) #397

Closed
@gera2ld

Description

@gera2ld

Create two tweens and chain them:

const tween1 = new TWEEN.Tween({})
.to({}, 500)
.onComplete(() => {
  console.log('complete');
  tween1.stop();
  tween2.stop();
});
const tween2 = new TWEEN.Tween({})
.to({}, 500);
tween1.chain(tween2);
tween2.chain(tween1);

In onComplete callback, I try to stop both of them, but it does not work and just loops forever.

Looking into the code, I find that, in onComplete callback tween2._isPlaying is set to false, after that, the chained tween2 is started no matter if it should be stopped, so the stop does not make a difference to the result.
So a workaround is to wrap it in setTimeout:

.onComplete(() => {
  setTimeout(() => {
    tween1.stop();
    tween2.stop();
  });
})

Anyway, it's ugly and doesn't make sense.

This has worked before, I think the refactor has broken a lot of things. 😞

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions