Change the background in Settings:

class Settings:
    def __init__(self):
        # [...]
    
        self.bg_color = pygame.image.load('images/space.bmp')

Get the background from the Settings object in the constructor of AlienInvasion. If the background image is a different size than the display, I recommend using pygame.transform.smoothscale() to scale the background to the correct size:

class AlienInvasion:
    """Overall class to manage game assets and behavior."""
    def __init__(self):
        # [...]
        self.settings = Settings()
        # [...]

        self.bg_color = pygame.transform.smoothscale(self.settings.bg_color, 
                            self.screen.get_size())
 

blit the background rather rather than fill the display surface:

class AlienInvasion:
    # [...]

    def _update_screen(self):
        self.screen.blit(self.settings.bg_color, (0, 0))

blit draw one image onto another. In this case it draw the background image (Surface) on the Surface which is associated to the display.


Note, that the name bg_color is misleading. If you are using a background image, you should rename it (e.g. bg_image or bg_surface).

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top