Jump to content
Search Community

Kill the animation after it is complete

chenxin test
Moderator Tag

Recommended Posts

I have a some animations which cannot be reused, so I have to kill it after it is completed. Now I am doing it by calling the kill() method after the completion:

 

173358282_ScreenShot2019-11-05at3_49_46PM.thumb.png.95fbf10464d581d106aa16daf397e517.png

 

I am not sure if this is the correct way or the easiest way to do this.

Link to comment
Share on other sites

Hey chenxin. Thanks for being a Shockingly Green member! We couldn't do what we do without people like you.

 

Your approach here is fine if you really need to kill the animation. Most of the time it's fine to just let them live :) 

 

Alternatively you could use an onComplete for the timeline or an onComplete for the last tween of the timeline. There's not really a "correct" way as they're doing pretty much the same thing.

Link to comment
Share on other sites

kill just frees an animation up for garbage collection. It doesn't actually destroy an animation, so you can do this.

 

let tl = new TimelineLite()
tl.to(....)
tl.call(() => {
  tl.kill();
  tl.restart();
});

 

You have an animation stored in your tl variable, so it can't be garbage collected if your tl variable it's still in scope.

 

All these animations will be garbage collected some time after the animation has finished. There is no need to worry about killing in this context.

 

for (let i = 0; i < 100000; i++) {
  createAnimation();
}

function createAnimation() {
  let tl = new TimelineMax()
    .to(...)
    .to(...)
}

 

  • Like 4
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...