Last active
August 29, 2015 14:22
-
-
Save jeromeetienne/3ed0ecb1360ca5e3bd5d to your computer and use it in GitHub Desktop.
Rendering Loop ala vendor.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// array of functions for the rendering loop | |
var onRenderFcts = []; | |
// Here you add your functions to the rendering loop. | |
// They will be executed in-order once per requestAnimationFrame() | |
onRenderFcts.push(function(now, delta){ | |
// now is the absolute time in millisecond | |
// delta is the delay between now and the last iteration | |
// put your code here. | |
}) | |
// ----------------------------------------------- | |
// ... you may put more functions here | |
// ----------------------------------------------- | |
// run the rendering loop | |
var previousTime = performance.now() | |
requestAnimationFrame(function animate(now){ | |
requestAnimationFrame( animate ); | |
onRenderFcts.forEach(function(onRenderFct){ | |
onRenderFct(now, now - previousTime) | |
}) | |
previousTime = now | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Should it be
previousTime = now
on the last line?