Best way for simple game-loop in Javascript?

前端 未结 8 591
被撕碎了的回忆
被撕碎了的回忆 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:52

    Yep. You want setInterval:

    function myMainLoop () {
      // do stuff...
    }
    setInterval(myMainLoop, 30);
    

提交回复
热议问题