AS3 - 距离下一帧/屏幕绘制还有多长时间
我有一个生成艺术应用程序,我希望它在每帧中绘制尽可能多的周期而不降低帧速率。有没有办法知道屏幕更新/刷新还剩多少时间?
我想如果我可以估计每个周期需要多少毫秒,那么我可以运行周期直到剩余时间少于平均或峰值周期时间,然后让屏幕刷新,然后运行另一组周期。
I have a generative art app, and I'd like it to draw as many cycles as possible each frame without reducing the framerate. Is there a way to tell how much time is left until the screen updates/refreshes?
I figure if I can approximate how many milliseconds each cycle takes, then I can run cycles until the amount of time left is less than the average or the peak cycle time, then let the screen refresh, then run another set of cycles.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您希望您的应用程序以每秒 N 帧的速度运行,那么您可以循环绘制 1/N 秒*,其中 N 通常是阶段帧速率(您可以获取和设置):
...构造函数:
...
如果代码导致帧速率慢于所需的帧速率,您可以尝试一些简单的方法,例如仅花费一帧分配时间的一半,将另一半留给 Flash 渲染:
周围还有 FPS 监视器,您可以使用它们来监视绘图时的帧速率。谷歌 as3 帧率监视器。
If you want your app to run at N frames per second, then you can draw in a loop for 1/N seconds*, where N is typically the stage framerate (which you can get and set):
... Somewhere in your main constructor:
...
If the code results in slower-than-desired framerates, you could try something as simple as only taking half the allotted time for a frame, leaving the other half for Flash to render:
There are also FPS monitors around that you could use to monitor your framerate while drawing. Google as3 framerate monitor.
将此代码放入主对象并检查 - 它将跟踪每个帧开始之间的时间。
Put this code to main object and check - it will trace time between each frame start .