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

[pygame] Dirty rectangle rendering group



Hi Pygame users,

Since this is my first post I'll get the formalities out of the way: Thank you for Pygame Pete! I left the world of Delphi and Jedi-SDL when I found out about Python and Pygame. I'm very happy that I made the switch. I'm creating a commercial (shareware) puzzle game using Pygame.

I'd really like my games to run well on old hardware so I've created a dirty-rectangle y-sorting/z-sorting render group for Pygame. This is my first attempt at something like this so I'd like to get some feedback on the code (efficiency or logic improvements etc.), and would just like to get it out there for use by others.

A few things to note:
* It does things a bit differently from the normal Pygame render group method of clear, update, draw. The update() function is called to calculate all the changed areas of the screen (old and new), then draw() takes care of updating by doing a redraw of those changed areas.
* The screen clipping rect is used to clip sprites to dirty-rect areas. This allows for partial sprite drawing in areas where a dirty rect includes only part of a sprite.
* The background is just like any other sprite. It doesn't have to be this way but it's easy and makes sense if you have something like background tiles where each one is separate sprite.

I haven't done any speed comparisons between this group and something like the render updates group, so if anyone is up to the task of doing some comparisons I'd be very interested in the results.

The archive file which contains the render group and sprite base, and a simple test module that bounces around some alpha-blended images, is located at:
www.gamesinmind.com/pygame/zydr_group.zip

Check the source of the zydr_group_test.py module for info about keys that will do various things while the test is running.

-Pat
www.gamesinmind.com