Scale your gaming character with Pygame

Pygame offers the pygame.transform module which we can use to rotate, flip as well as scale the gaming character as we wish to and today I am going to show you how to scale down the gaming character with the pygame.transform.scale method. The pygame.transform.scale method is really simple to use, all we need is a surface, and a tuple contains both the scale width and scale height, there is another third parameter in the method which is the optional destination surface but we usually do not need it in most of the scenario so we can leave it alone at the moment. Here is how to scale a game character to a new dimension.

self.image = pygame.transform.scale(self.image, (32, 32)) #this method takes in a surface plus a tuple contains both the scale width and the scale height and it returns a new surface which will be assigned to the self.image

The method above should be included under the setImage method of the GameSprite module which we have created in the previous tutorial and we will only apply it if the enemy and the player has overlapped each other. Below video will show you how the player will be scaled to smaller size after it has overlapped with the enemy.