在 Flex 中实现计时器循环是一个坏主意吗?

编程入门 行业动态 更新时间:2024-10-14 04:30:54
本文介绍了在 Flex 中实现计时器循环是一个坏主意吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

在我们的游戏项目中,我们确实将计时器循环设置为每秒触发约 20 次(与应用程序帧速率相同).我们用它来移动一些精灵.我想知道这是否会导致问题,我们应该使用 EnterFrame 事件处理程序进行更新吗?我的印象是,让计时器循环运行得比应用程序帧速率快可能会导致问题......是这种情况吗?

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 上执行此操作会导致非常奇怪的问题.它不是每 75 毫秒一帧,而是突然跳到 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.

在最深层次上,Flash 在其中运行的任何主机应用程序(通常是浏览器)都会以某个时间间隔轮询 Flash.该间隔在一个浏览器中可能是每 10 毫秒,在另一个浏览器中可能是 50 毫秒.每次轮询发生时,Flash 都会执行以下操作:

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/framerate) 毫秒吗?如果没有:什么都不做并返回如果是:执行帧更新:将所有(播放)时间线推进一帧调度所有事件(包括 ENTER_FRAME 事件使用挂起事件执行所有帧脚本和事件处理程序绘图屏幕更新返回

但是,某些类型的外部事件(例如按键、鼠标事件和计时器事件)与上述过程异步处理.因此,如果您有一个在按下某个键时触发的事件处理程序,则该处理程序中的代码可能会在帧更新之间执行多次.除非您使用 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屋!

更多推荐

[db:关键词]

本文发布于:2023-04-19 19:37:37,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/968437.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:是一个   坏主意   计时器   Flex

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!