Why speed of my game character is different in different computers?(为什么我的游戏角色在不同的电脑上速度不同?)
问题描述
我正在使用 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 (https://developer.mozilla.org/en-US/docs/DOM/window.requestAnimationFrame).
Instead of setInterval you should probably use requestAnimationFrame (https://developer.mozilla.org/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.
http://paulirish.com/2011/requestanimationframe-for-smart-animating/ 提供了有关如何执行此操作的更多信息.
http://paulirish.com/2011/requestanimationframe-for-smart-animating/ has some more info about how to do this.
浏览器支持非常好(http://caniuse.com/#feat=requestanimationframe)简而言之,除了 Android Stock 浏览器之外的所有当前浏览器.
Browser support is pretty good (http://caniuse.com/#feat=requestanimationframe) in short, all current browsers apart from the Android Stock browser.
如果您必须在 IE9 及更低版本中使用此功能,https://gist.github.com/paulirish/1579671 在模拟这些浏览器中的行为方面做得不错.(虽然说实话,我怀疑这将是你最后的担忧,特别是关于缺少 canvas...)
If you must have this working in IE9 and lower, https://gist.github.com/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…)
这篇关于为什么我的游戏角色在不同的电脑上速度不同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:为什么我的游戏角色在不同的电脑上速度不同?
基础教程推荐
- Bootstrap 模态出现在背景下 2022-01-01
- 在 contenteditable 中精确拖放 2022-01-01
- fetch 是否支持原生多文件上传? 2022-01-01
- 检查 HTML5 拖放文件类型 2022-01-01
- Bokeh Div文本对齐 2022-01-01
- npm start 错误与 create-react-app 2022-01-01
- 原生拖动事件后如何获取 mouseup 事件? 2022-01-01
- 即使用户允许,Gmail 也会隐藏外部电子邮件图片 2022-01-01
- Fabric JS绘制具有活动形状的多边形 2022-01-01
- 如何添加到目前为止的天数? 2022-01-01
