Jump to content
Search Community

simple animation very jerky

omnider test
Moderator Tag

Recommended Posts

Hi,

I'm building a data flow simulation animation and from the very beginning I'm having problems with performance. If you have a look at http://strikermultimedia.com/dev/jerkyAnimation/binary.swf you can see that the animation is fairly fluid but every now and then in gets really choppy/jerky for for me no obvious reason. This is the code that is creating the animation:

 

import com.greensock.*;
import com.greensock.easing.*;
import com.greensock.events.TweenEvent;

Reproductions();

function Reproductions(){
Reproduction();
Reproduction2();
TweenMax.delayedCall(.1,Reproductions);
}

function Reproduction(){

var Logic:Number = Math.random();
var State:MovieClip;

if(Logic > 0.5){
	State = new nula();
}else{
	State = new jedna();
}

State.x = 500;
State.y = 500;
State.scaleX = 0.2;
State.scaleY = 0.2;

this.addChild(State);

TweenMax.to(State, 5, {bezierThrough:[{x:975, y:55}, {x:1700, y:120}], scaleX:1, scaleY:1, orientToBezier:false, ease:Quart.easeIn, onCompleteListener:DeleteItem} );
}

function Reproduction2(){

var Logic:Number = Math.random();
var State:MovieClip;

if(Logic > 0.5){
	State = new nulaA();
}else{
	State = new jednaA();
}

State.x = 500;
State.y = 500;
State.scaleX = 0.2;
State.scaleY = 0.2;

this.addChild(State);

TweenMax.to(State, 5, {bezierThrough:[{x:955, y:30}, {x:1720, y:100}], delay:0.2, scaleX:1, scaleY:1, orientToBezier:false, ease:Quart.easeIn, onCompleteListener:DeleteItem} );
}

function DeleteItem(evt:TweenEvent)
{
removeChild(evt.currentTarget.target);
}

 

and just in case this is the .fla file http://strikermultimedia.com/dev/jerkyAnimation/binary.fla .

 

I've read somewhere that bitmapdata are easier to render than vectors but in my case changing vectors into bitmapdata didn't help. Can you please tell me if you see any obvious mistakes? what might be causing the occasional jerkiness of the animation? Any suggestions are much appreciated,

 

Thanks

Link to comment
Share on other sites

Very cool animation you have there. I see the jerkiness.

 

There may be a few factors that combined may be contributing to it

 

1: large stage and great amount of travel distance means a much bigger re-draw area

2: 60fps may be too demanding on some systems

3: use of glow filter

4: constant and quickly paced creation of tweens / function calls via delayedCall(.1, reproductions)

 

------

 

the unfortunate news is that I played around with your file quite a bit and messed with some of the factors above.

 

I also attempted to do some object pooling (instead of destroying and creating objects over and over again you just re-use the same objects). For instance I used a loop to create 50 tweens (with offset delays) that would repeat constantly. This didn't show any noticeable performance gain and I had an issue with some objects overlapping. it was a quick test.

 

I removed the bezier plugin (just did a straight tween) and also enabled FastEase for a quad ease.

 

Nothing really made the occasional slow-down go away. It seems there are times where it can run buttery smooth for a few seconds and then it "gets a little tired".

 

I can tell you from many years of experience with Flash that sometimes you just have to "deal with" the performance limitations of the player. Flash can run very differently based on environment: stand alone player vs flash ide test vs every browser plugin version.

 

I'm doing some TweenMax stuff right now with a hundred clips scaling and fading while mask-revealing an image and it runs great. I know people have tweened thousands of things simultaneously with no problem.

 

Also, I'm not an expert on Flash Player performance optimization, or code optimization for that matter.

 

Perhaps someone else around here can see something that may be causing the player to bog down over time.

 

Carl

Link to comment
Share on other sites

Yep, the occasional stagger is most likely caused by the garbage collection routine running in the Flash Player, cleaning up all the excess instances that built up. Unfortunately there isn't a way to predict exactly when it will happen or to force it to happen at certain times (you can in the debug version of the player, but who cares). Carl's idea of recycling things would very likely reduce the frequency of the gc kick-in, but it won't eliminate it altogether because the Flash Player generates Event instances anyway on every frame that need to get gc'd. In your case, 60 times per second it's spitting out another ENTER_FRAME event instance. So there is indeed a certain amount of occasional lag that we just have to put up with.

 

To make your stuff run the fastest, it probably would indeed be best to draw() or copyPixels() your stuff to a BitmapData but that is kinda painful and cumbersome.

 

Hope that helps clear up some of the mystery at least.

Link to comment
Share on other sites

Thanks for your swift replies again guys.

 

some of the stuff you say I already knew, something I was suspecting and something is completely new to me. The thing is that I was playing with the animation so long that after a while even when I created one tween with a rectangle going from one side of the stage to another I saw the same thing that was happening with ones and zeros. Basically I cannot create an animation that wouldn't do that anymore :D So I guess it really must be something that FP does. Garbage collection sounds like a viable candidate. I'm really curious what the new FP will bring in this area.

 

Anyway, thanks again very much guys for all your suggestions. Thanks Carl for spending so much time playing with it, I really thought I was going crazy :)

Link to comment
Share on other sites

no problem. from what I have heard, future versions of the Flash Player will give the developer much better control of when garbage collection can and can not happen. It will be a welcome addition for many of us!

 

I really did enjoy your animation, its a very cool effect with little coding effort and something I don't see all that often.

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