Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
mikebolt opened this issue Dec 13, 2016 · 5 comments
Closed

Comments

@mikebolt
Copy link
Contributor

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.

@sole
Copy link
Member

sole commented Jan 24, 2017

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:
tweenjs/discuss#3

@dalisoft
Copy link
Collaborator

@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

@trusktr
Copy link
Member

trusktr commented Sep 16, 2017

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

@trusktr trusktr changed the title Allow tween reuse Make a reset method (allows tween reuse in an object pool for example) Sep 16, 2017
@trusktr
Copy link
Member

trusktr commented Dec 31, 2020

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
Copy link
Member

trusktr commented Apr 23, 2023

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 trusktr closed this as completed Apr 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants