3 ms·
The function `requestAnimationFrame(update)` on line 191 [1], typically updates at 60 frames per second [2]. When it fires, it re-calls the `update()` function
by bArray 7y ago
The function `requestAnimationFrame(update)` on line 191 [1], typically updates at 60 frames per second [2]. When it fires, it re-calls the `update()` function starting on line 184 [3].
As you say though, it's not 100% reliable in terms of speed, but I imagine 90%+ who play the game get a good experience.
[1] https://github.com/bradtraversy/vanillawebprojects/blob/master/breakout-game/script.js#L191 https://github.com/bradtraversy/vanillawebprojects/blob/mast...
[2] https://developer.mozilla.org/en-US/docs/Web/API/window/requestAnimationFrame https://developer.mozilla.org/en-US/docs/Web/API/window/requ...
[3] https://github.com/bradtraversy/vanillawebprojects/blob/master/breakout-game/script.js#L184 https://github.com/bradtraversy/vanillawebprojects/blob/mast...
- rypskar 7y agoTrue when using a normal monitor, but could be a problem if using a 120Hz monitor or if the previous call didn't finish fast enough. The best is to use the timestamp requestAnimationFrame sends in to the callback to find time-delta since last call >> The number of callbacks is usually 60 times per second, but will generally match the display refresh rate in most web browsers as per W3C recommendation.