Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<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
You can’t perform that action at this time.