Jump to content
Search Community

launching 5 tweens per second stalls machine

lastnerve test
Moderator Tag

Recommended Posts

I've been trying for about a week to get this fairly simple animation to run without overloading my old machine's CPU (1.8 gz, 1.5g RAM). A recent test on a machine with 2.4 gz and 4g RAM gave similar results. I know I'm doing something wrong but I sure need some help to figure out what it is.

 

I launch the same tween with each click so a rapid clicker can launch as many as 5 tweens per second. Each tween has a duration of 1and all run well until about 5 rapid clicks, then everything starts to slow down.

If I click about 20 times the animation stops for about 10 seconds, starts again, and then finishes the tweens that I launched. But, if I start clicking again then all the tweens start out dog slow and my machine stalls. So it looks as if my code is maybe using up all my RAM.

 

The tween below uses a 2 px dot (attached 16 times) and moves each one radially so that it looks like an expanding cirlce of dots.

 

Am I simply being too ambitious with the tweens?

 

Also, does "TweenMax.allFrom" actually run a separate tween for each object in it's assigned array?

Is it more efficient than running a separate tweenLite for each array object?

 

var dot_Array:Array = new Array();
var dot_mc:MovieClip; 
var dot_Timeline:TimelineLite = new TimelineLite;

function dumpClips():Void {
for(var i:Number = 0; i < 16; i++){
	removeMovieClip(dot_Array[i]);		
}
remove(dot_Timeline);
}

function movedot():Void {
for(var i:Number = 0; i < 16; i++){
	dot_mc = this.attachMovie("dot", "dot", getNextHighestDepth());
	dot_Array[i] = dot_mc;

	dot_Array[i]._alpha = 0;
     // _root.xcd_Array and _root.ycd_Array  contain the ending positions for each dot
	dot_Array[i]._x = _root.xcd_Array[i];
	dot_Array[i]._y = _root.ycd_Array[i];
}

dot_Timeline.append(new TweenMax.allFrom(dot_Array, 1, 
  {_x:0, _y:0, _alpha:100, ease:Linear.easeNone, overwrite:false, onComplete: dumpClips}, 0));

}

Link to comment
Share on other sites

It's late and I'm brain dead at the moment, so I don't have time to look into this in depth right now, but I have a few questions for you:

 

1) Why are you giving all your dots the same name? That's a really bad idea in AS2 - it can confuse the Flash Player (and to some degree TweenLite/Max too). You should append the depth level to the name or something so that they're unique.

 

2) Why are you storing your tweens in a TimelineLite? Do you need to store them there for use later? Why not just fire of normal tweens? If you put them into a TimelineLite, it gives you lots of flexibility for controlling the group as a whole, but in your situation, it's not a controlled scenario - you're shoving 16 new tweens in there every time the user clicks.

 

3) Did you realize that every time the user clicks, you're replacing the contents of dot_Array, but your dumpClips() won't be able to dump the ones that you replaced in the array. In other words, if the user clicks, you put 16 into the array, then if they click quickly again, those 16 clips are still alive, but you replace their references in the array with 16 new ones, so when those finish tweening, dumpClips() gets called, and only the 2nd (last) set of 16 actually get dumped. The others stick around. I assume you don't want that.

 

4) Why are you doing allFrom() instead of allTo()? I've seen some folks get confused by the allFrom() and normally I recommend doing allTo() in most situations. Not that it's necessarily wrong in this situation. I was just curious about your reasoning.

 

Oh, and to answer your question, yes, TweenMax.allFrom() creates a unique TweenMax instance for each object in the array.

 

For the record, I highly doubt that TweenMax is using up all your ram with these tweens. I've had 1000 tweens running in AS2 without much of a problem at all. It performs very well under pressure.

Link to comment
Share on other sites

Wow, I wasn't expecting a response from you so soon. I figured I'd hear from you this afternoon maybe.

 

1. All dots the same name: clumsiness born of repetitive code modifications to solve the current problem; added "+ i".

2. tweens in a TimelineLite: so that I could use remove(); trying to make sure tween was removed in case garbage collection didn't occur. Removed the TimelineLite var.

3. dumpClips(): attempt to solve overloading problem; only way I could think of to dump the clips. Removed it.

4. I need to use allFrom() because allTo() would only allow me to move all the dots to the same location. I define the ending location of each dot on the root by rotating a line mc and getting the width and height. I would prefer to use allTo(), but my trig abilites are well beyond rusty.

 

I didn't mean to imply that TweenMax was the problem. I think my code is the problem, and maybe there's more I can do to optimize.

I tried loading the dot mcs on the root and reusing them each time the tween is called but there is no performance difference.

 

The tween that I included in the code block is called from another tween. So here are both of them with updates to my previously posted code. If you have time to review and comment, I'd sure appreciate it.

 

function movedot():Void {
for(var i:Number = 0; i < 16; i++){
	dot_mc = this.attachMovie("dot", "dot" + i, getNextHighestDepth());
	dot_Array[i] = dot_mc;

	dot_Array[i]._alpha = 0;
     // _root.xcd_Array and _root.ycd_Array contain ending values for each dot_Array[i]
	dot_Array[i]._x = _root.xcd_Array[i];
	dot_Array[i]._y = _root.ycd_Array[i];
}
TweenMax.allFrom(dot_Array, 1, {_x:0, _y:0, _alpha:100, ease:Linear.easeNone, overwrite:false});
}

// on _root  
//( leader_mc is a 2px circle that moves to a random x,y and calls movedot() onComplete )

var leader_Timeline:TimelineLite = new TimelineLite;
leader_Timeline.append(new TweenLite(leader_mc, 1, 
   {_x:aimPoint_x, _y:aimPoint_y, ease:Linear.easeNone, overwrite:false}));

leader_Timeline.insert(new TweenLite(leader_mc, 1,
   {bezierThrough:[{_x:midpoint_x, _y:midpoint_y}, {_x:endPoint_x, _y:endPoint_y}],
   _alpha: 0, ease:Linear.easeOut, overwrite:false, onComplete: movedot}), .4);

leader_Timeline.insert(new TweenLite(leader_mc, .5, 
   {ease:Linear.easeNone, overwrite:false, onStart: playSound}), .2);

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