如何Flash Player的执行计时器? [英] How does Flash Player execute Timer?

查看:284
本文介绍了如何Flash Player的执行计时器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道的运行code执行基本面的在Flash Player和AIR调试器。但我想知道定时器code的执行是怎么做的。 难道更好地使用定时器,而不是enterFrame事件类似的行动?哪一个是更好地最大化优化?

I know about runtime code execution fundamentals in Flash Player and Air Debugger. But I want to know how Timer code execution is done. Would it be better to use Timer rather than enterFrame event for similar actions? Which one is better to maximize optimization?

推荐答案

这取决于你想用它来做什么。大多数人会激烈地说,使用 Event.ENTER_FRAME 。在大多数情况下,这是你想要的。每帧开始建设它只会被调用。如果你的应用程序是在24fps的(默认)运行,即code将运行一次41.7ms,假设没有丢帧。对于几乎所有的图形用户界面相关的情况下,你不想往往比这个运行code,因为它是完全没有必要(你可以更经常地运行它,当然,但它不会做任何好处,因为屏幕只有更新的常)。

It depends on what you want to use it for. Most will vehemently say to use Event.ENTER_FRAME. In most instances, this is what you want. It will only be called once every frame begins construction. If your app is running at 24fps (the default), that code will run once every 41.7ms, assuming no dropped frames. For almost all GUI related cases, you do not want to run that code more often than this because it is entirely unnecessary (you can run it more often, sure, but it won't do any good since the screen is only updated that often).

有,当你需要code然而,更经常地运行,时间大多在非GUI有关的案件。这可以从一个系统检查需要发生在后台的东西,需要绝对precise,如一个对象,需要显示/更新的确切时间间隔(Timer是精确到毫秒,我相信,而ENTER_FRAME是只精确到了1000 /帧率毫秒)。

There are times when you need code to run more often, however, mostly in non-GUI related cases. This can range from a systems check that needs to happen in the background to something that needs to be absolutely precise, such as an object that needs to be displayed/updated on an exact interval (Timer is accurate to the ms, I believe, whereas ENTER_FRAME is only accurate to the 1000/framerate ms).

在最后,它并没有太大的意义,使用定时器对小于ENTER_FRAME将被调用。任何比这更多,你的风险丢帧。 ENTER_FRAME非常适合与几乎所有的图形,不是做其他的东西出现/更新以precise时间。即使如此,你应该使用ENTER_FRAME,以及因为它只会在下一帧反正呈现。

In the end, it doesn't make much sense to use Timer for anything less than ENTER_FRAME would be called. Any more than that and you risk dropping frames. ENTER_FRAME is ideal for nearly everything graphics related, other than making something appear/update at a precise time. And even then, you should use ENTER_FRAME as well since it would only be rendered in the next frame anyway.

您需要评估在逐案基础上每一种情况,并确定哪些是最适合特定情况,因为对所有的情况下没有最佳答案。

You need to evaluate each situation on a case-by-case basis and determine which is best for that particular situation because there is no best answer for all cases.

修改

我扔一起快速测试应用程序时看到计时器火灾。帧率为24fps的(42ms),我设置定时运行每隔10ms。这里是一个选择的时候,它跑了。

I threw together a quick test app to see when Timer fires. Framerate is 24fps (42ms) and I set the timer to run every 10ms. Here is a selection of times it ran at.

2121
2137
2154
2171
2188
2203
2221
2237

正如你可以看到,它正在运行的每15-18ms,而不是我想它的10毫秒。我还测试了20毫秒,100毫秒,200毫秒和1000毫秒。最终,每一个发射在约时它应该具有为10ms。因此,这是几乎没有precise因为我原本以为是。

As you can see, it is running every 15-18ms instead of the 10ms I wanted it to. I also tested 20ms, 100ms, 200ms, and 1000ms. In the end, each one fired within about 10ms of when it should have. So this is not nearly as precise as I had originally thought it was.

这篇关于如何Flash Player的执行计时器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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