如何将精灵的图像缩放为更大或更小?我可以更改rect和all,但不能更改图像。
代码:(虽然我不确定为什么你需要它)
class test(pygame.sprite.Sprite):
def __init__(self):
pygame.sprite.Sprite.__init__(self)
self.image = pygame.image.load("testImage.png").convert()
self.image.set_colorkey((255,255,255))
self.rect = self.image.get_rect()
答案 0 :(得分:3)
了解pygame的转换模块:http://www.pygame.org/docs/ref/transform.html
class test(pygame.sprite.Sprite):
def __init__(self):
pygame.sprite.Sprite.__init__(self)
self.image = pygame.image.load("testImage.png").convert()
self.image.set_colorkey((255,255,255))
# return a width and height of an image
self.size = self.image.get_size()
# create a 2x bigger image than self.image
self.bigger_img = pygame.transform.scale(self.image, (int(self.size[0]*2), int(self.size[1]*2)))
# draw bigger image to screen at x=100 y=100 position
self.screen.blit(self.bigger_img, [100,100])
答案 1 :(得分:2)
你试过吗
pygame.transform.scale()
官方文档指出您应该使用以下语法:
scale(Surface, (width, height), DestSurface = None) -> Surface