Learn by Building Workshop Skills GitHub Türkçe Workshop › Asteroids › Step 7 of 41
The game loop What we are doing A game runs in a loop: update, draw, again, about 60 times a second. requestAnimationFrame(loop) asks the browser to
run loop before the next screen refresh, and loop asks again each time.
```js
function loop() {
update()
draw()
requestAnimationFrame(loop)
}
resetShip()
requestAnimationFrame(loop)
```What it means
loop does one frame: move, then draw, then book the next frame.
At the bottom, requestAnimationFrame(loop) replaces the single draw() call and starts the loop.
Your turn
Under draw, after an empty line, write loop.
At the bottom, replace draw() with requestAnimationFrame(loop).
Skills: The game loop
← Turning Thrust and drift →
All steps Black space Where the ship is Which way it points A triangle ship Which keys are down? Turning The game loop Thrust and drift A little friction A speed limit Around the screen Making a bullet Fire! Bullets fly A lifetime for bullets Making a rock Four big rocks Drawing the rocks Jagged rocks Drifting rocks When do two circles touch? Breaking a rock Bullets hit rocks Points Show the score Losing a life A rock hits the ship Show the lives What time is it? A moment of safety Blink while safe Waves of rocks The next wave Faster every wave One function to start Playing or over Game over Best score GAME OVER Play again Build it yourself: hyperspace