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()
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.
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.
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).
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.
Have you tried
pygame.transform.scale()
Official documentation notes that you should use this syntax:
scale(Surface, (width, height), DestSurface = None) -> Surface
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With