它是实现在Flex的定时器循环一个坏主意? [英] Is it a bad idea to implement a timer loop in Flex?

查看:168
本文介绍了它是实现在Flex的定时器循环一个坏主意?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我们的游戏项目中,我们确实有一个计时器循环集火约20次(在相同的应用程序帧率)。我们用这个来移动一些精灵。 我不知道这可能会导致问题,我们应该使用enterFrame事件处理程序,而不是做我们的更新? 我得到的IM pression,有一个定时循环运行比应用程序更快的帧速率可能导致问题......是这样吗?

In our game project we did have a timer loop set to fire about 20 times a second (the same as the application framerate). We use this to move some sprites around. I'm wondering if this could cause problems and we should instead do our updates using an EnterFrame event handler? I get the impression that having a timer loop run faster than the application framerate is likely to cause problems... is this the case?

作为更新,试图做到这一点的EnterFrame造成非常怪异的问题。取而代之的是帧的每个75ms,突然跃升至25毫秒。请注意,它不只是我们的计算的要求的帧率是不同的,突然动画加速到疯狂的速度。

As an update, trying to do it on EnterFrame caused very weird problems. Instead of a frame every 75ms, suddenly it jumped to 25ms. Note, it wasn't just our calculation claimed the framerate was different, suddenly the animations sped up to a crazy rate.

推荐答案

下面是Flash如何处理帧率一个破败的,为什么你看到你的内容打得更快。

Here's a rundown of how Flash handles framerates and why you saw your content play faster.

在最深层次,无论主机的应用程序,闪光灯在(浏览器通常)投票在某个时​​间间隔闪烁运行。该时间间隔可能是每10ms在一个浏览器,或50ms的另一种。该民意调查发生每次时,闪光灯确实是这样的:

At the deepest level, whatever host application that Flash is running in (the browser usually) polls flash at some interval. That interval might be every 10ms in one browser, or 50ms in another. Every time time that poll occurs, Flash does something like this:

  • 有无(1000 /帧率)毫秒为单位自上一帧更新通过呢?
    • 如果没有:什么都不做,返回
    • 如果是:执行帧更新:
      • 高级所有(打)时间线一帧
      • 在调度所有事件(包括 ENTER_FRAME 事件
      • 执行所有帧脚本和事件处理程序与挂起的事件
      • 在画屏幕更新
      • 返回
      • Have (1000/framerate) miliseconds passed since the last frame update?
        • If no: do nothing and return
        • If yes: Execute a frame update:
          • Advance all (playing) timelines one frame
          • Dispatch all events (including an ENTER_FRAME event
          • Execute all frame scripts and event handlers with pending events
          • Draw screen updates
          • return

          然而,某些种的外部事件的(如键presses,鼠标事件和计时器事件)被异步处理,以上述方法。所以,如果你有一个事件处理程序,当关键是pressed火灾时,code在处理程序可能被帧更新之间执行多次。屏幕仍然只能每帧一次更新重绘,除非使用了的updateAfterEvent()方法(全球在AS2,附着事件AS3)。

          However, certain kinds of external events (such as keypresses, mouse events, and timer events) are handled asynchronously to the above process. So if you have an event handler that fires when a key is pressed, the code in that handler might be executed several times between frame updates. The screen will still only be redrawn once per frame update, unless you use the updateAfterEvent() method (global in AS2, attached to events in AS3).

          请注意,这些事件的异步行为不会影响帧的更新定时。即使您使用计时器事件,例如,重绘屏幕每秒50次,帧动画仍然会出现在公布的帧率,而且如果他们在enterFrame事件(而不是被动的脚本动画不会执行得更快定时器)。

          Note that the asynchronous behavior of these events does not affect the timing of frame updates. Even if you use timer events to, for example, redraw the screen 50 times per second, frame animations will still occur at the published framerate, and scripted animations will not execute any faster if they're driven by the enterFrame event (rather than the timer).

          这篇关于它是实现在Flex的定时器循环一个坏主意?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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