1 / 8

Using Images

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.

beulah
Download Presentation

Using Images

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Using Images Lecture 10

  2. Drawing Images to the Screen Before we have only used pygame.draw

  3. Using the Images We need to load the images Then blit them to the screen

  4. 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))

  5. Adding Images to the Entity We will need to add the image path to the constructor def__init__(self, size, filename):

  6. 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)

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

  8. Scaling the Image The image must be resized in the grow function self.image = pygame.transform.scale(self.masterimage, (area, area))

More Related