IT lexicon › Programming › Pixel-perfect collision

Pixel-perfect collision

Programming På svenska → Updated: 2026-10-27

Two sprites only count as colliding when at least one of their visible pixels actually overlaps one of the other's.

Each sprite carries a bitmask recording which pixels are opaque. A cheap bounding-rectangle test runs first; only if the rectangles overlap are the masks compared within that overlap, row by row, with a bitwise AND. A single set bit in the result is a hit. The Commodore 64's VIC-II did this in silicon: two registers latched sprite-to-sprite and sprite-to-background collisions while the beam was drawing, with no CPU arithmetic at all.

It sounds like the fairest system possible, and players tend to experience the opposite. An enemy's stray tuft of hair kills them, and the shape changes with every animation frame. Modern games almost always use simplified hitboxes instead — often deliberately a little smaller than the character, so the close calls go the player's way.

← Back to the lexicon