8.5.5 - Background

To change the background from a dull color to an image we need:

  1. An image of our choice as a background
  2. A command to convert the image for the pygame
  3. A command to blit the image instead of filling with uniform color

For the background image download it from here and save it as background.jpg inside the working folder.

background

The commands to draw the background are:

background_image = pygame.image.load("background.jpg").convert()

before the main loop but after the screen's set mode and :


screen.blit(background_image, [0, 0])

instead of screen.fill(COLOR) command inside the main loop. The code can be downloaded from here (avoid_v0.8.0.py)