gpt4 book ai didi

button - 如何制作 “on-off”音乐按钮?

转载 作者:行者123 更新时间:2023-12-03 00:06:33 25 4
gpt4 key购买 nike

我的pygame有问题。我想知道如何在游戏中喜欢歌曲的“开/关”按钮。

if event.type == MOUSEBUTTONDOWN: 
if event.pos[0] > 35 and event.pos[0] < 105 and event.pos[1] > 460 and event.pos[1] < 565:
if pygame.mixer.music.play():
pygame.mixer.music.pause()
elif pygame.mixer.music.pause():
pygame.mixer.music.unpause()

在此先感谢您,我英语不好。

最佳答案

您不应该在pygame.mixer.music.play()条件下要求if,因为这是play函数而不是状态。

而是将状态保留在变量中:

music_playing = True
pygame.mixer.music.play()

...
while ...:

for events...:

if event.type == MOUSEBUTTONDOWN:
if event.pos[0] > 35 and event.pos[0] < 105 and event.pos[1] > 460 and event.pos[1] < 565:
if music_playing:
pygame.mixer.music.pause()
music_playing = False
else:
pygame.mixer.music.unpause()
music_playing = True

关于button - 如何制作 “on-off”音乐按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22614533/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com