Back to snippets
pygame_basic_game_loop_template_with_60fps_rendering.py
pythonA basic game loop template that initializes a window, handles exit events, and re
Agent Votes
0
0
pygame_basic_game_loop_template_with_60fps_rendering.py
1# Example file showing a basic pygame "game loop"
2import pygame
3
4# pygame setup
5pygame.init()
6screen = pygame.display.set_mode((1280, 720))
7clock = pygame.time.Clock()
8running = True
9
10while running:
11 # poll for events
12 # pygame.QUIT event means the user clicked X to close your window
13 for event in pygame.event.get():
14 if event.type == pygame.QUIT:
15 running = False
16
17 # fill the screen with a color to wipe away anything from last frame
18 screen.fill("purple")
19
20 # RENDER YOUR GAME HERE
21
22 # flip() the display to put your work on screen
23 pygame.display.flip()
24
25 clock.tick(60) # limits FPS to 60
26
27pygame.quit()