Last active
December 19, 2015 15:08
-
-
Save kane-thornwyrd/5974086 to your computer and use it in GitHub Desktop.
Some JS/Coffee Game dev gizmo out of http://nokarma.org/2011/02/02/javascript-game-development-the-game-loop/index.html
This file contains hidden or 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
class Game | |
constructor: ()-> | |
draw: ()-> | |
update: ()-> | |
run: (()=> | |
skipTicks = 1000/@fps | |
maxFrameSkip = 10 | |
nextGameTick = (new Date).getTime() | |
()=> | |
loops = 0 | |
while (new Date).getTime() > nextGameTick && loops < maxFrameSkip | |
@update() | |
nextGameTick += skipTicks | |
loops++ | |
@draw() | |
)() | |
Game._intervalId = setInterval Game.run, 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment