0

I created some groups (pygame.sprite.LayeredUpdates) as global variable in my code. But when I use "groupA = groupB" and "groupA.empty()", it shows that groupB is also empty.

if not in_bag_intro:
    all_sprite = bag_sprite
    background_sprite.empty()
else:
    all_sprite.empty()
    print(bag_sprite.sprites()) #result:[]
    all_sprite.add(bag_item_intro)
    background_sprite = bag_sprite

Besides, this part is in a while-loop, so I don't want to copy a sprite each time to save memory. Now I use a flag to see if all_sprite need change (ex: the moment that "in_bag_intro" turns to True or False, I'll change the flag into True). But if I run this code for a long time, the times it copy will still over 100 times.
By the way, does group.copy() consume memory? I ask this question because of the result "sprite XXX (in 1000 groups)"

Rabbid76
  • 177,135
  • 25
  • 101
  • 146
  • 2
    `all_sprite = bag_sprite` does not create a copy of the group; it just makes a second name for the *same* group. Read https://nedbatchelder.com/text/names.html – chepner Feb 28 '22 at 22:12

0 Answers0