📝 Worksheet← Lesson← Course
BitWithBite
Pygame Mastery · Quick Reference

Camera System Cheat Sheet

Pygame Mastery
In one line: A camera is just an offset vector subtracted from world positions before drawing — everything else (follow, zoom, shake, parallax) builds on that.

Key Ideas

1Camera Offset. apply(pos) = pos - camera.offset. World objects never move; only the offset changes.
2Smooth Follow. Lerp the offset toward the target each frame instead of snapping instantly, for an eased feel.
3Zoom. Render to a smaller off-screen Surface, then scale it to fill the window — scaling up zooms in.
4Screen Shake. Add a small random offset to the camera for a limited duration after an impact, often decaying.
5Parallax. Multiply the camera offset by a depth factor per background layer — distant layers move slower.
6Mini-map. Same offset math, just drawn at a smaller scale into a corner Surface.

Core Snippets

def apply(self, pos):
  return pos - self.offset
self.offset.x += (target_x - self.offset.x) * smoothing * dt
layer_x = -camera.offset.x * depth_factor
WorldViewportcamera.offset
apply(pos) = pos - camera.offset — the viewport is a fixed-size window scrolled across the larger world by that offset.