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

Re: [pygame] Re: sprite.spritecollide

I'm pretty confident it returns the instances, not the class itself, unless the new PyGame has changed things... Here's some old code from one of my old projects to show you:

        hit_cells = pygame.sprite.spritecollide(shuriken, self.cancer_sprites, False)
        if hit_cells:
          for e in hit_cells:
            if e.health <= 0:
              self.kills += 1

The last line shows that it's a reference, otherwise it wouldn't ever be able to remove the right one.

On Sat, Aug 15, 2009 at 2:06 AM, Henrique Nakashima <henrique.nakashima@xxxxxxxxx> wrote:
If '[<Tableau sprite(in 1 groups)>]' is the result of printing colliding_with, I'm pretty sure that is a list of only one instance of a Sprite. If it were the Sprite class itself if would be represented by '<class 'pygame.sprite.Sprite>' or something like that, and would not contain the number of groups the sprite is in.

That is also what the doc says:
"Return a list containing all Sprites in a Group that intersect with another Sprite. Intersection is determined by comparing the Sprite.rect attribute of each Sprite. "

If it really is returning just the class, then it's a bug in pygame.

On Sat, Aug 15, 2009 at 03:45, Maxwell Wise <maxdwise@xxxxxxxxx> wrote:
The sprites all have unique names... but spritecollide only returns
the class of the object, not the name or any other identifier to
distinguish between objects of the same class...