[英]How do I make my pygame character animations the same size if some of them are different sizes to start with?
目前我正在嘗試為我的游戲編寫一個跳轉 animation 代碼。 我已經設法讓跳躍的 animation 工作,但圖像的大小與我的其他動畫不同。 除了大小,動畫都很好。 我從這個鏈接中得到了我要使用的角色。
這是我加載動畫的代碼:
player_size = (80, 80)
for n in range(0, 10):
img_right = pygame.image.load(f'img/Character animations/Jump Start/Jump Start_{n}.png').convert_alpha()
img_right = pygame.transform.smoothscale(img_right, player_size)
img_left = pygame.transform.flip(img_right, True, False)
self.images_jump_start_right.append(img_right)
self.images_jump_start_left.append(img_left)
for n in range(0, 12):
img_right = pygame.image.load(f'img/Character animations/Idle/Idle_{n}.png').convert_alpha()
img_right = pygame.transform.smoothscale(img_right, player_size)
img_left = pygame.transform.flip(img_right, True, False)
self.images_idle_right.append(img_right)
self.images_idle_left.append(img_left)
for n in range(0, 16):
img_right = pygame.image.load(f'img/Character animations/Walk/Walk_{n}.png').convert_alpha()
img_right = pygame.transform.smoothscale(img_right, player_size)
img_left = pygame.transform.flip(img_right, True, False)
self.images_run_right.append(img_right)
self.images_walk_left.append(img_left)
我嘗試將跳轉圖像的大小與其他圖像分開,但它要么相同,要么更大。
有人對問題所在有任何想法嗎?
提前感謝您的幫助:)
您必須對所有圖像使用一個縮放因子。
定義比例因子(例如:0.5):
image_scale = 0.5
編寫一個 function 通過縮放因子縮放圖像:
def scale_surface(surf, scale):
width = round(surf.get_width() * scale)
height = round(surf.get_height() * scale)
return pygame.transform.smoothscale(surf, (width, height))
使用 function 和比例因子來縮放所有圖像。 例如:
img_right = scale_surface(img_right, image_scale)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.