Lesson 4 - Time and Sound
This tutorial will cover how to add sound effects and keep track of time in a Monogame program.
Lesson 4 - Time and Sound
What to Do?
1 - Complete the tutorial on Time and Sound.
Text version, or follow along in class.
Github tutorial solution: https://github.com/AldworthClass/Monogame-4---Sounds-and-Time
Link to adding sounds using the MGCB Tool: https://sites.google.com/gotvdsb.ca/aldworth/monogame/tutorials/sounds-in-monogame
Click here for a visual representation of how tracking time works.
Tutorial on how to play sounds: http://rbwhitaker.wikidot.com/playing-sound-effects
Look at SoundEffectInstance for more control over playing sounds.
2 - Complete the Your Task programming component of the tutorial along with any challenges that you can complete. Complete the Your Task 2 component as well.
3 - Try some of the challenges laid out in the tutorial or something of your own.
Count down instead of up.
Change timer from 10 to 15 seconds
If the bomb explodes, display an image of an explosion.
If the bomb explodes, quit the program after the sound effect completes.
Allow the user to reset or stop the timer by clicking on the red wire.
By the end of this you should know:
How to keep track of elapsed time in a program.
How to add and play sound effects in a program.
What to Submit:
1 - The completed programming task described in the tutorial, along with any completed challenges.
Lesson Tutorial - Time and Sound
Here is the image file used in the tutorial:
You will also need to download the sound effects found at the bottom of this page.
Files
You will need explosion.wav for this tutorial, and tribble_coo.mp3 to add to Animations
Time Tracking Visual
Tips and FAQ's
Q - What is the best way for me to time events with sound effects or the end of songs?
A - You have two options listed below. Option 1 is for long sound effects like background music, but just one at a time. Option 2 is better suited to sound effects.
Option 1: If you are playing a longer sound like background Music, you can use the MediaPlayer and a Song object to play it. This gives you access to all sorts of details regarding the sound file. You can only play one sound through the media player at a time.
Here is an example program that demonstrates using the Song class and MediaPlayer:
https://github.com/AldworthClass/Monogame-Songs
Option 2: Create a SoundEffectInstance and use it to play your sound file. You can play multiple sounds at once, and determine whether a sound effect is playing or not.
Here is a good tutorial on how to use it: