Skip to content

Instantly share code, notes, and snippets.

@kane-thornwyrd
Last active December 19, 2015 15:08
Show Gist options
  • Save kane-thornwyrd/5974086 to your computer and use it in GitHub Desktop.
Save kane-thornwyrd/5974086 to your computer and use it in GitHub Desktop.
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