import pygame,sys
pygame.init()
size = 40,40
screen = pygame.display.set_mode(size)
LEFT = 1
s = pygame.mixer.Sound("Sound.wav")
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
elif event.type == pygame.MOUSEBUTTONDOWN:
if event.button == LEFT:
s.play()
所以目前,我正在尝试使用 Pygame 制作游戏。我已将其设置为只要单击鼠标就会播放声音。它确实有效,但我真的很恼火,因为我一次只能听到一种声音效果。如果我快速点击 7 次,我可能只会听到 4-6 声。如果我快速单击两次,我只会听到一种声音。
我查看了有关重叠 Pygame 声音的各种其他问题(它与 pygame.mixer.Channel 有关,我不明白)。到目前为止,没有什么对我有用。有什么想法吗?
最佳答案
旧线程,但像我这样的人可能会遇到同样的问题
为了让 CodeSurgeons 解决方案正常工作,我必须使用较小的缓冲区大小初始化 pygame.mixer
pygame.mixer.init(buffer=2048)
或
pygame.mixer.pre_init(buffer=2048)
pygame.init()
关于python - 有什么办法可以让Python的声音重叠吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41273152/