当我的帧速率变慢时,我可以防止 Flash 的输入事件堆积吗?

发布于 2024-08-31 19:22:30 字数 296 浏览 3 评论 0原文

我的 Flash 游戏的目标帧率为 24 fps,但在较慢的机器上速度减慢至 10。这很好,除了 Flash 决定限制传入的 MouseEvent 和 KeyboardEvent 的队列,并且它们堆积起来并且事件落后。远远落后。太糟糕了,在 10 fps 的速度下,如果我在几秒钟内向鼠标和键盘发送垃圾邮件,则不会发生太多事情,然后,在我停止后,游戏似乎会在接下来的 5 秒内自行运行,因为事件会慢慢渗入。知道。

有谁知道解决这个问题的方法吗?我基本上需要对 Flash 说:“我知道您认为我们落后了,但是限制输入事件不会有帮助。请在收到它们后立即将它们给我。”

My Flash game targets 24 fps, but slows to 10 on slower machines. This is fine, except Flash decides to throttle the queue of incoming MouseEvent and KeyboardEvents, and they stack up and the Events fall behind. Way behind. It's so bad that, at 10 fps, if I spam the Mouse and Keyboard for a few seconds not much happens, then, after I stop, the game seems to play itself for the next 5 seconds as the Events trickle in. Spooky, I know.

Does anyone know a way around this? I basically need to say to Flash, "I know you think we're falling behind, but throttling the input events won't help. Give them to me as soon as you get them, please."

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

通知家属抬走 2024-09-07 19:22:31

您可能会更幸运地努力提高帧速率,而不是尝试解决低帧速率问题的副作用。您是否使用分析器来确定帧速率如此慢的原因?你能利用失效来改进它吗?是否存在可以优化的瓶颈?

You'll probably have better luck working to increase your framerate instead of trying to work around a side-effect of the low framerate problem. Have you used a profiler to identify why the framerate is so slow? Can you utilize invalidation to improve it? Are there bottlenecks that can be optimized?

友谊不毕业 2024-09-07 19:22:31

我不认为闪存会限制输入事件。我认为您的应用程序更有可能确实无法足够快地处理它们。我认为阻止它们以这种方式“堆积”的唯一方法就是完全丢弃事件。因此,您的代码中需要这样的内容:

function onKeyPress() {
  if(inputIsTooFarBehind()) 
    return; // skip this keypress

  // process keypress as normal
}

但有一个缺点...用户现在将放弃一些命令,只需单击越来越多的按钮来尝试让他们的命令发挥作用。

也许您应该致力于以不需要过多按键/鼠标的方式设计游戏?或者按照 Sam 的建议优化游戏本身,以防止游戏速度变慢。

I don't think flash is throttling the input events. I think it's more likely that your application truly cannot process them quickly enough. I think the only way to stop them from 'stacking up' in this way, would be to completely discard events. So you'd need something in your code like:

function onKeyPress() {
  if(inputIsTooFarBehind()) 
    return; // skip this keypress

  // process keypress as normal
}

But there's a drawback...users will now have some of their commands discarded, and will simply click more and more to try and get their commands to work.

Perhaps you should work on designing the game in such a way that doesn't need such excessive key/mouse presses? Or go with Sam's suggestion to optimize the game itself to prevent it slowing down in the first place.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文