My goal for my program is for it to loop over images and display them on the screen. When the user presses space, it is supposed goes to a new screen. For some reason, there is a lag from when the user presses space and when it breaks out of the game1 loop.
def game_loop1():
game1=True
winScreen=True
current=0
myfont = pygame.font.SysFont("monospace", 25)
label = myfont.render("Who is this person? (Press Space)", 1, (0,0,0))
while game1:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
if event.type == pygame.KEYDOWN:
if event.key==pygame.K_SPACE:
game1=False # doesn't break out of loop immediately here
gameDisplay.fill(white)
gameDisplay.blit(label,(0,500))
gameDisplay.blit(obama[current], (0,0))
current+=1
pygame.display.flip()
clock.tick(50)
pygame.time.delay(2500)
while winScreen:
gameDisplay.fill(white)
winLabel=myfont.render("The person was Obama! ", 1, (0,0,0))
gameDisplay.blit(winLabel,(0,500))
gameDisplay.blit(obama[len(obama)-1], (0,0))
pygame.display.flip()
pygame.time.delay(2500)
winScreen=False
How do I fix this?