Created
April 7, 2015 08:37
-
-
Save gre/7fa26874759cab0c23c1 to your computer and use it in GitHub Desktop.
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
var raf = require("raf"); | |
raf(function loop (t) { | |
raf(loop); | |
if (isVisibleInWindow(canvas)) return; | |
// ... do your consuming stuff | |
}); |
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
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