I add a pygame.time.wait(2000) function between two display updates expecting that after a keydown, it will first show up one text, then after 2 seconds, the second one. But it end up showing up the two texts simultaneously two seconds after the trigger. How should I correctly use the function to reach my goal?
import pygame
from pygame.locals import *
from sys import exit
SCREEN_WIDTH = 448
SCREEN_HEIGHT = 384
pygame.init()
screen = pygame.display.set_mode([SCREEN_WIDTH, SCREEN_HEIGHT])
my_font = pygame.font.SysFont("arial", 16)
textSurfaceObj1 = my_font.render('Hello world!', True, (255,255,255))
textRectObj1 = textSurfaceObj1.get_rect()
textRectObj1.center = (100, 75)
textSurfaceObj2 = my_font.render('Hello world!', True, (255,255,255))
textRectObj2 = textSurfaceObj2.get_rect()
textRectObj2.center = (200, 150)
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
exit()
if event.type == KEYDOWN:
screen.blit(textSurfaceObj1, textRectObj1)
pygame.display.flip()
pygame.time.wait(2000)
screen.blit(textSurfaceObj2, textRectObj2)
pygame.display.flip()