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