Understanding the Game Loop
The terminal-based programs you wrote in Chapter 2, First Steps with Rust, operate and execute top to bottom through the main function, pausing for user input. Most games won’t stop or pause whenever the player wants to press a key. In Flappy Dragon, the player’s dragon continues to fall even if the player isn’t touching the keyboard. For games to operate smoothly, they instead run a game loop.
The game loop initializes windowing, graphics, and other resources. It then runs every time the screen is refreshed—often 30, 60, or more times per second. Each pass through the loop, it calls your game’s tick function. A closer look at the game loop and what each step does is shown.
-
Configure App, Window, and Graphics
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access