Made it not crash when window gets resized.

This commit is contained in:
The Wobbler 2024-02-26 13:27:00 +01:00
parent 6da49ee7a6
commit ff3367c058

View file

@ -115,7 +115,7 @@ class FallingSand:
self.mouse = pygame.mouse self.mouse = pygame.mouse
self.mouse_pressed = self.mouse.get_pressed() self.mouse_pressed = self.mouse.get_pressed()
self.mouse_pos = self.mouse.get_pos() 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.sand_surface.fill(self.gray)
self.matrix = pygame.PixelArray(self.sand_surface) self.matrix = pygame.PixelArray(self.sand_surface)
@ -187,7 +187,15 @@ class FallingSand:
print("Bye!") print("Bye!")
def window_update(self, size): def window_update(self, size):
w, h = size
self.settings.window_size = 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): def spawn_sand(self, position):
for ax in range(-8, 9): for ax in range(-8, 9):