Skip to content

Instantly share code, notes, and snippets.

@andrevenancio
Last active December 20, 2017 23:56
Show Gist options
  • Save andrevenancio/ce8f07fe9ae8685b510ff6cdc2c22639 to your computer and use it in GitHub Desktop.
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)
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