Is there a way to shufle a group of sprites created with:
I have tried using random.shuffle but it apparently doesn't work on sprite groups.
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It only takes a minute to sign up.Sign up to join this community
According to pygame documentation:
The Sprites in the Group are not ordered, so drawing and iterating the Sprites is in no particular order. http://www.pygame.org/docs/ref/sprite.html#pygame.sprite.Group
I think the best you can do is not to use the Group, and make your own group mechanism. If you need only ordered update then use http://www.pygame.org/docs/ref/sprite.html#pygame.sprite.OrderedUpdates
As other already said, the
sprite.Group iterator yield its members in an unordered way (like a
dict, not like a a
So if you're after a simple unordered list (not properly shuffled with a random method - if you want that follow user744's answer), just get what it gives by default.
The "problem" here is quite the contrary: how to get an ordered list of sprites from it (or a sprite by its index in the group)