Skip to content Skip to sidebar Skip to footer

Permanently Delete Sprite From Memory Pygame

I want to delete a sprite permanently from the memory once an event occurs. Using self.kill() doesn't help as the image of the sprite is deleted, but the sprite is still there. Wha

Solution 1:

You have to use bomb_list instead of bomb. Iterate through bomb_list to move the bombs:

for bomb in bomb_list:
    bomb.move()

Use pygame.sprite.groupcollide instead of pygame.sprite.spritecollide() to finde the collisions between the Groupbomb_list and the Groupbullet_list:

bomb_hit_list = pygame.sprite.spritecollide(bomb, bullet_list, True)

bomb_hit_dict = pygame.sprite.groupcollide(bullet_list, bomb_list, True, True)

You don't need the loop for bullet in bomb_hit_list: at all, if the the arguments dokill1 and dokill2 are set True.

Post a Comment for "Permanently Delete Sprite From Memory Pygame"