Python Programming for Raspberry Pi, Sams Teach Yourself in 24 Hours

(singke) #1

However, using .convert introduces a new problem: no transparency. In Figure 19.2, you can see
the image loaded, but there is a white rectangle around the image.


FIGURE 19.2 A loaded game image with no transparency.

To make the image transparent and allow the background images to show through, you use the
.convert_alpha() method instead, as in this example:


Click here to view code image


# Set up the Game Image Graphics
GameImage="/usr/share/raspberrypi-artwork/raspberry-pi-logo.png"
GameImageGraphic=pygame.image.load(GameImage).convert_alpha()

This allows the image to have transparency and display the background behind it. In other words, you
do not get a white box around the image on the game screen. Figure 19.3 shows the effects of using
.convert_alpha().

Free download pdf