I'm beginner programmer and am using pygame for the first time--I'm stuck on a strange behavior with screen updating.
My sample code simply displays a count on the screen, starting at 0 going up one with every iteration. I want it to pause for 2 seconds at "10." Instead it pauses at "9" (or the frame before whatever you set the numbers at). "10," in this case will display (after the pause) as it continues at full speed.
Why is it pausing one "frame" early? The pause if-statement is just after the screen display update--I'm missing something...
#!/usr/bin/python
import pygame
pygame.init()
number = 0
color = (255, 255, 255)
done = False
pygame.mouse.set_visible(False)
info = pygame.display.Info()
screen = pygame.display.set_mode((info.current_w, info.current_h), pygame.FULLSCREEN)
screen_rect = screen.get_rect()
font = pygame.font.SysFont('ffmetapro', 96)
while not done:
for event in pygame.event.get():
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
done = True
text = str(number)
pygSurface = font.render(text, True, color)
screen.fill((0, 0, 0))
screen.blit(pygSurface, pygSurface.get_rect(center=screen_rect.center))
pygame.display.flip()
if number == 10:
pygame.time.delay(2000)
number = number +1
pygame.quit()
sys.exit()