Last active
December 20, 2017 23:56
-
-
Save andrevenancio/ce8f07fe9ae8685b510ff6cdc2c22639 to your computer and use it in GitHub Desktop.
Simple example on how to drop some frame, optimising calculations, or renders every N frames on a RequestAnimationFrame update method. (ES6)
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
let lastTime = Date.now(); | |
const N = 24; | |
update() { | |
requestAnimationFrame(update); | |
// refresh only N times per second | |
if (Date.now() - lastTime < 1000 / N) { | |
return; | |
} | |
lastTime = Date.now() | |
// do some calculations | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment