80 likes | 299 Views
Using Images. Lecture 10. Drawing Images to the Screen. Before we have only used pygame.draw. Using the Images. We need to load the images Then blit them to the screen. Adding a Background Image. Put the file in the same folder as the python file.
E N D
Using Images Lecture 10
Drawing Images to the Screen Before we have only used pygame.draw
Using the Images We need to load the images Then blit them to the screen
Adding a Background Image Put the file in the same folder as the python file backimage = pygame.image.load("bg.jpg").convert() screen.fill(blue) screen.blit(backimage, (0,0))
Adding Images to the Entity We will need to add the image path to the constructor def__init__(self, size, filename):
Loading the Image def__init__(self, size, filename): self.masterImage = pygame.image.load(filename).convert() self.image= pygame.transform.scale(self.masterImage, (size, size)) self.rect = self.image.get_rect() self.image.set_colorkey(white)
Color Key The color key makes a certain color transparent def draw(self): self.image.set_colorkey(white) screen.blit(self.image, self.rect.topleft)
Scaling the Image The image must be resized in the grow function self.image = pygame.transform.scale(self.masterimage, (area, area))