tween.js icon indicating copy to clipboard operation
tween.js copied to clipboard

Make a reset method (allows tween reuse in an object pool for example)

Open mikebolt opened this issue 9 years ago • 4 comments

We should allow users to reuse tween objects. This could lead to some performance improvements for advanced users who are willing to set up a memory pool for tween objects. Currently you can reuse a tween if it has the same tweened object. In order to allow full reuse we would need to add a function such as "setObject", or alternatively we could add a new function such as "reset" that would completely reinitialize the tween with a new tweened object. This change could easily break the code, so it would need to be done carefully.

mikebolt avatar Dec 13 '16 06:12 mikebolt

I think it is a bit dangerous to talk about 'performance improvements' when we do not really have a baseline benchmark yet. We should focus on getting that one ready before we try to optimise more. Filed a bug for this but haven't seen much traction so far: https://github.com/tweenjs/discuss/issues/3

sole avatar Jan 24 '17 16:01 sole

@mikebold We can reuse tween via reset tween#to method. Right? But this not mean performance improvement, when user need that tween again. Anyway TWEEN#update does loop check and finding update boolean

dalisoft avatar Mar 19 '17 18:03 dalisoft

This shouldn't be too hard to implement. A simple reset functionality can reset all state to the same as in the constructor.

trusktr avatar Sep 16 '17 20:09 trusktr

For reference, here is an example that shows a workaround on how to reset a tween (see the stopTween method):

https://codepen.io/trusktr/pen/2870d850113cad70f06464e3e0bdb72a

trusktr avatar Dec 31 '20 02:12 trusktr

Closing, as I believe that stopping and re-starting a tween is a good enough way to reset a tween for this rare use case. If there's a use case where changing a tween's target object would really help performance, we can re-open and check it out.

trusktr avatar Apr 23 '23 05:04 trusktr