From ff3367c0580b3f3d577b133b19c21c8d3ea14490 Mon Sep 17 00:00:00 2001 From: EKNr1 Date: Mon, 26 Feb 2024 13:27:00 +0100 Subject: [PATCH] Made it not crash when window gets resized. --- falling_sand.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/falling_sand.py b/falling_sand.py index 647efad..d883e8d 100644 --- a/falling_sand.py +++ b/falling_sand.py @@ -115,7 +115,7 @@ class FallingSand: self.mouse = pygame.mouse self.mouse_pressed = self.mouse.get_pressed() self.mouse_pos = self.mouse.get_pos() - self.sand_surface = pygame.Surface(self.screen.get_size()) + self.sand_surface = pygame.Surface(self.settings.window_size) self.sand_surface.fill(self.gray) self.matrix = pygame.PixelArray(self.sand_surface) @@ -187,7 +187,15 @@ class FallingSand: print("Bye!") def window_update(self, size): + w, h = size + self.settings.window_size = size + self.matrix.close() + old_sand_surface = self.sand_surface + self.sand_surface = pygame.Surface(size) + self.sand_surface.fill(self.gray) + self.sand_surface.blit(old_sand_surface, (0, 0)) + self.matrix = pygame.PixelArray(self.sand_surface) def spawn_sand(self, position): for ax in range(-8, 9):