Skip to content

Instantly share code, notes, and snippets.

@gre
Created April 7, 2015 08:37
Show Gist options
  • Save gre/7fa26874759cab0c23c1 to your computer and use it in GitHub Desktop.
Save gre/7fa26874759cab0c23c1 to your computer and use it in GitHub Desktop.
var raf = require("raf");
raf(function loop (t) {
raf(loop);
if (isVisibleInWindow(canvas)) return;
// ... do your consuming stuff
});
var raf = require("raf");
var lastFrame;
raf(function loop (t) {
raf(loop);
if (isVisibleInWindow(canvas)) {
lastFrame = t;
return;
}
if (!lastFrame) lastFrame = t;
var dt = t - lastFrame;
lastFrame = t;
// ... do your consuming stuff
// dt is the delta time with the last frame
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment