Quick answer: After pygame.image.load(...) call .convert() (opaque) or .convert_alpha() (transparent). The Surface now matches the display’s pixel format, blits go fast.
Loading 100 sprites and blitting them costs 30ms per frame. Each blit converts pixel format on the fly. Convert once at load time.
The Symptom
Frame rate drops with sprite count. Profiler shows blit time scaling unexpectedly. Pre-converting fixes it.
The Fix
import pygame
pygame.init()
screen = pygame.display.set_mode((1920, 1080))
# Load + convert once
player_img = pygame.image.load("player.png").convert_alpha()
floor_img = pygame.image.load("floor.png").convert()
# Reuse
while running:
screen.blit(floor_img, (0, 0))
screen.blit(player_img, (px, py))
pygame.display.flip()
Convert at load. Blits in the loop are fast.
Convert Mode Choice
- convert(): drops alpha. Fastest. Use for opaque sprites.
- convert_alpha(): keeps per-pixel alpha. Slightly slower than convert but still much faster than no-convert.
Verifying
Profile with cProfile or pygame.time.get_ticks. Blit time should drop dramatically after converting. Without convert: per-blit format negotiation.
“Convert once. Blits cheap.”
Related Issues
For BLEND_RGB_ADD, see BLEND additive. For text antialias, see text edges.
Convert at load. Frame rate climbs.