I’m using requestAnimationFrame to draw players in my game. One of the players is moving faster than everybody else. I did some checking with him and he told me that his monitor has a 120hz refresh rate. I’m assuming this means has can process frames faster than others resulting in faster movement speed. Any ideas as to how I can get around this?
Thanks
The shim layer used is below:
JavaScript
x
12
12
1
// shim layer with setTimeout fallback
2
window.requestAnimFrame = (function(){
3
return window.requestAnimationFrame ||
4
window.webkitRequestAnimationFrame ||
5
window.mozRequestAnimationFrame ||
6
window.oRequestAnimationFrame ||
7
window.msRequestAnimationFrame ||
8
function(/* function */ callback, /* DOMElement */ element){
9
window.setTimeout(callback, 1000 / 60);
10
};
11
})();
12
Advertisement
Answer
There is no guaranteed framerate. However, you can force an approximate framerate using a simple timer: How to solve different FPS in requestAnimationFrame on different browsers?