Task 2.3: Add Background Image
- Save the image path as a variable: e.g.
background_image = "images/background/wooden_floor.jpeg"
- Then load it using
background = pygame.image.load(background_image)
- Make sure the background fits the window use
background = pygame.transform.scale(background, (size_x, size_y))
- 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 yourwhile running:
loop - A background showing up instead of a black screen!