1

I have a game doing a countdown, at the end of the countdown I want to display the text "Missle Away!" on the screen for 3 seconds. I have the code below but when I run it, the text never displays. If I remove the delay, the text displays but of course it does not disappear after 3 seconds.

def missle_call():
    global missle_active
    global active
    while missle_active == True:
        gameDisplay.blit(radarbg, (700, 100)) # clears the countdown text by writing the background image over it
        TextSurf, TextRect = big_text_objects("Missle Away!" , large_base_font) # set font & text 
        TextRect.center = (950, 300) # set location of text 
        gameDisplay.blit(TextSurf, TextRect) # render text to screen 
        pygame.time.delay(3000) # continue to show text on screen for 3 seconds 
        gameDisplay.blit(radarbg, (700, 100)) # cover text on display by blitting the background image on it 
        active = False # reset the launch execution to not launched 
        return

    else:
        return
Tugay
  • 2,057
  • 5
  • 17
  • 32
Daniac21
  • 57
  • 5

1 Answers1

0

The display is updated only if either pygame.display.update() or pygame.display.flip() is called. Further you've to handles the events by pygame.event.pump(), before the update of the display becomes visible in the window:

gameDisplay.blit(TextSurf, TextRect) # render text to screen 
pygame.display.flip()
pygame.event.pump()
pygame.time.delay(3000) # continue to show text on screen for 3 seconds 
Rabbid76
  • 202,892
  • 27
  • 131
  • 174