-
The best way? (deceleration: onEnterFrame / functions)
Hey guys, thanks for taking the time to help out.
Ok, so I'm sure all of you have seen the simple decelleration script...
code: this._height = this._height+((_root.targetH-this._height)*.2);
... if not it's pretty easy to understand. Anyway, I'm putting together a project which requires multiple MC's to share this same code but with different properties (instead of _height, it would be _y). As well, the movements have to be controlled by button onPress events.
Now, I am wondering how the best way to go about this would be.
I have tried this before by placing the above code in an onEnterFrame event of every MC that requires it, but after three or four of these bad boys get on the stage at once, performance is severy affected because of all the endless loops.
My other alternative would be to throw the code into a function. Even still performance decreases because it's still being called endlessly.
Is there an easier way to do this that doesnt affect CPU performance as much? Maybe a way to only cycle through the script until the MC has reached it's target properties?
Any help would be greatly appreciated...
Thanks!
-
hi,
yes, stopping once you've reached the target will have a big impact. Having many objects moving at the same time will always slow down the movie though - but you have to make it as efficient as possible...
Are you publishing to v5 or v6 player?
- n.
-
I'll be publishing for Flash Player 6.
-
ok, in that case, attach and remove the enterFrame event handler dynamically, eg:
code:
// start the animation
myMC.targetH = 200;
myMC.onEnterFrame = heightEaseAnimation;
function heightEaseAnimation ()
{
this._height += (this.targetH - this._height)/2;
// check if finished
if(Math.abs(this._height - this.targetH) < 1)
{
// close enough - done
this._height = this.targetH;
delete this.onEnterFrame;
}
}
Since the animation never really finishes (it just gets closer and closer to the target value), you need to check whether it's close enough for your requirements. Then just simply jump straight to the target value.
The 'delete ....' line removes the onEnterFrame handler, so no more animation code will be called for this particular movie clip.
- n.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|