[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] pygame slowness



On Thu, 2005-12-15 at 18:47 +0100, Lionel barret De Nazaris wrote:
> my game (a cross between a shoot them up and gauntlet) is running so 
> slow that i consider abandoning python and pygame (at least for display 
> and collision detection).
> I would be very grateful if anybody could lend a hand to help and avoid 
> this, I really like Python.

The first and easiest place to check is if your Surfaces are the proper
format for fast blitting. If you are using any alpha transparency, get
rid of it. It's the slowest draw operation pygame has. If you do need
some alpha blending, use it only where absolutely necessary.

Make sure every image you load you also call Surface.convert() on it.
This makes sure the image is the same pixel format as the screen. Blits
with the same pixel format are fast. Mismatched formats need to convert
as they blit, which is slower. If you have a lot of text, look at
creating blended text with colorkeys, instead of alpha transparency for
antialiasing.

I would also double check that your screen rendering tries to be
efficient. If parts of the screen are not animating, hopefully you don't
have to redraw them every frame. Also use the pygame.display.update()
call in these situations, with a list of only the modified areas. If
your game is scrolling, or the entire screen animates each frame, forget
all that fancy updating and just draw everything as straighforward as
possible.

Also try to ensure you have no unnecessary "overdraw". This means
modifying the same pixel more than once per frame. Obviously with many
moving objects you will be required to have some overdraw (assuming they
are non rectangular). But try to minimize this expense, especially for
background elements.