开发者

How to avoid flash.display flickering

开发者 https://www.devze.com 2023-03-04 03:23 出处:网络
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.

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.


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消