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

Re: [pygame] groups



Gonzalo Castro wrote:
HI! I'm practising with groups and I have problems. ;)
I have 2 clases, ball and killer... they are more or less the same,
and 3 objects: a 2 of class ball and the other of class killer. I
grouped both of 2 objects balls into a group called my_balls. I define
it like this:

global my_balls= pygame.sprite.Group(ball, second)

and at  some point of the game I do:

print(myballs.has())

And this prints None. What Am I missing?

Thank you a lot. :)
group.has() is a membership test that takes at least one sprite as an argument. It tests if a one or more sprites are in a group. It it not for testing if any sprites are in a group. This is not documented, yet, but to check if a group is empty or not get its boolean value. An empty group evaluates to False.

print bool(my_balls)

or

if my_balls:
   print "has sprites"
else:
   print "empty"


--
Lenard Lindstrom
<len-l@xxxxxxxxx>