There are couple of changes to be made:
self.displaySurface
should be equal to pygame.display.set_mode(self.size)
self.displaySurface = pygame.display.set_mode(self.size) #Making the screen
(Note that you need to move the line self.size = (self.width, self.height) = 1920, 1080
above self.displaySurface = pygame.display.set_mode(self.size)
, so that you can use self.size
in self.displaySurface = pygame.display.set_mode(self.size)
)
- You need to use a while loop to keep check of all the events taking place on the game screen and to update the screen at every single frame
while self.isRunning:
for event in pygame.event.get():#Get all the events
if event.type == pygame.QUIT:#If the users closes the program by clicking the 'X' button
pygame.quit()#De-initialise pygame
sys.exit()#Quit the app
pygame.display.update() #Update the screen
- To execute the
__init__
method of the class you need to create an object
app = Application()#Creating an object
So the final code should look somewhat like:
import pygame
import os
import sys
class Application:
def __init__(self):
pygame.init()
self.isRunning = True
self.size = (self.width, self.height) = 1920, 1080 #A tuple
self.displaySurface = pygame.display.set_mode(self.size) #Making the screen
self.fpsClock = None
self.attractors = []
while True:
for event in pygame.event.get():#Get all the events
if event.type == pygame.QUIT:#If the user closes the program by clicking the 'X' button
pygame.quit()#De-initialise pygame
sys.exit()#Quit the app
pygame.display.update() #Update the screen
app = Application()#Creating an object