5.4 Conclusion
Here are some key points about what we learned in this last chapter:
- Sounds are short audio effects that may be played as a result of something happening in a game. For example, if a character jumped in a game, there may be a stomping sound. In pygame, you can load a sound from a file by doing
sound = pygame.mixer.Sound("sound.wav")
, and you can play the sound by doingsound.play()
.
- Music is long audio that may be played in the background of a game. This is like the piano soundtracks in the popular game called Minecraft. In pygame, you can load music from a file by doing
pygame.mixer.music.load("jazz.wav")
, and you can play the music by doingpygame.mixer.music.play(-1)
. The number in the parenthesis determines how long the music is played.
Previous Section
5.3 - Practice ProblemsCopyright © 2021 Code 4 Tomorrow. All rights reserved.
The code in this course is licensed under the MIT License.
If you would like to use content from any of our courses, you must obtain our explicit written permission and provide credit. Please contact classes@code4tomorrow.org for inquiries.