0

Is there a method in pygame that removes a single sprite from a sprite group by passing it the rect.x and rect.y of the sprite?

Ex: single_sprite has a rect.x of 88 and a rect.y of 112

The method that does something like this: a_sprite_group.remove(88, 112) would remove the single_sprite from the group.

I flipped trough the doc and there doesn't seem to be one.

Eric
  • 363
  • 2
  • 9
  • 24
  • What if more than one sprite is at that location? – Natecat Jan 21 '17 at 03:01
  • `for sprite in (sprite for sprite in a_sprite_group.sprites() if sprite.x == 88 and sprite.y == 112): sprite.remove(a_sprite_group) ` – Natecat Jan 21 '17 at 03:04
  • Ah, well either way just iterate over the sprites in the group and compare the x, y then call Sprite.remove(); should only be a few lines. Edit: Now just make it a generic function. – GRAYgoose124 Jan 21 '17 at 03:05
  • 1
    you can always create small sprite with this position and use [pygame.sprite.spritecollide()](http://www.pygame.org/docs/ref/sprite.html#pygame.sprite.spritecollide) to remove from group elements which collide with this small sprite. – furas Jan 21 '17 at 09:24

0 Answers0