App 6: Make a Game, Snake in Pygame / Build Snake
Lesson 2 of 10
The game loop
Games run in a loop about 10 to 60 times a second: handle events, update the game, draw everything. clock.tick() controls the speed.
Key points
- Events, update, draw
- QUIT event when the window closes
- clock.tick(10) = 10 frames a second
clock = pygame.time.Clock()
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
screen.fill((10, 16, 32))
pygame.display.flip()
clock.tick(10)
pygame.quit()Your turn
Add the game loop. The window should stay open until you close it.
Quiz · +10 XP
What does pygame.display.flip() do?
Log in to save progress and earn XP.