Last active
August 28, 2022 00:34
-
-
Save cenullum/8ae66127c60ac37628b8b82021114670 to your computer and use it in GitHub Desktop.
Javascript Infinite Loop with Delta Time
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 lastUpdate = Date.now(); | |
var lastFixed = Date.now(); | |
var fixedTimer=0.02; | |
var updateInterval = setInterval(tick, 0); | |
var fixedInterval = setInterval(fixedTick,fixedTimer); | |
function tick() { | |
var now = Date.now(); | |
var dt = now - lastUpdate; | |
lastUpdate = now; | |
update(dt); | |
render(dt); | |
} | |
function fixedTick(){ | |
var now = Date.now(); | |
var dt = now - lastFixed; | |
lastFixed = now; | |
fixedupdate(dt); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment