This probably will not change the situation. The requestAnimationFrame method is asynchronous, so anyway, your rendering function will work as expected. But ... there is a trick when it comes to stopping. Say you have the following code:
function render() { requestAnimationFrame(render); // Rendering code }
To stop the next rendering, you need to call the cancelAnimationFrame method, for example:
function render() { requestAnimationFrame(render); // Rendering code if (noLongerInterested) { cancelAnimationFrame(); } }
Otherwise, the render method will run indefinitely. Alternatively, you can:
function render() { // Rendering code if (stillInterested) { requestAnimationFrame(render); } }
As for dropping frames, you can look at requestAnimationFrame as a fixed schedule (at 60 frames per second, this will be about 16 ms intervals). If your code takes longer, the browser will begin to drop frames. See Patrick Roberts answer for instructions on how to take responsibility for your frames and use them for more consistent rendering.
I hope this helps!
marcelino
source share