Best way for simple game-loop in Javascript?

前端 未结 8 589
被撕碎了的回忆
被撕碎了的回忆 2020-12-14 01:51

Is there a simple way to make a game loop in JavaScript? something like...

onTimerTick() {
  // update game state
}
8条回答
  •  误落风尘
    2020-12-14 02:33

    setInterval(onTimerTick, 33); // 33 milliseconds = ~ 30 frames per sec
    
    function onTimerTick() {
        // Do stuff.
    }
    

提交回复
热议问题