舞台强制渲染/重绘 [英] stage force render / redraw

查看:36
本文介绍了舞台强制渲染/重绘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通常我会在每次渲染帧时监听 ENTER_FRAME 事件并执行代码.. 但是对于我的应用程序来说这太慢了.2 个 ENTER_FRAME 事件之间的时间为 40 毫秒.如果我改变我的帧率没关系.

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.

那么是否可以在不监听事件的情况下强制 flash 重绘/渲染帧?我尝试了 stage.invalidate() 方法并更改了帧速率,但它没有改善任何东西(stage.invalidate() 实际上没有做任何事情)

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)

我做了一个小测试,看看 ENTER_FRAME 和 EXIT_FRAME 事件之间的平均时间:

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();
}

如果我是对的,则在渲染该帧之前触发 ENTER_FRAME 事件,并在渲染之后触发 EXIT_FRAME 事件.因此,在 EXIT_FRAME 事件之后,渲染完成,应用程序将调度 ENTER_FRAME 事件.这两个事件之间的平均时间为 52 毫秒.我想缩短那个时间

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

顺便说一下,我已将本次测试的帧率设置为 180

Bytheway I have set my framerate to 180 for this test

推荐答案

stage.Invalidate 将强制舞台重绘.不建议您先解决时间问题.

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

这篇关于舞台强制渲染/重绘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆