我无法让我的背景在 Pygame 中自行缩小,我该怎么办?

I can't get my background to scale itself down in Pygame, what do I do?

看看下面的“pygame.transform.scale(bg_image, (-500, 600))”,按照 Pygame 网站上的说明进行设置,所以不知道还能做什么

import pygame, sys

pygame.init()
clock = pygame.time.Clock()
screen = pygame.display.set_mode((500, 900))
pygame.display.set_caption('Climbing Man')

bg_image = pygame.image.load("/Users/apple/Downloads/Python Projects/Climbing_Game/bckwall.jpg").convert
pygame.transform.scale(bg_image, (-500, 600)) 


def climbing_man():
    pass

while True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            sys.exit()
    
    screen.blit(bg_image,(-50,0))
         

    pygame.display.update()
    clock.tick(60)

pygame.transform.scale returns 新的 Surface 具有缩放尺寸。因此,您必须分配 return 值 bg_image:

pygame.transform.scale(bg_image, (-500, 600))

bg_image = pygame.transform.scale(bg_image, (500, 600)) 

但是,您不能缩放到负尺寸。如果你想翻转图像,你必须使用 pygame.transform.flip():

bg_image = pygame.transform.scale(bg_image, (500, 600))
bg_image = pygame.transform.flip(bg_image, True, False) 

另外,你忘了convert后面的括号:

bg_image = pygame.image.load("/Users/apple/Downloads/Python Projects/Climbing_Game/bckwall.jpg").convert

bg_image = pygame.image.load(
    "/Users/apple/Downloads/Python Projects/Climbing_Game/bckwall.jpg").convert()

完整代码:

import pygame, sys

pygame.init()
clock = pygame.time.Clock()
screen = pygame.display.set_mode((500, 900))
pygame.display.set_caption('Climbing Man')

bg_image = pygame.image.load(
    "/Users/apple/Downloads/Python Projects/Climbing_Game/bckwall.jpg").convert()

bg_image = pygame.transform.scale(bg_image, (500, 600))
# bg_image = pygame.transform.flip(bg_image, True, False) # <--- OPTIONAL


def climbing_man():
    pass

while True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            sys.exit()
    
    screen.blit(bg_image,(-50,0))
         

    pygame.display.update()
    clock.tick(60)