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

Working with Images Cheat Sheet

Pygame Mastery
In one line: Load images with pygame.image.load, always convert them, then scale/rotate/flip with pygame.transform and manage transparency correctly.

Key Ideas

1Loading Images. pygame.image.load(path) returns a Surface. Always follow with .convert() or .convert_alpha() for fast blitting.
2Image Formats. PNG supports real per-pixel alpha transparency; JPG has none; use PNG for sprites, JPG for photos/backgrounds.
3Scaling & Rotating. pygame.transform functions return a NEW Surface, never mutating the original — cache results instead of transforming every frame.
4Flipping. pygame.transform.flip(img, flip_x, flip_y) mirrors an image — common for facing direction changes.
5Alpha Channel. set_alpha(0-255) fades a WHOLE surface; convert_alpha() preserves real per-pixel PNG transparency.
6Asset Organization. Load every image once at startup into a dict; never call pygame.image.load() inside the game loop.

Common Mistakes

Loading images inside the game loop.
Load once at startup into a dict, reuse every frame
Forgetting .convert_alpha() on transparent PNGs.
Without it, blitting is slow and alpha may render wrong
Rotating the same image object every frame live.
Pre-generate a list of rotated frames once instead
Expecting transform functions to mutate in place.
They always return a NEW Surface — store the result
OriginalScaledRotatedFlipped
pygame.transform functions each return a new Surface — scale, rotate, and flip never mutate the original.