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

Re: [pygame] sprite engine



On Thu, 2006-04-27 at 13:11 -0700, Kamilche wrote:
> I don't know what 'lostrects' would be for... 

The pygame sprite groups keep track of these "lostrects". It is used to
keep track of sprites that were deleted on the current frame. At the
start of the frame everything is cleared. If a sprite is then deleted,
we need to be sure to include that in the dirtyrects. If the sprite is
not deleted on a frame, then its "clear" rect is combined with its
"paint" rect.


> Finally - the use of the 'dirty' flag. I also use that, but only for 
> 'paint.' It's a whopper of an enhancement!

This is a great optimization when it can be used. It requires that you
have sprites not moving/updating on every frame. This can also only be
used when sprites are not overlapping. (Or when any sprites are
overlapping they are always dirty together).


The pygame containers for drawing handle the general cases. Once you
have a set of sprites that follow a more rigid set of rules, you will
always be able to optimize. The pygame sprite system tries to be
extensible enough so anyone can create a group subclass with its own
modified rendering logic.

Of course, since they are just generic containers with some generic
methods, there's no loss in going with your own classes for object
management.