Download and unzip the zip file and you will see an ExampleProgram folder. Open the ExampleProgram
folder, the EXE folder contains the compiled program and you can double click on the .sln
file to work with the source code.
If you double click and run the executable program, you will observe:
This application is identical in all ways to that from the third tutorial except
in this case a soft background music and audio cues can be heard when significant events happen (e.g.,
soccer ball collide with window boundary). In this tutorial, we will examine the
details of working with audio cues. We will first examine our source code file
structure, and then describe how to create wave files to be included in our projects
as audio cues.
2. The Source Code Files/Structure
Take a look at the
folder that you have unzipped and
you will see a structure almost identical to that of previous tutorial. The only
notable difference is a new
subfolder in the
files are the source of the audio cues.
3. The Solution Explorer:
Now double click on the
file in the
folder, to start the
project in the IDE. Notice the structure of the
follows the source code folder structure we have examined:
As illustrated in the above figure, you will notice the
and the collection of *.wav files. The process of including the *.wav files into
the project works identical to that of *.jpg Texture files, where you would
right-mouse-button click on the
folder and add the existing
folder. Any *.wav files can be included in this folder (and thus into
your project). For example the
Left.wav and Right.wav files are recorded
words of "Left" and "Right" from the Microsoft Audio Recording utility software.
functions, the cueName
refers to names of these *.wav files. Notice that as in the case of jpg image
files where we identify the images by their names
In this case, we will also refer the audio cues by their file names
the .wav extension.
Limited audio bank support
: We have a very simple audio support
where you can only play up to 8 audio cues at the same time.
3d. Hints on working with Audio Cues:
Our simple audio architecture support means we have limited audio resources to
work with. We should use this resource carefully and strategically to maximize support for feedback to
our users (students).
Use it as a hint to events
: Use audio cues to
inform users that something has happened (e.g., the soccer ball has touched
the window boundary).
Use one cue at a time
: it can be confusing to the user when more
than one cues are playing at the same time, i.e., be mindful when calling
more than once during a single
function. For example, in your application a hero is walking and encountered
a gold nugget during the UpdateWorld() function. It may be your desired to play a cue
to represent the hero walking, and a separate cue to represent the encountering of
the gold nugget. In this case, you should weigh the importance and
probably only play one of the cues.
Use shorter cues rather than longer cues:
The audio support will
honor the requested duration of a cue even if the cue span multiple
UpdateWorld() functions. This means, if you start a
five minute audio effect, within this five minutes interval other audio effects will be
mixed and can cause confusion. In general multiple short audio snippets corresponding to significant events is much more informative than one
significant audio segment representing one of the significant events. For example, if
five collisions occurred over a period of one seconds. In this case it is much more informative for the user to hear
five distinct audio cues (each can be 0.1 seconds in length), than for the user to hear a single one-second audio segment that accurately represents one of the
five collisions. With our simple library support, each of your audio cues should probably be less than
4. Examine the Game1.cs source file:
We are finally ready to examine our source code playing of the cues. In this case, when comparing to the source code from the third tutorial, no new instance
variables are necessary and no extra code is necessary in the
function. We simple call
in the beginning and call
funciton in the
function when "
" events occur:
A. Update the Rotating ladder
Update the soccer ball, make sure it bounces off the window bounds
collideStatus = CollideWorldBound(m_SoccerBall);
please refer to the source file for the rest of the