Background blit performance in pygame
On 17 Sep 11
I’m participating in this week’s pyweek and was having performance problems blitting a background image to the screen. Specifically, the game dropped to 20 frames per second on my brother’s five year old Linux box. The fix was simple, but not that easy to find if you don’t know where to look: There are convert and convert_alpha methods that will turn the surface into a more efficient in-memory format, greatly speeding up blitting. If you don’t do the conversion yourself, pygame has to convert the surface on every blit. That’s why the performance impact is worse when blitting larger images.
Use them like this:
self.background = pygame.image.load('gfx/bg01.png').convert()