Created
March 17, 2011 12:17
-
-
Save robashton/874223 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 timeAtLastFrame = new Date().getTime(); | |
var idealTimePerFrame = 1000 / 30; | |
var leftover = 0.0; | |
var frames = 0; | |
function runApplication(){ | |
setInterval(tick, 1000/30); | |
} | |
function tick() { | |
var timeAtThisFrame = new Date().getTime(); | |
var timeSinceLastDoLogic = (timeAtThisFrame - timeAtLastFrame) + leftover; | |
var catchUpFrameCount = Math.floor(timeSinceLastDoLogic / idealTimePerFrame); | |
for(i = 0 ; i < catchUpFrameCount; i++){ | |
controller.doLogic(); | |
frames++; | |
} | |
renderer.renderScene(); | |
leftover = timeSinceLastDoLogic - (catchUpFrameCount * idealTimePerFrame); | |
timeAtLastFrame = timeAtThisFrame; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Could update
to
It's much faster