我的游戏角色,为什么速度在不同的计算机上有什么不同? [英] Why speed of my game character is different in different computers?

查看:163
本文介绍了我的游戏角色,为什么速度在不同的计算机上有什么不同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发使用Java脚本的在线游戏。我使用的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.

推荐答案

相反的setInterval你应该使用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.

浏览器支持为pretty好( http://caniuse.com/#feat=requestanimationframe)总之,从Android浏览器的股票除了目前所有的浏览器。

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 做模拟这些浏览器的行为的一份体面的工作。 (不过说实话,我怀疑这将是最后一次您的后顾之忧,特别是在考虑到缺乏画布 ...)

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…)

这篇关于我的游戏角色,为什么速度在不同的计算机上有什么不同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆