Jump to content
GreenSock

Search In
  • More options...
Find results that contain...
Find results in...
thrasherstudios77

Performance hit

Recommended Posts

I am trying to find a way to completely remove some tween effects from my video as I have noticed that once they are applied the CPU takes a performance hit of about double.

 

So I apply an effect to my video when the video is paused and then it gets removed when the video is playing again. And I try to remove the effect completely like this

 

private function removeTweens():void {
  TweenMax.to(_video, 0.6, {  ease:Circ.easeOut, blurFilter: { blurX:0, blurY:0 },colorMatrixFilter: {brightness:1, contrast:1, saturation:1 },

	  onComplete: function():void {
		  TweenMax.killTweensOf(_video);
	  }
  } );
}

 

The first part brings the video back to looking normal and then on tween complete I try and kill the tween from memory TweenMax.killTweensOf(_video);

 

If I never add the effect at all the CPU hovers around 5-6, but when I add the effect then remove it starts hovering at 12-14%. Is there anything more I can do to remove tweens from memory??

Link to comment
Share on other sites

It sounds like you still have filters applied. To get rid of them at the end of the tween, simply set remove:true like:

 

TweenMax.to(_video, 0.6, {  ease:Circ.easeOut, blurFilter: { blurX:0, blurY:0, remove:true }});

 

Same for the colorMatrixFilter object.

Link to comment
Share on other sites

To take this maybe a step further is there a way to dynamically remove tweens from an object. Get a list of current tween properties on a tweened object then say run a loop to remove each of these tween properties

 

private function removeTweens(media:DisplayObject):void {

//Run a loop to find all the tween properties on an object
  // Of course this doesn't work but just to get the idea across
  for each(var prop in tweenProps){
   prop.remove = true
  }
}

 

Now that I know that keeping a tween alive on an object takes a bit of a hit on performance I would really like to start removing all my tweens from my objects once they are not needed anymore. And having a function like above would allow me to send any object with any amount of tweened properties to it and have it stripped clean of overhead.

 

I looked into the vars object of a tween also the TweenMaxVars, but not sure how to get what I need to work. What is the syntax for adding a blur filter using TweenMaxVars, this doesn't seem to work?

 


var tweenProps:TweenMaxVars = new TweenMaxVars().blurFilter(blurX:3, blurY:3).colorMatrixFilter(brightness:0.95, contrast:1.1, saturation:0.35);
TweenMax.to(_video, 0.6, { ease:Circ.easeOut, tweenProps} );

Link to comment
Share on other sites

Now that I know that keeping a tween alive on an object takes a bit of a hit on performance I would really like to start removing all my tweens from my objects once they are not needed anymore. And having a function like above would allow me to send any object with any amount of tweened properties to it and have it stripped clean of overhead.

 

Just to be clear, the performance hit you experienced previously had nothing to do with TweenMax - it simply had to do with the fact that you still had a filter applied to your object and Flash forces cacheAsBitmap to true whenever a DisplayObject has a filter and it can use up some extra memory. But if you do an x or y or alpha or pretty much any other type of property tween on your object, there is no such trade off. It's not the tween that was causing the problems - it was the filter.

 

And the tween's don't get "attached" to the target object. Tweens are separate and distinct objects that simply set property values on each update/frame while the tween is active. Once the tween completes, it becomes eligible for garbage collection and is swept away relatively soon thereafter. Tweens do NOT generally build up or drain performance over time (unless you're doing something REALLY weird).

 

It really sounds like you got spooked by the filter thing and are worrying about things that you need not worry about. I think that adding the code that you're talking about (looping through all the tween properties and trying to individually kill each one) is actually going to HURT performance much more than it would help. A lot of effort went into building TweenLite and TweenMax in a way that would maximize performance and minimize the hassle you need to go through to have things cleaned up properly.

 

To answer your question, though, you can kill all the tweens of any object anytime with TweenMax.killTweensOf(yourObject). To kill individual tweening properties inside of a specific tween, you can use the killVars() method for v11, or the new v12 allows it with the kill() method. See the ASDocs for details.

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.
×