Skip to content

Instantly share code, notes, and snippets.

@huytd
Created March 14, 2014 13:22
Show Gist options
  • Save huytd/9547553 to your computer and use it in GitHub Desktop.
Save huytd/9547553 to your computer and use it in GitHub Desktop.
<script>
var fps = 30;
var time = 0;
var deltaTime = 1;
function Start() {
looper();
}
function looper() {
setTimeout(function() {
requestAnimationFrame(looper);
// Calculate the deltaTime
var now = new Date().getTime();
deltaTime = 1 / (now - (time || now));
time = now;
// Your code here
mainLoop();
}, 1000 / fps);
}
function mainLoop()
{
console.log("deltaTime = " + deltaTime);
}
Start();
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment