我正在做一个pygame游戏,我正在尝试添加背景音乐。这一切工作,直到我按空格键,这会导致其他声音效果(拍摄声音),但它停止了背景音乐,我不知道为什么和如何解决这个问题。
pygame.mixer.music.load(background_music)
pygame.mixer.music.play(-1,0.0)
这就是按空格键时的声音效果(在主循环中):if keys[pygame.K_SPACE]:
if (len(bullets) < 4 and shootLoop == 0 and not (ship.isBolt)) or (len(bullets) < 8 and shootLoop == 0 and ship.isBolt):
if not (ship.isBolt):
bullets.add(Projectile(round(ship.rect.x + ship.width / 2 - 5), ship.rect.y - ship.height - 8))
else:
bullets.add(Projectile(ship.rect.x + ship.width - 11, ship.rect.y - ship.height + 8))
bullets.add(Projectile(ship.rect.x - 4, ship.rect.y - ship.height + 8))
pygame.mixer.music.load(SOUND_SHOT)
pygame.mixer.music.play()
这是我用来播放背景音乐的代码
如何修复?你知道吗
使用频道如果你想另一个效果的声音使用pygame.mixer.Channel频道(1) 例如你能试试这个吗
你可以这样使用它:
相关问题 更多 >
编程相关推荐