Every game you have played is the same function running over and over. It reads your input, changes the state of the world, paints the result, and immediately does it again — thousands of times until you quit. That repeating function is the game loop, and almost every rule about movement, timing and physics comes out of it.
This article builds three pieces and then connects them: the loop itself (update then draw), the state it carries from one pass to the next, and delta time — the one number that ties the loop to real seconds so a game does not run at different speeds on different machines.
A game does not run once; it runs forever
An ordinary program starts, does its work, and exits. A game starts and then waits in a loop until you close it. Each pass through the loop produces one frame — one still picture, one tick of the world. "60 FPS" means this loop completed 60 times in the last second.
Inside a single pass, three things happen in order:
- Read input. Which keys are held, where the mouse is, what arrived over the network.
- Update. Turn that input into changes: move the player, run gravity, tick timers, move enemies, resolve collisions, check win conditions.
- Draw. Take the current state of the world and paint it.
Update and draw are two different jobs
The thing being looped over is state: plain numbers sitting in memory. A player's state might be an x and y, a velocity, a health value, whether it is on the ground, and which animation frame it is on. No pixels involved — just numbers.
Update reads state, changes state. It never touches the screen.
Draw reads state, paints it. It rarely changes anything.
Keeping the two apart is what lets the same simulation work at 30 FPS on a laptop and 144 FPS on a desktop, and it is why a slow frame of drawing does not corrupt the simulation: the update still advances correctly on the next pass. Nearly every engine is built around this split — Godot spells it out as "each frame, you need to update the state of your game world before drawing it on screen" 3.
The naive loop, and the bug everyone hits
Written plainly, moving a player looks like this:
1while game is running:
2 read_input()
3 update() # player.x += 1 ... move one pixel right
4 draw()Why is this wrong? Because +1 happens once per frame, and the number of frames per second is not fixed.
| Display / frame rate | Frames per second | Distance after 1 second |
|---|---|---|
| Slow laptop | 30 | 30 px |
| Typical monitor | 60 | 60 px |
| Gaming monitor | 144 | 144 px |
Same code, same input — but the character is nearly five times faster on the gaming monitor. And frame rate is not even constant on one machine: a level load, a garbage-collection pause, or a browser throttling a background tab all stretch individual frames. A jump that clears a gap during a smooth stretch can fail in a busy moment, which feels like the game is being unfair rather than slow.
Delta time: the length of the last frame, in seconds
The fix is to stop thinking "per frame" and start thinking "per second". To do that, the loop measures how much real time the last pass took:
That value — written dt, delta, or deltaTime — is the frame duration in seconds. On a 60 FPS machine it is about s; during a hiccup it might be s. Then movement becomes:
1player.x += speed * dt # speed is in pixels per secondNow watch what each machine actually does. Suppose speed = 300.
| Frame rate | Movement this frame | Distance after 1 second | |
|---|---|---|---|
| 30 | 0.0333 s | 10 px | 300 px |
| 60 | 0.0167 s | 5 px | 300 px |
| 144 | 0.00694 s | 2.08 px | 300 px |
The per-frame step differs; the speed in the world does not. That property has a name worth knowing — frame-rate independence — and it is why a well-written game feels the same on a cheap phone and a fast PC.
Where does dt come from? In a browser, requestAnimationFrame hands your callback a timestamp, and you subtract the previous one; MDN's walkthrough of the loop uses exactly that timestamp 2. In an engine you usually do not measure anything: Unity exposes Time.deltaTime, and Godot passes delta into _process(delta), documented as "the time elapsed in seconds since the previous call" 13.
What must not be multiplied by delta time
Delta time is not a spell you sprinkle everywhere. The test is the unit of the number:
- A rate — pixels per second, degrees per second, gravity in units per second squared — must be multiplied by
dt:velocity.y += gravity * dt. - A one-time event — "set the jump velocity to −600 when the key is pressed" — must not be, or the jump gets weaker on slower frames.
- A countdown in seconds — a 3-second invulnerability, an attack cooldown, an animation timer — subtracts
dtand is compared against zero, never against a frame count.
The most common bug in AI-written game code is a timer that counts frames ("wait 6 frames, then shoot") instead of seconds. It works on the machine where it was tested and quietly changes on every other machine.
Coyote time: a rule that must be measured in seconds
Coyote time is the classic example, and it shows why delta time is a design decision, not just a physics detail. Players expect to still be able to jump for a moment after walking off a ledge — a slightly late input should still work. The usual implementation:
1# on the ground:
2coyote_timer = 0.1
3
4# every frame:
5coyote_timer -= dt
6
7# on jump press:
8if coyote_timer > 0 and not jumping:
9 jump()0.1 seconds is a tenth of a second of grace, no matter the hardware: at 30 FPS that is 3 frames, at 144 FPS about 14. Written as "6 frames of grace" instead, the window is 0.1 s at 60 FPS but only 0.04 s at 144 — the mechanic is subtly broken on good monitors, which is the opposite of what players expect. Jump buffering (pressing jump slightly before landing) works the same way.
Where plain delta time runs out
Using the measured frame time everywhere is called a variable timestep, and it has three known failure modes:
- Tunneling. A projectile at 1000 px/s with s moves 100 px in a single step. If a 10 px wall sits in between, nothing ever checked the space it jumped over, so it passes straight through.
- Instability. Simulation math that reacts to motion (springy movement, stacks of physical objects) can behave very differently — or blow up — when one step is far larger than expected 4.
- Non-reproducibility. Two machines produce different sequences of
dt, so identical inputs diverge. Replays, deterministic tests and multiplayer synchronisation all depend on identical step sizes.
Games that care about physics solve this with a fixed timestep: the simulation always advances in equal chunks, say s, and the loop accumulates real time and consumes it in whole chunks — running zero, one or several update steps in a frame, then drawing once. Engines expose both kinds of processing: Godot's _physics_process runs at a fixed 60 times per second by default, "independent of your game's actual framerate", while _process runs once per drawn frame 3; Unity's FixedUpdate uses Time.fixedDeltaTime, 0.02 s (50 times per second) by default 1.
Two things are easy to confuse here, so state them precisely: a fixed timestep means the simulation advances in equal steps; a fixed frame rate means the display refreshes at a constant rate. They are independent — the normal setup is a fixed-step simulation under a display-driven, variable frame rate.
What to check in code an AI wrote for you
When a coding tool hands you a game, these checks catch most timing bugs:
- Which function actually runs every frame? If you cannot identify it, you cannot reason about anything else.
- Is every continuous motion multiplied by delta — position, rotation, gravity, animation playback?
- Are gameplay timers in seconds and decremented by delta, rather than counting frames?
- Is physics or collision handled in a fixed step (or a capped delta), rather than whatever
dthappened to arrive?
The picture in one sentence
A game is a loop that updates state and then draws it, tens to hundreds of times per second; delta time is how the loop converts "once more" into "how much time passed", which is what lets a speed written in per-second units stay the same speed on any machine — and what lets a tenth of a second of coyote time feel the same to every player.