If I have a loop using requestAnimationFrame like this:
function render() {
// Rendering code
requestAnimationFrame(render);
}
Will there be any difference if I put the requestAnimationFrame
in the beginning of the function, like this:
function render() {
requestAnimationFrame(render);
// Rendering code
}
I haven't noticed any difference, but I have seen both implementations, is one of them better in any way, or are they the same?
Edit: One thing I have thought about is, if I put it in the beginning, and the render code takes quite long time to run, say 10ms, wouldn't putting it in the end make the frame rate drop with 10ms?
rAF
early, but the key to success is ensuring that your code routinely executes within the 1/60th second allowed. Then the positioning ofrAF
is irrelevant. – Leyva