This Python Server-based game I’m building requires data to be sent back and forth between the host and the client. But the client’s pygame window keeps flashing.
I have this class loop (my_player)
my_player.start()
player_thread = threading.Thread(target=my_player.run_display)
player_thread.start()
this is the class pygame (my_player) class code
def start(self):
pygame.init()
self.screen = pygame.display.set_mode((width, height))
self.clock = pygame.time.Clock()
self.running = True
def run_display(self):
while self.running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
self.running = False
with lock: # Acquire the lock before accessing shared resources
self.move()
self.draw_map()
pygame.display.flip()
self.clock.tick(60)
pygame.quit()
The loop does work the screen flashes like crazy and objects load in and out. How could I fix this?
I tried removing the ‘while self.running’ which still caused the screen to flash. I also tried to keep the while self.running and remove the thread and just run as a function, which also gave flashing.
ImOkayAtPython is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.