Choosing a random sound Pygame

2019-09-07 04:53发布

问题:

I was wondering how to go about picking a random sound and playing it on an event in an OOP way. My original plan was have a list in my resource loader class, and have it iterate through that. My only issue is my code constantly breaks everything when I try to implement this. How would you guys go about this?

回答1:

class SoundManager:
    sounds = [] # list of sound objects

    @staticmethod
    def playRandom():
        random.choice(SoundManager.sounds).play()


标签: python pygame