Task 2.3: Add Background Image

  1. Save the image path as a variable: e.g.background_image = "images/background/wooden_floor.jpeg"
  2. Then load it using background = pygame.image.load(background_image)
  3. Make sure the background fits the window use background = pygame.transform.scale(background, (size_x, size_y))
  4. Draw the background onto the screen use screen.blit(background, (0,0))

💡 Note

Make sure you add your background image before the game loop!

Try adding your own image! JPEGs are preferable since they don't get as blurry when you zoom in on them.


🚩 Checkpoint

  • A background_image variable (path to the image)
  • A background variable (the scaled loaded image)
  • A screen.blit(variable, coordinate) line outside your while running: loop
  • A background showing up instead of a black screen!