4

Coming from a more 'traditional' C++ background so more used to dealing with low level API's rather than something like the flash.display API.

My issue is rather rudimentary, but my searches haven't found a solution.

How does one avoid screen tearing/flickering in the display API? Even with a high framerate like 60 fps I'm experiencing some rather nasty flickering/tearing between frames.

Take the simplistic example below, where the children of the Sprite are merely instances of Shape and never change.

private function onEnterFrame(event:Event):void
{   
    var t:Number = (getTimer() - time) / 1000;
    time = getTimer();

    step(t);
}

private function step(t:Number):void {
    var speed:Number = 100;

    for (var i:uint = 0; i < numChildren; i++){             
        getChildAt(i).x += speed * t;
        getChildAt(i).y += speed * t;
    }
}

However, since everyone else is able to do seemingly smooth fast animations I'm sort of puzzled as to how actually do it since it basically seems like a sync issue.

Casper Beyer
  • 2,203
  • 2
  • 22
  • 35

2 Answers2

1

First: you are letting your CPU work harder than necessary, 25/30 fps should do for a smooth animation, so you can call step only at this rate. Before updating location of the sprites look of x, y really change and update only if they have changed.

Make your loop as tight as you can: take numChildren (method call) out of the loop. Make speed variable an int instead of Number (faster)

Look at the sprites: do they have transparency? Transparency is a performance killer, since flash has to draw all layers on each frame. Optimize them further I you can, for example make them as small as you can without loosing quality (in case you are using bigger images that get scaled down to the sprite size).

Tomasz Stanczak
  • 12,796
  • 1
  • 30
  • 32
  • Yeah those optimizations are sort of silly, only ones that should actually matter is blending and sub pixel accuracy i'll give you those. And none really deal with the issue anyways, which is tearing. – Casper Beyer May 08 '11 at 04:18
0

I've seen wmode parameter having large influence on animation smoothness. The same swf behaves differently in standalone player and on html page with different wmodes. After some tests, I'm preferring wmode="direct" - it gives smoothest movements, even better than "gpu".

It's good to see your real fps with some monitoring tool for ActionScript, for example, Stats. If it stays high and you still see jerky movements, it is wmode issue. And 60 fps are better than 30, if you're not performance bound, why not use it.

alxx
  • 9,897
  • 4
  • 26
  • 41
  • Did benchmark using Mr.Doobs Stats before posting ofc. And the actual swf is the same as simplistic as the above posted example. The issue isn't preformance, but the fact that there's no way to sync so frames get overriden in the middle of another frame producing tearing. – Casper Beyer May 08 '11 at 04:14
  • 1
    I didn't say performance is the issue here, I just seen same swf playing smoothly or jerky, depending on wmode. And even the standalone Flash Player wasn't the best performing environment. – alxx May 08 '11 at 10:23