Adding Audio Files to a Silverlight project
Setting values of a Collision behavior to audio
Venture into Gaming Using Expression Blend: Module 9
Adding Audio Resources to a Silverlight Game
Audio and sound effects are key elements in almost every game. Adding audio files to Expression Blend is straightforward and linking these audio files to specific events in the game is also very easy, especially when you are relying on Behaviors as we are here. For more information on Behaviors and how they work, refer to the module named “Adding and Applying Behaviors”.
Overview of Adding Audio to your Silverlight project
In this module you will import a number of sound files and link these sound files to the following game events: the ball hitting the paddle, the ball hitting a honeycomb, the ball hitting one of the walls.
Adding the Sound of the Ball Hitting the Paddle
Open the BeeHive Solution file in Blend, then right-click the Beehive Silverlight project and choose Add Existing Item.
Within the Beehive folder associated with this module, locate the Audio folder, then open it and select the paddle.mp3 file. Press OK to add it to your project.
Locate the Paddle object in the Objects and Timeline panel and click the arrow to the left to expand it. Nested within are two behaviors as well as the path and image of the paddle. Select the Collision behavior. This is the code that that defines what happens when something hits the user’s paddle. You will now set the properties so that the paddle.mp3 file plays each time the paddle is hit.
Click the Properties tab if necessary, then locate the Collision Properties section. Click the Audio Menu and scroll through the list until you find paddle.mp3. Select this option, then press F5 to test your game.
When the game starts, you will hear the paddle sound play every time the ball hits. Close your browser and now you’ll add the rest of the sounds.