Reputation: 83
i programmed a little browser game with javascript/html/css. To improve the performance of my game i want to check if the game is running slow on the browser of the person whos playing it and lower the preferences automatically.
Does anybody know how to check the frames per second from the current user (or the hardware data)?
Upvotes: 0
Views: 222
Reputation: 1076
you could use
window.requestAnimationFrame
requestAnimationFrame = window.requestAnimationFrame || window.mozRequestAnimationFrame ||
window.webkitRequestAnimationFrame || window.msRequestAnimationFrame;
var start = window.mozAnimationStartTime; // Only supported in FF. Other browsers can use something like Date.now().
function step(timestamp) {
var progress = timestamp - start;
d.style.left = Math.min(progress/10, 200) + "px";
if (progress < 2000) {
requestAnimationFrame(step);
}
}
requestAnimationFrame(step);
more on: https://developer.mozilla.org/en/DOM/window.requestAnimationFrame
Upvotes: 2
Reputation: 5645
If you are using just javascript, html and css (no jquery or dojo or ...), then you should measure this yourself. I assume you would have some while-loop which rerendere the whole screen or parts. Check how many times this is called, by using Date() you can then decide the time for a frame:
from=new Date();
//render one frame
to = new Date();
dt=to-from;
setFPS(1000/dt);
Upvotes: 4