I would like to be able to work out the browser refresh rate at the start of the program and store it within a variable, and then continue with the rest of the program execution after the refresh rate has been computed. The refresh rate value must then be used in the lines of code which follow. I am currently using requestAnimationFrame() to work out the refresh rate (value is constantly changing):
var fps;
function step(timestamp) {
var time2 = new Date;
fps = 1000 / (time2 - time);
time = time2;
document.getElementById('test').innerHTML = fps;
window.requestAnimationFrame(step);
}
var time = new Date(), i = 0;
window.requestAnimationFrame(step);
// lines of code to be executed which are never being reached
var currentFps=fps;
However, this function keeps on running forever and does not allow the value for fps to be used in further lines of code. Also, I used cancelAnimationFrame() function to stop the running of the requestAnimationFrame(). However, the lines of code after requestAnimationFrame() are never getting executed in this way. If possible I would like the requestAnimationFrame() code to terminate so that I can then continue executing any lines of code which follow. How can this be done please?
Thank you
Aucun commentaire:
Enregistrer un commentaire