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

Impossible to stop tweens #96

Closed Robinfr closed 7 years ago

Robinfr commented 7 years ago

It seems to be impossible to stop/remove Tweens inbetween. In the latest version tweenjs_count is checked before removing tweens in Tween.removeTweens, however, this never seems to get set to more than 0..

Note, I'm using the NEXT version.

gskinner commented 7 years ago

I just tested this and it seems to be working fine with the latest. Could you please provide more information or a reproduction case? Please re-open this issue if you are able to repro.

Here's a fiddle showing it working: https://jsfiddle.net/4gfwt82a/

Robinfr commented 7 years ago

I'm sorry, the paused property does work. But the removeTweens function doesn't work. I'm expecting that if call that function, it should stop tweening as well, but it doesn't.

E.g.: https://jsfiddle.net/4gfwt82a/1/

gskinner commented 7 years ago

Hmm. I just tested your fiddle in Chrome, Firefox, and Safari, and it seems to work properly. For example, here's the output from Chrome 58: 10.365999999999998 20.868999999999993 30.92399999999999 40.97099999999999 // stopped at ~40 as expected.

https://jsfiddle.net/4gfwt82a/2/ (updated to use rawgit)

Is this happening only in a specific browser or something?

Robinfr commented 7 years ago

No, I'm also using Chrome 58. I find it very strange that it does work for you.. Is it possible that this is because I'm tweening a setter on an instance of an ES6 class?

gskinner commented 7 years ago

What result are you seeing on the fiddle?

If you are using a transpiler that seals the instance you are tweening, that could cause a problem, but otherwise I can't think of any reason tweening a setter on an ES6 class instance would cause an issue.

Robinfr commented 7 years ago

It seems to the problem with the timeline, I've updated the Fiddle to my exact problem: https://jsfiddle.net/4gfwt82a/3/

There doesn't seem to be any way to remove the tweens that are added to a timeline from an object.

gskinner commented 7 years ago

Ok. This is expected behaviour, but I can definitely see the confusion. When a tween is added to a timeline it is paused, and then advanced "manually" by the timeline. Since it's already paused, calling removeTweens doesn't do anything (it effectively just pauses the tweens). The workaround is to remove the tween from the timeline, or decouple the tween from its target.

In the new version of TweenJS I added a _parent property, which could potentially make it possible to make this work the way you expected, but I have to be very careful to avoid memory leaks through excess references.

Robinfr commented 7 years ago

Hmm alright, so in case I would want to dispose of a timeline and stop all of its tweens, how would I go about doing that?

gskinner commented 7 years ago

Just use: myTimeline.paused = true

Robinfr commented 7 years ago

This is what I'm doing at the moment, but does this actually clean up the tweens or does it leave objects in memory? I need a way to fully dispose of the timeline and the tweens in the timeline so they are no longer in memory.

gskinner commented 7 years ago

as long as you do not retain any direct references to the timeline or tweens in your own code then pausing the timeline is sufficient to stop all execution and free it for garbage collection.

Robinfr commented 7 years ago

Alright, thanks for the info!