Chapter 14. Adding Sound, Music, and Video

Chapter 14. Adding Sound, Music, and Video

A game needs sound, music and video. It has to offer the player attractive background music. It must also generate sounds associated with certain game events. When a spaceship shoots a laser beam, a sound must accompany this action. Reproducing videos showing high-quality previously rendered animations is a good idea during transitions between one stage and the next.

In this chapter we will add sounds, music and videos to the game. By reading this chapter and following the exercises we will learn how to:

  • Add background music to the game

  • Generate sounds associated to the game events

  • Take advantage of multiple channel audio

  • Control the reproduction of concurrent sounds

  • Organize the media elements for the game

  • Prepare our media elements for their use in Silverlight applications

  • Take advantage of Silverlight 3 performance enhancements for videos

  • Reproduce videos combined with animated projections

Hear the UFOs coming

So far, we have worked with 3D scenes showing 3D models with textures and different kinds of lights. We took advantage of C# object-oriented capabilities and we animated 3D models and moved the cameras. We have read values from many different input devices and we added physics, artificial intelligence, amazing effects, gauges, statistics, skill levels, environments, and stages. However, the game does not use the speakers at all because there is no background music and there are no in-game sounds. Thus, we have to sort this issue out. Modern games use videos to dazzle the player before starting each new stage. They use amazing sound effects and music custom prepared for the game by renowned artists. How can we add videos, music, and sounds in Silverlight?

Note

We can do this by taking advantage of the powerful multimedia classes offered by Silverlight 3. However, as a game uses more multimedia resources than other simpler applications, we must be careful to avoid including unnecessary resources in the files that must be downloaded before starting the application.