cookietran Posted July 29, 2020 Share Posted July 29, 2020 Could someone explain the difference between using kill() or clear() on a timeline? That is, besides kill() being able to kill individual tweens, lets assume we're using kill() on the entire timeline itself. The documentation is unclear (use kill to kill a tween; define kill?). If they're the same, then why use clear(), other than the timeline instance being preserved? And, I'm interested if either resets the positions of elements in a timeline to their beginning position, or what the best way to go about that is? Thanks! Link to comment Share on other sites More sharing options...
ZachSaucier Posted July 29, 2020 Share Posted July 29, 2020 Hey cookietran and welcome to the GreenSock forums. Clear empties a timeline so you can reuse it. Kill removes the timeline completely so it can be garbage collected - it can't be reused. 5 hours ago, cookietran said: I'm interested if either resets the positions of elements in a timeline to their beginning position, or what the best way to go about that is? tl.progress(0) is the best way to go about that Link to comment Share on other sites More sharing options...
OSUblake Posted July 29, 2020 Share Posted July 29, 2020 9 hours ago, ZachSaucier said: Kill removes the timeline completely so it can be garbage collected - it can't be reused. You can use an animation after kill. kill frees the animation up garbage collection. If you still have a reference to the timeline, then it obviously can't be freed for garbage collection, and you can play it again. 1 Link to comment Share on other sites More sharing options...
ZachSaucier Posted July 30, 2020 Share Posted July 30, 2020 14 hours ago, OSUblake said: You can use an animation after kill. You're right - I believe you can reuse timelines but not tweens that are killed. Sorry for misspeaking. @GreenSock can correct me if I'm wrong. Link to comment Share on other sites More sharing options...
OSUblake Posted July 30, 2020 Share Posted July 30, 2020 You can reuse anything that gets killed. It doesn't destroy the animation. It just stops it from playing and frees it up for garbage collection inside gsap's internal cache. It doesn't free it up for garbage collection if you still have a reference to it i.e. storing it in a variable. See the Pen 5da1e4c25397934adc50b5a567620896 by osublake (@osublake) on CodePen 2 Link to comment Share on other sites More sharing options...
GreenSock Posted July 30, 2020 Share Posted July 30, 2020 I definitely wouldn't recommend calling kill() on a tween/timeline that you plan to reuse later. Technically that can work sometimes, but: It isn't intuitive. Killing is intended to make something dead If the goal is to reuse it, I think it's far more clear to just pause() it. Even if it technically works in some cases now, there's a chance that updates will be made in the future that would cause those cases not to work. 1 Link to comment Share on other sites More sharing options...
OSUblake Posted July 30, 2020 Share Posted July 30, 2020 Yeah, I wasn't suggesting using it for that. My point is that it doesn't destroy the actual animation. 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now