🎮 Game Loop

5th Grade 💻 Coding

The game loop is the loop at the heart of every video game. It runs over and over, dozens of times a second, and each time around it moves the game forward by a tiny moment.

Free · US Letter · no sign-up
Google Classroom Save to Pinterest Email me

Three things happen in each round: check the input (what did the player press?), update the world (move characters, check for collisions, update the score), and draw the screen again. Each drawing is called a frame, and many games draw 30 or 60 frames per second, fast enough that your eyes see smooth motion.

The loop keeps going until the game ends or is closed, so it’s a kind of planned “infinite” loop. In Scratch, a “forever” block with movement and checks inside is exactly a small game loop. If the work inside one round takes too long, the game stutters, which is why game programmers care so much about fast code.

For example

  • In a racing game, every frame checks whether the gas is pressed, moves the car forward a little and redraws the track.
  • In Scratch: “forever: if right arrow pressed, change x by 5; if touching enemy, say Ouch!”

📌 Remember: Game loop = input, update, draw, and again, fast.

Quick quiz

  1. What does a game loop do each round?

  2. How many frames per second do many games draw?

  3. What happens if a round of the loop is too slow?

🔎 Ask Thinkapedia another question