Audio is an important part of making a game. You can have the best visuals in the world, the best mechanics, but something is missing – it’s audio! In this chapter we take a look at playing one-off sounds such as explosions or effects as well as music.
© Sloan Kelly 2019
Sloan KellyPython, PyGame, and Raspberry Pi Game Developmenthttps://doi.org/10.1007/978-1-4842-4533-0_1818. Audio
Sloan Kelly1
(1)
Niagara Falls, ON, Canada
Sounds are played using PyGame’s built-in mixer object. Like, PyGame, you must first initialize the sound mixer before using it.
pygame.mixer.init()
Likewise, when you stop using the sound mixer, you should shut it down gracefully by calling the quit method:
pygame.mixer.quit()
You can check to see if the mixer is playing ...
Get Python, PyGame, and Raspberry Pi Game Development now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.