为什么我的游戏角色在不同的电脑上速度不同?

编程入门 行业动态 更新时间:2024-10-20 05:43:37
本文介绍了为什么我的游戏角色在不同的电脑上速度不同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用 Java Script 开发在线游戏.我正在使用 setInterval (movimage, 10) 方法来移动游戏角色.但是我看到游戏角色的移动速度是不一样的都是电脑.请给我建议.

I am developing an online game using Java Script. I am using setInterval (movimage, 10) method to move the game character. But I have seen that the movement speed of the game character is not same is all computer. Please suggest me.

推荐答案

你可能应该使用 requestAnimationFrame (developer.mozilla/en-US/docs/DOM/window.requestAnimationFrame).

Instead of setInterval you should probably use requestAnimationFrame (developer.mozilla/en-US/docs/DOM/window.requestAnimationFrame).

尝试比屏幕绘制速度更快地更新内容是没有意义的.您的目标是 60fps,即每帧约 16 毫秒.

There is no point trying to update something quicker than the screen can draw. You are aiming for 60fps, which is about 16ms per frame.

paulirish/2011/requestanimationframe-for-smart-animating/ 提供了有关如何执行此操作的更多信息.

paulirish/2011/requestanimationframe-for-smart-animating/ has some more info about how to do this.

浏览器支持非常好(caniuse/#feat=requestanimationframe)简而言之,除了 Android Stock 浏览器之外的所有当前浏览器.

Browser support is pretty good (caniuse/#feat=requestanimationframe) in short, all current browsers apart from the Android Stock browser.

如果您必须在 IE9 及更低版本中使用此功能,gist.github/paulirish/1579671 在模拟这些浏览器中的行为方面做得不错.(虽然说实话,我怀疑这将是你最后的担忧,特别是关于缺少 canvas...)

If you must have this working in IE9 and lower, gist.github/paulirish/1579671 does a decent job of simulating the behaviour in those browsers. (though to be honest, I suspect this will be the last of your worries, particularly in regard to the lack of canvas…)

更多推荐

为什么我的游戏角色在不同的电脑上速度不同?

本文发布于:2023-07-18 04:41:33,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1141115.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:角色   速度   电脑   游戏

发布评论

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

>www.elefans.com

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