# Pygame performance issue for many images

I've made a script for generating a game world based off of image pixel data.

Trying to make a python map editor

My progress so far has resulted in a program which loads an image and draws sprites in positions correlating with the map, like this:

Now the problem is that even for small levels, I'm noticing a drop in frame rate. The provided example level will make pygame drop from 100 fps to 80 fps. If the map is 40 x 40 the frame rate will be around 17.

This is concerning, for two reasons. The program is not doing anything else than drawing images right now, how bad will the frame rate be when game logic is also being calculated every frame? Second, the aim is to ultimately make a two-player strategy game, in which the levels would be significantly larger than the example, and in that case 20 frames per second is way below acceptable parameters.

Every sprite in the game is a 48x48 pixel png image with some portion of transparency. Everything except rendering the sprites is done once when the game starts. This is the only code being run on every frame:

    def draw(self):
self.screen.fill((0,0,0))

for e in self.map_layout.fixed_list:
self.screen.blit(e.picture, e.rect)


I'm guessing pygame's method for rendering images does not scale very well. Windows task manager shows my CPU utilisation at 2% with a map of size 40x40.

My question is: What can I do to improve frame rate? I don't mind switching from (or complementing) pygame to something else, so long as the transition is not very difficult for a novice programmer like myself.

• Are you using a texture atlas or are you using single images? – Vaughan Hilts Jan 11 '13 at 21:14
• @VaughanHilts Single images, but I'm going to implement a spritesheet today. Hopefully it will improve performance. – Anonymous Entity Jan 12 '13 at 3:50
• You should defintely do that - texture swapping can be a real killer. You should also look into implementing spritebatching if pygame does not natively support it, as that will also botch your performance! – Vaughan Hilts Jan 12 '13 at 5:23