I try to display the list of settings after pressing the button, the problem is that I do it in the game loop and it is known that the text will appear and disappear over and over, is there any sensible way to get around it somehow? Thanks in advance
def settings_show():
draw_text('CONTROL:', font, WHITE, 115, 380),
draw_text('JUMP', font, WHITE, 190, 410),
screen.blit(Wkey, (140, 395)),
draw_text('LEFT', font, WHITE, 55, 450),
screen.blit(Dkey, (180, 435)),
draw_text('RIGHT', font, WHITE, 230, 450),
screen.blit(Akey, (100, 435)),
draw_text('SHOOT', font, WHITE, 210, 490),
screen.blit(SPkey, (125, 460)),
draw_text('NADE', font, WHITE, 55, 546),
screen.blit(Qkey, (5, 530)),
draw_text('MUTE MUSIC', font, WHITE, 55, 586),
screen.blit(Mkey, (5, 570)),
draw_text('UNMUTE MUSIC', font, WHITE, 55, 626),
screen.blit(Ukey, (5, 610)),
draw_text('FULLSCREEN', font, WHITE, 55, 666),
screen.blit(Fkey, (5, 650)),
draw_text('TAKE SCREENSHOT', font, WHITE, 55, 706),
screen.blit(F5key, (5, 690)),
draw_text('EXIT', font, WHITE, 55, 746),
screen.blit(ESCkey, (5, 730))
settings_button = button.Button(SCREEN_WIDTH // 1 - 1050, SCREEN_HEIGHT // 1 - 70, settings_img, 1)
if start_button.draw(screen):
start_game = True
MENUSELECT.play()
pygame.mixer.music.stop()
if exit_button.draw(screen):
MENUSELECT.play()
run = False
pygame.display.update()
if settings_button.draw(screen):
MENUSELECT.play()
settings_show()
CodePudding user response:
You must call settings_show()
in the application loop. Instead of calling settings_show()
when the button is pressed, set a state that indicates that the settings must be shown:
game_state = "start_menu"
# application loop
while run:
# [...]
if game_state == "start_menu":
if start_button.draw(screen):
start_game = True
MENUSELECT.play()
pygame.mixer.music.stop()
if exit_button.draw(screen):
MENUSELECT.play()
run = False
if settings_button.draw(screen):
MENUSELECT.play()
game_state = "settings"
elif game_state == "settings":
settings_show()