Question

Do TweenMax instances need to be cleared/unset/killed manually or is it done automatically? Here's the following code I'm using to add effect to a piece of text on screen:

TweenMax.to($('#score'), 0.25, { fontSize: '56px', onComplete: myFunction });

function myFunction(){
    TweenMax.to($('#score'), 0.125, { fontSize: '28px' });
}

This piece of code runs a lot and I'm afraid over time some garbage would pile up.

Was it helpful?

Solution

You could try and use the kill() method:

Also you can store your reference to the tween in a variable:

Check out this Example

var myTween = TweenMax.to($('#score'), 0.25, { fontSize: '56px', onComplete: myFunction });

function myFunction(){
   myTween.kill();
   myTween = TweenMax.to($('#score'), 0.125, { fontSize: '28px' });
}

For more info checkout the GreenSock TweenMax Docs.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top