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

Re: [pygame] Remove a sprite



Are you sure the sprite doesn't belong to another group?  As long as a
sprite belongs to at least one group, it will continue to live.  Also
check to see if some other object is referring to it.  That should
also keep it alive.

On 5/4/05, Matt Bailey <mattb@xxxxxxxxxx> wrote:
> I'm using sprite.Group.remove(). Here's a direct snippet from one of my games:
> 
>     pygame.sprite.Group.remove(self.group, self)
> 
> where "self.group" is the group you're removing the sprite from, and "self" is
> the sprite.
> 
> Interestingly, this isn't in the docs exactly, for either the online docs
> (current, I assume) or the docs that came with my 1.6.2 Pygame Linux build.
> I'm gonna have to look at the version of the docs on my Windows install, they
> must be different (I don't know where else I would have got this).
> 
> Looking at the online docs and my 1.6.2 docs, I don't see why your code
> wouldn't work (assuming you've done the proper "from <module> import * "
> etc). I assume you're trying to get rid of something once it moves off
> screen? Are you sure there's no possibility of the sprite not being equal to
> posx/posy before moving off screen? Personally I'd change your condition
> statement to:
> 
>     if (sprite.rect.centerx >= posx and sprite.rect.centery >= posy):
> 
> That way you're not relying on the object being *exactly* at the max X/Y
> coords.
> 
>         -Matt Bailey
> 
> On Tuesday 03 May 2005 12:40, teo von upereth wrote:
> > Hello,
> >
> > I'm trying to remove a sprite but it doesn't work... The sprite is not
> > removed.
> >
> > Here a sample of my code :
> >
> > for sprite in wb_group_sprites.sprites():
> >       if (sprite.rect.centerx == posx and sprite.rect.centery == posy):
> >           wb_group_sprites.remove(sprite)
> >
> > Thanks in advance
> >
> > teo
> 
> 


-- 
Andrew Ulysses Baker
"failrate"