Workshop › Tetris-style Blocks › Step 16 of 32
A game loop redraws about 60 times a second. The browser passes the time in milliseconds; every 800 ms the piece moves one row down.
```js
let lastDrop = 0
function loop(time) {
if (time - lastDrop >= 800) {
lastDrop = time
tryMove(0, 1)
}
draw()
requestAnimationFrame(loop)
}
requestAnimationFrame(loop)
```requestAnimationFrame(loop) asks the browser to run loop before the next screen refresh; loop asks again at its
end, so it keeps running.time is the time since the page opened, in milliseconds; lastDrop remembers when the piece last fell.draw() runs every frame.let piece write let lastDrop = 0.draw() line in the key listener.draw() call at the very bottom with loop and requestAnimationFrame(loop).Skills: The game loop
← Wall kicks A random piece at the top →