pygame image background does not match main background

If the background has a uniform color, then you can set the transparent colorkey by pygame.Surface.set_colorkey. For instance if the background is the white (255, 255, 255):

image = pygame.image.load('./car1.bmp').convert()
image.set_colorkey((255, 255, 255))

Anyway that won’t solve the issue if the background has multiple colors.

I recommend to use an image format which supports per pixel alpha. For instance PNG (Portable Network Graphics):

image = pygame.image.load('./car1.png').convert_alpha()

See also How can I make an Image with a transparent Backround in Pygame?

Leave a Comment