Learn › Make games

Lesson 1 of 6 · About 5 min

The game loop

Every game, this one too, repeats three steps many times a second.

Feather Jump: the fox kit next to a foe, with platforms and coins above.

Every game repeats three steps many times a second. Once you see them, you know where any change belongs.

Read, update, draw

A game is a program that never stops asking the same three questions. What is the player pressing? What happens next in the world? What should be on the screen now?

It asks them about sixty times a second. Each pass is called a frame, and the three steps together are called the game loop.

Read the buttons. Update the world: move the hero, move the enemies, check what touched what, count the score. Draw everything where it now is. Then do it all again.

State is what the loop remembers

Between one frame and the next, the game keeps a small set of facts: where the hero is, how fast it is moving, how many lives are left, which level this is. These facts are called state.

The update step is the only place state changes. The draw step only looks at it. That split is worth keeping in mind: when something looks wrong, the question is whether the fact is wrong (update) or only the picture of it (draw).

Most games also keep one fact about the whole game: is this the title screen, is the game being played, or is it over? The loop runs the whole time and does different work in each of them.

Most of a game is numbers you can name

A well made game does not scatter its numbers through the code. It names them once, near the top: how many lives you start with, how fast the hero runs, how hard gravity pulls.

That is where you will make most of your changes, and it is why you can ask for them in plain words. "Start with 5 lives" is one named number.

In the session below you get your own copy of a small platformer called Feather Jump. You will ask the AI for one change, watch it find the number, and check that the game now holds it.

The Shiny Gen editor with the Feather Jump platformer running and the AI chat open beside it.
Change your first number

Try it yourself

In the app this lesson opens a real game for you, with a guide that walks you through these steps:

  1. This is a real editor session on your own copy of Feather Jump. The game is running next to the chat. The chat with the AI is where you ask for changes.
  2. Right now the game loop is running the title screen: it reads no buttons, updates a demo hero, and draws it. Next you will change a number the update step uses.
  3. Start the hero with 5 lives instead of 3.
  4. The change is in. One request, one named number, and the game rebuilt itself. That is the whole loop of making a game here: ask, change, play.
Start makingDownload on the App StoreGet it on Google Play