【发布时间】:2018-12-22 02:39:33
【问题描述】:
我想在我的游戏中创建一个按钮来控制背景音乐的开启和关闭。第一次点击会停止背景音乐,第二次点击可以恢复音乐。现在我的按钮可以控制音乐的开启和关闭,但是我需要多次点击才能让它起作用,似乎每次都没有捕获点击事件,这是我的代码:
for event in pygame.event.get():
if event.type == pygame.MOUSEBUTTONDOWN:
if 20 + 50 > mouse_position[0] > 20 and 20 + 20 > mouse_position[1] > 20:
play_music = not play_music
if play_music:
pygame.mixer.music.unpause()
else:
pygame.mixer.music.pause()
pygame.display.flip()
clock = pygame.time.Clock()
clock.tick(15)
【问题讨论】:
标签: python button pygame game-development