What is a game loop?
A game loop keeps simulating and drawing every frame even when the player is idle; fixed timesteps keep physics stable.
Published here , updated · 4 sources · Resume reading
A game loop is the central cycle that keeps a game running whether or not the player presses a key [1]. Most office apps idle without input; games keep simulating and drawing [1]. Timestep care: Glenn Fiedler's Fix Your Timestep article [2]. Related visuals: how Blender Cycles renders.
Quick start (under a minute)
Read the loop as three verbs in order: input, update, draw. If you remove input, update still runs in most action games. If you remove update, the screen freezes even when menus animate on decorative loops.
Sketch the loop Wikipedia uses
Wikipedia's simplified pseudocode [1]:
while (user does not exit)
check for user input
run AI
move enemies
resolve collisions
draw graphics
play sounds
end whileEngines add fixed-timestep physics, job threads, and asset streaming, but the spine matches: poll input, advance state, present frames [1].
Picture simulation vs render rates
Fiedler recommends accumulating frame time, stepping physics with a constant dt, optionally interpolating for render [2].
See variable dt vs fixed dt on this host
Toy integrator: position += velocity * dt each frame. One 100 ms hitch inserted mid run.
DT = 1/60
pos_v, vel = 0.0, 1.0
for frame_ms in [16.7, 16.7, 100.0, 16.7]:
pos_v += vel * (frame_ms/1000)
acc = 0.0
pos_f, vel_f = 0.0, 1.0
for frame_ms in [16.7, 16.7, 100.0, 16.7]:
acc += frame_ms/1000
while acc >= DT:
pos_f += vel_f * DT
acc -= DT
print("variable", round(pos_v, 4), "fixed", round(pos_f, 4))Observed on this draft host (Python 3.12.3, 2026-12-03):
variable 0.1501 fixed 0.15The mismatch is tiny here because the model is linear motion. Fiedler's point lands with springs, collisions, and integrators that amplify uneven dt: one long frame can tunnel objects or destabilize solvers [2]. Clamp huge spikes so a hitch does not schedule dozens of catch-up steps in one visual frame [2].
Fix the timestep so physics stays honest
Variable frame time straight into simulation is convenient and wrong for many physics systems [2]. Safer pattern:
accumulator += frameTime
while accumulator >= dt
integrate(state, dt)
accumulator -= dt
render(state) # optionally blend previous and current using leftover fractionDisplay refresh and simulation rate need not match [2]. Heavy rendering pushes work to GPU or simplified shaders (CPU vs GPU vs NPU vs TPU). Offline path tracing in Blender is a different loop: sample until convergence per pixel (how Blender Cycles renders).
Input sampling: poll vs event queue
Wikipedia's loop checks input every iteration [1]. Engines may batch OS events into a queue, drain it once per frame, then apply actions at simulation ticks so replays stay deterministic. Mobile titles care about touch coalescing; desktop FPS titles care about raw mouse delta time.
Audio often runs on its own clock but must stay within a few milliseconds of simulation lip sync. That is another reason the loop is more than requestAnimationFrame on the web: browsers schedule paint; they do not own your physics authority.
Interpolation for render-only smoothness
When simulation runs at 60 Hz and the display is 144 Hz, render can blend between the previous and current physics state using the fractional leftover in the accumulator [2]. Players see smooth motion even though integration steps stayed fixed. Without interpolation, entities appear to stutter on high refresh panels while physics is technically correct.
Spike frames and spiral of death
Fiedler warns about the spiral of death: if simulation cannot finish dt steps before the next visual frame arrives, the next frame adds even more debt [2]. Games cap the number of substeps per frame or clamp maximum frameTime fed into the accumulator so one pause does not simulate seconds of physics in one visual tick. Teaching loops should mention the cap even if your first prototype omits it.
Determinism vs floating point
Fixed dt improves repeatability for gameplay, but floating-point integration still drifts across platforms [2]. Lockstep multiplayer may fix random seeds and integration order separately from render rate. This page stops at single-player honesty; networked clocks are another article.
Fixed tick for simulation events
Rhythm games and netcode often quantize input to simulation ticks so replays stay reproducible [2]. Even when render runs at variable fps, input may be tagged with the tick it affected. Thinking in ticks separates "what the player saw" from "what the sim believes," which helps when debugging desync reports.
Profiling loop sections
A practical optimization pass measures time in input, physics, AI, and render buckets per frame [1]. If physics is cheap but render dominates, you optimize draw calls, not integrators. If physics spikes, fixed substeps and collision broadphase are suspects. Without splitting the loop, teams buy hardware for the wrong bottleneck.
Sleep versus spin
Mobile and console titles sleep until the next frame boundary to save battery [1]. Benchmark demos sometimes spin tight with no sleep to max fps; that is not the shipping pattern. Your loop should match platform expectations: vsync on, frame limiter on, or uncapped only when you accept heat and noise.
Wikipedia's scope versus engine reality
Wikipedia lists AI, collisions, and audio inside one loop for clarity [1]. Shipping engines split work across jobs (animation, navmesh bake, streaming) but still present a single authoritative simulation step per tick for gameplay state. Readers should treat the pseudocode as responsibilities, not proof that one thread does everything.
Where people go wrong
Tying gameplay speed to frame rate. If movement uses speed * frameTime without fixed substeps, a 30 fps run feels different from 144 fps unless you compensate carefully [2].
Using vsync as physics clock. Vsync caps present time; simulation still needs its own dt discipline.
Skipping the loop during menus. If you pause simulation but not audio networking, desync follows. Decide what "paused" freezes.
Multithreading replaces loop design. Threads help workloads; one authority still owns game state each tick.
Blaming the GPU when jump height changes with thermal throttling. That pattern often signals variable dt in physics, not weak silicon [2].
Log dt for sixty frames and watch variance before you blame game feel on art. When draw calls dominate, CPU vs GPU vs NPU vs TPU names which device owns the bottleneck; realtime shading stages in what is a shader sit inside the same frame budget as this loop. Offline sampling in how Blender Cycles renders is the contrast picture when convergence beats sixteen milliseconds.
Send this to the friend who ties physics to raw frame time and wonders why springs explode.

Keep this guide
Filed under Dev explainers, Science
Questions about this guide
How is a game loop different from a normal app?
Most desktop apps sleep until input. Games keep advancing simulation time, AI, physics, and drawing even when the player is idle, so the world does not freeze. The loop is that continuous update and present cycle.
What is delta time?
Delta time is the elapsed real time since the last frame. Feeding raw, spiky frame times directly into physics integrators can make springs explode or objects tunnel. Engines often accumulate real time and consume it in fixed simulation steps instead.
Should render and physics share one rate?
Not always. A common pattern runs simulation at a fixed dt (for example 1/60 s) while rendering as fast as the display allows, optionally interpolating between the last two simulation states for smooth motion.
Is this the same as a browser requestAnimationFrame?
requestAnimationFrame is a display-paced callback hook. A full game loop still decides simulation substeps, input, audio, and networking. rAF is one scheduler; the loop is the whole cycle.
Sources
- Gaffer On Games: Fix Your Timestep!, accessed 2026-12-03gafferongames.com
- Full Byte Developer: How Blender Cycles rendersfullbytedeveloper.com
- Full Byte Developer: CPU vs GPU vs NPU vs TPUfullbytedeveloper.com