I'm trying to integrate a "pause" menu and "main" menu in pygame, along with a screen that will show during the game. My code first loads the intro, or main menu, which works fine, and then handles a button click to call the main game loop function. The problem arises when, within that loop, I try to call the function for the pause menu. I use the same loops to do this so I'm not sure why one works and the other doesn't. Below I've added code snippets for reference.
The main menu (which is called first in the program):
def intro_screen():
intro = True
while intro:
# Event listeners
for event in pygame.event.get():
main_window.fill(tan)
... I also have other buttons etc. which are unimportant, but to get out of the intro, a mouse event sets intro to false and calls the function game_loop:
# Handle the click event
if click[0] == 1:
intro = False
game_loop()
The game_loop function has a similar while loop:
def game_loop():
playing = True
paused = False
while playing:
# This is the main loop
# Load in the play screens...
main_window.fill(white)
play_screen = PlayScreen(main_window)
And buttons etc... But when I set playing to False and paused to True, which calls the pause_screen() function, it doesn't pull up any new screen. It just stays on the game menu as if no event was received.
for event in pygame.event.get():
if event.type == pygame.QUIT:
playing = False
# Listen for the escape key and bring up the pause menu
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
playing = False
paused = True
pygame.display.update()
while paused:
pause_menu()
For reference, these are all contained in functions. The last line of my code simply calls intro_screen(), which works fine.
I can provide the rest of the code if that would be helpful. The only thing I could think of is that the mouse event works and the keydown event doesn't, but my syntax looks to be correct from what I can tell.
paused
andplaying
are first defined and used – kaktus_car