buaa-soft-summer / soft-summer-2022

软件学院《程序设计实践》2022小学期仓库
26 stars 3 forks source link

飞机大战中,企图加入gameover音效却没能成功 #12

Closed CodingKirby8620 closed 2 years ago

CodingKirby8620 commented 2 years ago

在写飞机大战时企图往gameover中加入音效,但是最终gg时没有能播放出来,求解 相关代码:

#restrict gameover sound play
    played=False  #这一段在游戏循环外添加
elif life_num==0:
            #stop music,sound and timer,play gameover music
            pygame.mixer_music.stop()
            pygame.mixer.stop()
            pygame.time.set_timer(SUPPLY_TIME,0)
            if not played:#从这里到最后为gg音效执行的代码
                played=True
                gameover_sound.play()

在单步调试时音效可以正常播放,求问应该怎么做

echo17666 commented 2 years ago

if life_num==0: pygame.mixer.music.load(); pygame.mixer.music.play; 试试看