我正在制作游戏,我希望能够调整窗口大小,所以我将屏幕设置为screen = pygame.display.set_mode((width, height), pygame.RESIZABLE)
. 我有一个函数调用resize()
也可以更新所有图像的位置。
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))
当我运行代码时,我收到此错误:
pygame.error: Window surface is invalid, please call SDL_GetWindowSurface() to get a new surface
我究竟做错了什么?(如果你想要我所有的代码,请告诉我)