如何用 JavaScript 制作稳定的自动机?

发布于 2024-08-30 12:36:20 字数 176 浏览 4 评论 0原文

我正在开发一个 javascript 游戏,我有一个自动机系统来控制游戏时间和精灵动画,并为寻路系统提供计时等帮助。我的问题是在慢速浏览器上,我用来计算时间的 javascript 循环不是很准确。它往往会跳来跳去。我有办法强制循环以 30 fps 持续运行吗?

基本上我需要一种方法来保持自动机循环以 1/30 秒运行。

I'm working on a javascript game and I've got an automata system controlling game time and sprite animation as well as giving a hand to the path finding system for timing and such. My problem is on slow browsers the javascript loop I'm using for counting the time is not very accurate. It tends to jump around a lot. I there a way to force the loop to run consistently at 30 fps?

Basically I need a way of keeping my automata loop running at 1/30th of a second.

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

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

发布评论

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

评论(2

薄荷梦 2024-09-06 12:36:20

您无法控制时间(请阅读此处了解更多信息),但如果没有更多信息,恐怕我无法为您提供更多帮助。

There's no way for you to control the timing (have a read up here for more info), but without some more info I'm afraid I can't help you more.

因为看清所以看轻 2024-09-06 12:36:20

似乎使用设置间隔而不是带有 setTimeout 的自调用函数可以加快速度。谢谢博宾斯

It seems useing set interval instead of a self invoking function with setTimeout sped thing up quite a bit. thanks bobince

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