Al momento de intentar cambiar el valor de la variable running
me indica en el propio VS que la variable no esta siendo accedida, requiero cambiar el valor de la variable que viene desde otra parte por referencia:
main.py:
import pygame
from public.modules.classes.Screen import Screen
FPS = 75
SCREEN_DIM = (1280, 720)
SCREEN_COLOR = (0, 0, 0, 0)
def main():
# pygame setup
pygame.init()
screen = Screen(SCREEN_DIM, SCREEN_COLOR, FPS)
screen.init()
while screen.running:
#screen.paint()
screen.listenForEvents()
#screen.graphics.drawCircle('red', (200, 200), 20)
# flip() the display to put your work on screen
pygame.display.flip()
screen.tick()
pygame.quit()
main()
Screen.py (Minimizado):
import pygame
from .Graphics import Graphics
from .EventHandler import EventHandler
class Screen:
def __init__(self, SCREEN_DIM = (1280, 720), SCREEN_COLOR = (0, 0, 0, 0), FPS = 75) -> None:
#Constants
self.FPS = FPS
self.SCREEN_DIM = SCREEN_DIM
self.SCREEN_COLOR = SCREEN_COLOR
#Variables
self.running = ~(True)
def init(self):
self.screen = pygame.display.set_mode(self.SCREEN_DIM)
self.clock = pygame.time.Clock()
self.eventHandler = EventHandler()
self.graphics = Graphics(self.screen)
def tick(self):
self.clock.tick(self.FPS / 1000)
def listenForEvents(self):
self.eventHandler.listenCloseEvent(self.running)
EventHandler.py:
import pygame.event
class EventHandler:
#Constructor
def __init__(self) -> None:
pass
#Evento para cerrar la ventana
def listenCloseEvent(self, running):
# poll for events
# pygame.QUIT event means the user clicked X to close your window
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = ~(True)
La propiedad hace parte de la clase Screen
se llama running
y debe ser cambiada desde EventHandler
.