Crisp pixel art in Pygame
Pixel art looks wonderful when every pixel is a sharp square, and muddy when scaling blurs it. Here's how to keep it crisp from the image file to the screen.
On this page
Use the right scaling function#
pygame.transform.scale() and scale_by() use nearest-neighbour sampling: each source pixel becomes a solid block. That's what pixel art needs. smoothscale() and rotozoom() filter and blur, which suits photos and painted art.
sprite = pygame.image.load("hero_16.png").convert_alpha()
sprite = pygame.transform.scale_by(sprite, 4) # 16x16 -> 64x64, crispPrefer whole-number scale factors#
Scaling 16 pixels by 4 gives perfect 4 × 4 blocks. Scaling by 3.5 means some source pixels become 3 pixels wide and others 4, and the art looks uneven. Pick a scale of 2, 3, 4 and so on.
Render small, scale once#
Instead of scaling every sprite, draw the whole game on a small Surface at your art's native resolution and scale the finished frame:
screen = pygame.display.set_mode((320, 180), pygame.SCALED)With SCALED, Pygame enlarges the 320 × 180 frame to the window for you, and mouse coordinates are converted back. Positions in your code stay in "art pixels", which keeps movement consistent with the art grid. More options in handling screen sizes.
Avoid jitter#
When objects move at fractional speeds, keep their positions as floats but draw at rounded coordinates: rect.x = round(x). At low resolution, moving a sprite half a pixel isn't possible, so rounding consistently avoids wobble. A camera that follows the player should be rounded too, otherwise the background and the player round differently and appear to shake against each other.
Rotation#
Rotating pixel art at arbitrary angles breaks the pixel grid. Common solutions: draw separate frames for the angles you need, rotate only in 90-degree steps (which are lossless), or render at low resolution and accept the stylised result.
Palettes#
A limited palette (often 8–32 colours for a whole game) is a big part of the pixel-art look and keeps sprites consistent. Pick colours with the colour picker, save them as a palette, and use the same palette in the pixel art editor.
Workflow#
- Draw sprites at native size (16 × 16 or 32 × 32) in the pixel art editor.
- Combine animation frames with the sprite sheet generator.
- Load with
convert_alpha()and draw on a low-resolution screen usingSCALED.