JavaScript setInterval function for a game loop

JavaScript setInterval function for a game loop

I am in the process of creating a 2D platform game for use in web browsers using vanilla JavaScript.

I have the following code using setInterval to run a 30 FPS game loop:

//game loop static run() { setInterval(function() { Game.update(); Game.render(); }, 1000/30); //calls render/update 30 times per second } 

my update method will update the game logic and render will draw to the screen.

Is this ok to call these methods 30 times a second or is there extra complexity which I have not thought about?

Submitted February 24, 2017 at 10:19PM by rk1012
via reddit