../

Creating a window in pygame

Creating A Window

import pygame
from sys import exit

pygame.init() # start pygame

screen = pygame.display.set_mode((800,400)) # creating display surface ((width,height))

pygame.display.set_caption('Runner') # title of the game

clock = pygame.time.Clock() #controlling the frame rate

while True:
    for event in pygame.event.get():  # get all the events and loop through them
        if event.type == pygame.QUIT:
            pygame.quit() #end the game
            exit() # breaking the loop

    # draw elements
    #update everything
    pygame.display.update() #getting all the things and put them in the display surface
    clock.tick(60) # should not run the while true loop faster than 60x per second

Common Event Types

Tags: /python/ /python3/ /pygame/ /gamedev/ /tutorial/