What is a game loop?
Every real-time game runs one repeating cycle: read input, update the world, draw it. Here is what that cycle looks like and why it decides how your game feels.

Key takeaways
- The game loop repeats three steps every frame: read input, update the game state, render the result.
- In a browser it is driven by requestAnimationFrame, which fires once per screen refresh (usually 60 or 120 times a second).
- It is a code concept. The "core loop" of game design (play, reward, upgrade) is a different idea with a similar name.
The game loop is the piece of code that runs over and over while a game is open, each pass reading the player's input, moving everything in the world forward a little, and drawing one new frame. Run it 60 times a second and still pictures become motion, the same way a flip book does.
Think of a referee in a board game who, every few seconds, asks each player what they want to do, applies the rules, then redraws the board. A video game does exactly that, just fast enough that you never see the pauses.
The three steps, every frame
- 01Input. Which keys are held, where the finger is, whether the jump button was pressed since the last frame.
- 02Update. Apply movement, gravity, timers, enemy decisions and collisions. This is where the rules of the game live.
- 03Render. Draw the world as it now stands: background, sprites, effects, then the score and buttons on top.
In a browser game the loop is usually started with requestAnimationFrame, a browser function that calls your code right before the screen refreshes. On a 60 Hz phone that gives you about 16.7 milliseconds for all three steps; on a 120 Hz screen, about 8.3. Go over budget and the frame is late, which players feel as stutter.
A stripped-down shape of the code looks like this: `function frame(now) { const dt = (now - last) / 1000; last = now; readInput(); update(dt); render(); requestAnimationFrame(frame); }`. The dt value is delta time, the seconds since the previous frame, which keeps speed the same on fast and slow screens.
Fixed steps versus variable steps
The simplest loop runs update once per frame with whatever dt it got. That works for most casual games. Physics-heavy games often use a fixed timestep instead: the update always advances the world by the same slice, say 1/60 of a second, running twice on a slow frame or zero times on a fast one, while rendering happens once per frame. Fixed steps make jumps the same height on every device and keep physics stable. A good starting rule: variable steps for puzzle and card games, fixed steps for platformers, pinball and anything with a physics engine.
Why it matters when you build with Startbase
You do not write the loop by hand: Startbase games run on PixiJS for 2D and Three.js for 3D, and the agent sets up the loop when it creates the game (games template docs). Knowing the word still helps you describe problems precisely. "The player moves faster on my laptop than on my phone" is a loop problem (speed not scaled by dt). "The game hitches every few seconds" is usually too much work inside one update. The Engine panel's Perf view shows how long frames take, so you can see the budget being blown instead of guessing.
The game feels different on my phone and my laptop. Make all movement and timers use delta time, run physics on a fixed 60 Hz step, and cap dt at 0.1 seconds so returning from a background tab does not teleport the player.
Common confusions
- Game loop vs core loop. The core game loop is a design term for what the player repeats (fight, loot, upgrade). The game loop here is the code that ticks every frame.
- Loop speed vs game speed. A faster loop should mean smoother motion, not a faster game. If the game speeds up on a 120 Hz screen, movement is counted per frame instead of per second.
- Paused tabs. Browsers stop calling requestAnimationFrame in background tabs. When the player comes back, the first dt can be many seconds long, which is why loops clamp it.
To see the loop in a full game, read how to make a platformer, and for keeping it under budget on phones, game performance on phones.
Frequently asked questions
How many times per second does a game loop run?
In a browser, usually once per screen refresh: 60 times a second on most screens and 120 on high-refresh phones and monitors. Some games run their update at a fixed rate separate from drawing.
Do turn-based games have a game loop?
Usually yes, because animations, hover effects and timers still need frames. The rules may only change when a player acts, but the drawing keeps looping.
Is setInterval fine for a game loop?
It works but is a poor fit: it is not synced to the screen refresh, so frames tear or double up. requestAnimationFrame is the standard choice in browsers.

