8. Working with Audio Effects
back to Tutorial main page
References:
Goals: In this tutorial we want to experience:
- Working with audio effects!
Library function to notice:
Implementation:
-
Including aduio resources: Under the Solution Explorer, open the
Content tab,
- Right-mouse-click on the Resources folder:
-
Now, go to Explore (the XP file navigation tool)
- navigate to root folder of this tutorial
and to: 9.AudiEffect/AudioFiles
-
In this folder you will find:
| GameAudio.xap |
Microsoft Cross-Platform Audio Creation Tool (XACT) data file.
This is the file we will include into our project for all the
sound cues. |
| BallDie.wav |
Defines: BallDie audio cue. We will use this cue to
indicate a ball has expired. |
| Bounce.wav |
Defines: Bounce audio cue. We will use this cue to
indicate when the ball bounce off the paddle. |
| Break.wav |
Defines: Break audio cue. We will use this cue to
indicate when a block is broken. |
| Wall.wav |
Defines: Wall audio cue. We will use this cue to
indicate when the wall bounces off the wall. |
- While still in Explore copy all of the above files to
your newly create subfolder:
SourceCode/SimpleXNA/Contrent/Resources/Audio
NOTE: Perform the copy operation in the Explore and
not the IDE.
- Now go back to the IDE:
- Right-Mouse-Click over the
Resources/Audio subfolder
- "Add" ... "Existing Itme"
: select
the XACT data file: GameAudio.xap this data file
contains all the proper description of the above audio cues.
- Now, we are ready to use the above cues in our project.
- Bounce cue:
- Paddle.cs::BounceBall: Upon
detecting successful paddle-ball intersection, add in the following
line:
-
XnaAssignmentBase
.PlayACue(0.2f,
"Bounce");
- The above line says, play the "NewBall" cue for 0.5 second.
- Break cue:
- Paddle.cs::BounceBall: Upon
detecting successful paddle-ball intersection, add in the following
line:
- Wall and BallDie cues:
- Ball.cs::Update: When detecting
the ball is colliding with the wall and falls below the application
window.
Lesson Learned:
Please refer to the
library documentation for more details on working with audio effects.
The most important point to repeat here is, we only have one output channel, and
thus we should use audio as a cue when an event happens
(bouncing). Working with the XnaAssignmentBase library, we cannot have a
constant music playing in the background.
This document and the related materials are developed with support from
Microsoft Research Computer Gaming Initiative under the Computer Gaming
Curriculum in Computer Science RFP, Award Number 15871.