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

(singke) #1
FIGURE 19.3 A loaded game image with transparency.

Once your image is loaded, you simply display it to the screen by using the Surface object and the
same method you use for text: .blit. The following is an example of this:


Click here to view code image


#
GameScreen.blit(GameImageGraphic,(300,0))

Just as with text, the variable representing the image is passed to the .blit method, along with
where on the Surface object you would like the image to be displayed: (width, height).
However, the game screen still does not show this image! To have the game screen redrawn,
remember that you need to use pygame.display.update().


To review, you use .blit for the game screen background, you use .blit for the text and images (or
shapes) on the screen, and then you update the game screen.


Putting Sound into the Game


Now that you have text and graphics, it’s time to learn how to add sound to your Python game script.
The PyGame library makes adding sounds to a game very easy.

Free download pdf