Created
March 14, 2014 13:22
-
-
Save huytd/9547553 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
<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