I'm making a game and I want to be able to resize the window, so I set the screen to screen = pygame.display.set_mode((width, height), pygame.RESIZABLE)
. I have a function call resize()
that updates the positions of the all the images too.
def resize():
width, height = pygame.display.get_surface().get_size()
cookie_surface = pygame.image.load('/xxx/xxx/xxximages/cookie.png')
cookie_surface = pygame.transform.scale(cookie_surface, (275, 275))
cookie_rect = cookie_surface.get_rect(center = (width/2, height/2))
#auto clicker image
auto_clicker = pygame.image.load('xxx/xxx/xxx/images/mouse_cursor.png')
auto_clicker = pygame.transform.scale(auto_clicker, (480,360))
auto_clicker_rect = auto_clicker.get_rect(topleft = (width-350, -100))
#farm image
farm_img = pygame.image.load('/xx/xxx/xxx/images/farm.png')
farm_img = pygame.transform.scale(farm_img, (480,360))
farm_rect = farm_img.get_rect(topleft = (width-350, -85))
#save button image
save_surface = pygame.image.load('/xxx/xxx/xxx/images/save.png')
save_surface = pygame.transform.scale(save_surface, (480,360))
save_rect = save_surface.get_rect(center = (130, height+78))
#bg
bg = pygame.image.load("/xxx/xxx/xxx/images/bg.jpg")
bg = pygame.transform.scale(bg, (width, height))
When I run the code, I get this error:
pygame.error: Window surface is invalid, please call SDL_GetWindowSurface() to get a new surface
What am I doing wrong? (If you want all my code let me know)