'is that possible to exchange the member of a spritegroup in pygame
I randomly share pictures of houses on the screen. Then I drive a car across the screen.When the car hits a house,there are then a number of explosions in the picture of the house. it lasts about 3 seconds. then i want to exchange the picture of the house in the spritegroup for another picture.is that possible to change the member of a spritegroup?
treffer = pygame.sprite.spritecollide( auto, land, False, pygame.sprite.collide_mask)
for bumbs in treffer:
if bumbs not in auto.alte_treffer_liste:
expl = Explosion(bumbs.rect.center,"klein")
explosion_group.add(expl)
land ist the spritegroup with the pictures of the houses.
in land_copy ist the spritegroup with the copies of the house pictures
Solution 1:[1]
You need to kill the sprite and add another sprite. kill removes the Sprite from all Groups. e.g.:
treffer = pygame.sprite.spritecollide( auto, land, False, pygame.sprite.collide_mask)
for bumbs in treffer:
if bumbs not in auto.alte_treffer_liste:
expl = Explosion(bumbs.rect.center,"klein")
explosion_group.add(expl)
bumbs.kill() # <---
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Rabbid76 |
