Developing Game-Themed Applications with XNA
Day 1 - Section III: The Block Breaker
Game
g. Audio Effects
back to Day-1 main page
References:
- Pre-requisite: this is the
example (Section IIIf. BlockBreaker game with texture) we are building
off from and here is the source
file we will begin working with.
- Here is the result source code for this
example.
- For details of working with audio files and the organization of the source code folder,
please refer to the
library documentation.
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:
-
Add new folder: Audio.
-
Add audio files: Right-mouse-click over the Audio folder: Add
Existing Items
-
Browse and add the following audio files (under
AudioFiles folder):
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. |
- 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:
-
XNACS1LibBase
.PlayACue("Bounce");
- The above line says, play the "Bounce" cue.
- 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 XNACS1LibBase 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, and 16531.