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
Get Hands-on Rust now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.