Reputation: 37
Okay, so I want to make an overlay screen.
So whenever the keypress is p then the screen pauses and a screen pops up saying : "Press 'q' to quit or 'c' to continue," something like that.
Can anyone tell me how?
Upvotes: 1
Views: 2087
Reputation: 874
The easiest way to do this is using a submodule, then to create a new loop for blit()
-ing to the screen and event handling for this pause menu.
(This is methodology only; this is how I work my projects.)
Update: 13/12/11
The following excerpt of code is from the "parent" module. This is just the loop section of code. What you're looking for is the line button.doAction(screen)
, which basically tells PyGame to execute the applicable submodule (not important; you just need to call the "child" function as you would normally).
while mainRunning:
# --- Event Catching & Handling ---
for event in pygame.event.get():
# Quit PyGame safely upon exit
if event.type == pygame.QUIT:
mainRunning = False
# Make the buttons do actions
if event.type == pygame.MOUSEBUTTONUP:
mousePos = pygame.mouse.get_pos()
for button in menuList:
X = button.getXPos()
Y = button.getYPos()
if X[0] < mousePos[0] < X[1] and Y[0] < mousePos[1] < Y [1]:
button.doAction(screen)
pygame.display.flip()
pygame.quit()
So if we say that the function we wanted was playGame.levelChoose()
- remember, this is [submodule].[function] - then the loop in the "child" would be:
def levelChoose(screen, playerData, playerName):
levelChooseRunning = True
while levelChooseRunning:
# --- Event Catching & Handling ---
for event in pygame.event.get():
# Quit PyGame safely upon exit
if event.type == pygame.QUIT:
levelMenuRunning = False
pygame.display.flip()
(Of course, much code has been ommitted from these examples; if you'd like to pick apart the full files, they're over here on GitHub)
Let me know if there's more questions, because this probably just confused you some more...
Upvotes: 2