CreateJS / TweenJS

A simple but powerful tweening / animation library for Javascript. Part of the CreateJS suite of libraries.
http://createjs.com/
MIT License
3.56k stars 967 forks source link

Problems starting a Tween after it's complete #89

Closed JonatanGC closed 7 years ago

JonatanGC commented 7 years ago

Hi!

I need to move a shape with a tween to multiple positions, I can't use multiple .to() in a Tween, because I need to do some operations with the next position before assigning it after it's first .to() it's completed.

I think the problem it's because the Tween is paused and I've tried to call play() after setting the to() but I haven't figured out how to make it work.

https://jsfiddle.net/JonatanGC/1d3ysz5p/2/

lannymcnie commented 7 years ago

A simple fix is adding a short wait() call at the end. I believe what is happening is that the tween is prematurely ending.

tween.to(to, 500)
      .call(moveTween, [tween]).wait(50);

I would think that calling setPaused(false) or play() would work, so this is worth looking into -- but in the mean time, that short wait delay ensures that the tween queue continues to stay alive when the call() is made.

Note that I simplified your moveTween call (see example). Here is a working version: https://jsfiddle.net/1d3ysz5p/3/

Leaving this open to track this issue.

JonatanGC commented 7 years ago

Thx for the quick response, I will use that.

lannymcnie commented 7 years ago

@gskinner Check if TweenJS refactor handles this case.

gskinner commented 7 years ago

That solution won't work properly, because in some cases the time between ticks may be longer than 50ms (you can simulate this by switching tabs on the jsfiddle). A more reliable solution would be a 1ms delay on a setPaused(false) call.

https://jsfiddle.net/1d3ysz5p/5/

Is there a specific reason you don't just create a new Tween? That would be more efficient over the long haul, unless you are generating a series of steps that you need to "record" and play back again.

https://jsfiddle.net/1d3ysz5p/4/

I don't think the core of this is a bug necessarily. The current idea is that the tween ends (ie. fires its complete event and pauses) after it's entire chain completes. It's further complicated by features like looping and (in the upcoming build) bouncing and reversed.

Closing, but feel free to comment or reopen if you think there are valid reasons for a change.