stage force render / redraw

2019-03-04 04:12发布

问题:

Normally I would listen to the ENTER_FRAME event and execute code each time a frame gets rendered.. But for my application this is too slow. The time between 2 ENTER_FRAME events is 40 milliseconds. Doesn't matter if I change my framerate.

So is it possible to force flash to redraw/render the frame without listening to events? I tried the stage.invalidate() method and changing the framerate but it doesn't improve anything (stage.invalidate() doesn't do anything actually)

I did a small test to see the average time between the ENTER_FRAME and the EXIT_FRAME event:

private var beginTime:Number;
private var endTime:Number;

public function init():void {
    addEventListener(Event.ENTER_FRAME, enterFrame);
    addEventListener(Event.EXIT_FRAME, exitFrame);
}

private function enterFrame(e:Event):void {
    beginTime = new Date().getTime();

    if(endTime) {
        trace(beginTime - endTime);
    }
}

private function exitFrame(e:Event):void {
    endTime = new Date().getTime();
}

If I am right the ENTER_FRAME event is fired before the rendering of that frame and the EXIT_FRAME event is fired after the rendering. So after the EXIT_FRAME event the rendering is complete and the app will dispatch an ENTER_FRAME event. The average time between those two events is 52 milliseconds. And I want to shorten that time

Bytheway I have set my framerate to 180 for this test

回答1:

stage.Invalidate will force the stage to redraw. Its not suggested you should fix your time problem first.