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

Re: [pygame] Could sprite drawing be done but a Sprite.draw function?



Hey,

it can seem a bit weird that drawing is done in the Group, and not the Sprite.

However, since you will nearly always be drawing all the sprites every time, then it makes sense to draw them in the group.

There are things like z-order as well, which make drawing in the group the way to do it.  If you did Sprite drawing, then each Sprite would first need to talk to the other sprites in order to know when to draw.

cu.


On Sun, Jul 24, 2011 at 11:48 PM, Mac Ryan <quasipedia@xxxxxxxxx> wrote:
Hi all,

I'm pretty new to pygame (although I have good experience with python)
and this is my first message on the list. Bear with me if what I am
about to ask has been already discussed.

While working around my first program, I realised that while each
sprite has an update() function, it's drawing happens at group level,
by blitting the s.image and s.rect directly, which somehow limits this
functionality (for example making impossible to set blit flags).

I was wondering if this was a design choice, and in that case, what's
the rationale behind it.

I realise both that:

 1. Calling a sprite function is expensive
 2. I can override the group.draw method to call a sprite function

Yet it seems to me that having a sprite.update without a sprite.draw
is "inconsistent" from an API standpoint.

I did not profile the code to see how big is the performance hit
because of #1, but #2 has serious limitations as a workaround: for one,
the draw() method changes in each an all of the group classes, so if
the sprite must use a draw method, one will have to override _all_ of
the draw methods of the types of groups used in the program.

Your thoughts?
/mac