The Anatomy of a Game: Sprites, Loops & Collision

What happens 60 times per second

1

The Game Loop

Every game runs one loop, forever: read input, update the world, draw everything, repeat. This loop runs 60 times per second. Watch the steps highlight in real time as the game below runs.

1Input
2Update
3Draw
60/sRepeat

Use arrow keys or WASD to move the green square. The loop steps highlight in real time.

while (gameRunning) { readInput(); update(dt); draw(); }
This is the entire structure of every game ever made. Everything else is just details inside update() and draw().
2

Sprites: Objects in the World

A sprite is any visual object in the game: the player, enemies, coins, bullets. Each sprite has a position (x, y), a size, a velocity, and an image. Moving a sprite just means changing its x and y every frame.

Click anywhere to spawn a sprite. Each one has random velocity.

3

Collision Detection

How does the game know when two objects touch? It checks if their bounding shapes overlap. The simplest check: do two rectangles overlap? Watch the collision boxes light up when objects intersect.

Use arrow keys to move the green box. Collisions turn red.

AABB (Box)

Axis-Aligned Bounding Box. Check if two rectangles overlap by comparing edges. Fast and simple. Used for most 2D games.

Circle

Check if the distance between centers is less than the sum of radii. Perfect for balls, bullets, and round objects.

Pixel Perfect

Check individual pixels for overlap. Most accurate but slowest. Only used when precision matters more than performance.

4

Every Game Uses These

From Pong to open-world RPGs, every game is built on the same foundation you just explored.

Platformers

Game loop + gravity (update y velocity each frame) + ground collision (stop falling when touching floor) + input (jump on spacebar).

Shooters

Sprites for bullets (spawn on click, move each frame) + enemy sprites + circle collision (bullet hits enemy when distance < radius).

Puzzle Games

Grid-based sprites + input to move pieces + collision to check valid placement + state update to check win conditions.

Racing Games

Sprite for car + input for steering + velocity/acceleration physics in update + track boundary collision.

Fun Fact

The original Pac-Man runs at 60.6 fps on a 3 MHz processor. The entire game logic, ghost AI, input, rendering, and sound fit in 24 KB of ROM. Every modern game framework gives you more power in a single function call.

Game Developer!

You've seen the engine behind every game: a loop that reads input, updates the world, and draws the result, 60 times per second. Sprites, physics, and collision detection are just the pieces inside that loop.

0
Frames Rendered
0
Collisions Detected
0
Time Exploring

The Game Loop

Every game runs a loop: read input, update game state, draw everything, repeat. This loop runs 30-60+ times per second. Everything you see is just one frame of this loop.

Sprites Are Images

A sprite is a 2D image that represents a game object: a character, enemy, bullet, or background tile. Moving a sprite means changing its x,y position each frame.

Input Drives Action

The game loop checks keyboard, mouse, or controller state every frame. Pressed keys set velocity. Released keys stop movement. Input is just data.

Collision = Overlap

Two objects collide when their bounding boxes or circles overlap. Check every pair every frame. When they overlap, trigger the response: bounce, damage, collect, or block.

Ready to Create?

Put your new knowledge into practice!

Suggest a Correction