def options():
options = True
while options:
for event in pygame.event.get():
win.fill(WHITE)
win.blit(background, (0, 0))
... # Blitting text and switch buttons
options_x, options_y = pygame.mouse.get_pos()
if event.type == pygame.QUIT:
# Exit button
pygame.QUIT()
quit()
elif event.type == pygame.MOUSEBUTTONDOWN:
# Sound effect tuning
if 470 > options_x > 390 and 220 > options_y > 185:
# Checking if mouse click is on the ON SWITCH
mouse_click.play()
screen.blit(off_switch, (off_switch_x, off_switch_y))
pygame.mixer.stop()
# But doesn't stop sound from playing when I quit options section
# Music effect tuning
elif 470 > options_x > 390 and 300 > options_y > 260:
# Checking if mouse click is on the ON SWITCH
mouse_click.play()
screen.blit(off_switch, (off_switch_x, off_switch_y))
pygame.mixer.music.stop()
# Interactive BACK button
elif 90 > options_x > 42 and 75 > options_y > 25:
mouse_click.play()
options = False
pygame.display.update()这是我的绞刑游戏的一部分,我尝试设置选项部分,允许您配置音量。
问题在于“音乐”和“声音”的效果调整。
按下开关按钮的“音乐”和“声音”将显示关闭开关,但一旦我释放我的鼠标,他们回到原来的状态。
音乐停止了,但没有声音效果(鼠标点击,嗡嗡作响,等等)。
我希望图像闪烁被保存,声音效果被停止。我怎么才能解决这个问题?
发布于 2020-07-28 01:04:04
你在每一个循环中撤销blit。在顶部,我看到了清除\重置一切的代码。
win.fill(WHITE)
win.blit(background, (0, 0))
....您可以在事件处理程序中删除更改:
screen.blit(off_switch, (off_switch_x, off_switch_y))事件开关blit将在下一个事件循环中被清除(可能是鼠标移动)。
把这个游戏想象成一系列的州。循环顶部的代码应该绘制游戏的当前状态。
for event in pygame.event.get():
win.fill(WHITE)
win.blit(background, (0, 0))
if SwitchIsOn:
screen.blit(on_switch, (on_switch_x, on_switch_y))
else:
screen.blit(off_switch, (off_switch_x, off_switch_y))
....事件处理程序应用于更改游戏状态。
if 470 > options_x > 390 and 220 > options_y > 185:
# Checking if mouse click is on the ON SWITCH
mouse_click.play()
SwitchIsOn = not SwitchIsOn # reverse switch position这将防止您的事件更改被清除。
https://stackoverflow.com/questions/63086541
复制相似问题