Game Loop

game javascript
const targetFrameRate = 1000 / 25 // in ms let then = timestamp() function update(delta) { // your code // e.g. speed = pixelPerSecond * delta } ;(function loop(){ requestAnimationFrame(loop) let now = timestamp() let delta = now - then if (delta > targetFrameRate) { then = now - (delta % targetFrameRate) update(delta / 1000) } })()

Reference

No known

History Jun 24, 2018