Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pygame scaling a sprite

Tags:

python

pygame

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()
like image 911
Charles Noon Avatar asked Jan 13 '14 00:01

Charles Noon


People also ask

How do you scale a sprite in Pygame?

You can make a Sprite bigger or smaller with the SET SIZE command. ACTIONS Toolkit - Scroll down to SPRITE SETTINGS - Set Size Block. Use a number less than 1 to make your sprite smaller and a number bigger than 1 to make the sprite larger.

How do you scale something in Pygame?

To scale the image we use the pygame. transform. scale(image, DEFAULT_IMAGE_SIZE) method where we pass the image that we are going to scale and the default image size that we will set manually according to our need.

How do you scale a surface in Pygame?

The resizing function you are looking for is pygame. transform. scale . Pass it a surface and the new size you want, and it will return a new surface, or place the result into an already created surface (this is faster).

How do I resize a rectangle in Pygame?

You can simply change the width and the height of the rect (the w and h attributes). When the mouse gets moved (a MOUSEMOTION event is added to the queue) and if the rect is selected, add the relative movement event. rel to the width and the height.


1 Answers

Have you tried

pygame.transform.scale()

Official documentation notes that you should use this syntax:

scale(Surface, (width, height), DestSurface = None) -> Surface
like image 165
Aidan Avatar answered Oct 04 '22 13:10

Aidan