Choosing a random sound Pygame

我们两清 提交于 2020-01-06 12:56:55

问题


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()


来源:https://stackoverflow.com/questions/28865782/choosing-a-random-sound-pygame

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!