Skip to content

Instantly share code, notes, and snippets.

@cjcliffe
Created October 16, 2011 22:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cjcliffe/1291486 to your computer and use it in GitHub Desktop.
Save cjcliffe/1291486 to your computer and use it in GitHub Desktop.
Manual mainloop setInterval with locked framerate step
var interval;
// finishes when time-stepped 30fps reaches a virtual 20 seconds (600/30 = 20)
var ml = new CubicVR.MainLoop(function(timer,gl) {
// ...
if (timer.getNumUpdates()===600) {
clearInterval(interval);
finished();
}
}, true, true); // true 3rd param prevents mainloop from starting..
// step at 30fps exactly
var ml.timer.lockFramerate(30);
// run at 60fps max
interval = setInterval(1000/60,function() { ml.runOnce(); });
function finished() {
// do stuff here..
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment