Pygame scaling a sprite

2019-05-11 02:46发布

How would one scale a sprite's image to be bigger or smaller? I can change the rect and all, but not the image.

Code:(though i'm not sure why you would need it for this)

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()

标签: python pygame
2条回答
虎瘦雄心在
2楼-- · 2019-05-11 03:35

Have you tried

pygame.transform.scale()

Official documentation notes that you should use this syntax:

scale(Surface, (width, height), DestSurface = None) -> Surface
查看更多
唯我独甜
3楼-- · 2019-05-11 03:36

Read about pygame's transform module: 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])
查看更多
登录 后发表回答