Search⌘ K

Game Loop

Explore how the game loop functions to keep gameplay smooth by using requestAnimationFrame in JavaScript. Learn to animate tetrominoes, manage timing for their movement, and effectively control game flow for your Tetris project.

We'll cover the following...

Most games have one main function that keeps the game running even when the user isn’t doing anything. This cycle of running the same core function over and over again is called the game loop.

In our game, we need the loop to move the tetrominoes down the screen. We drop the tetromino down one row for every time frame.

RequestAnimationFrame

To create our game loop, we use requestAnimationFrame. It tells the browser that we want to animate, and it should call a function to update an animation before the next repaint. In other ...