Adding Sound, Music, and Video in 3D Game Development with Microsoft Silverlight 3: Part 1

by Gastón C. Hillar | October 2009 | Beginner's Guides Web Development Web Graphics & Video

In this article by Gastón C. Hillar we will add sounds, music and videos to the game. By reading this article 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

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.

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 eff ects and music custom prepared for the game by renowned artists. How can we add videos, music, and sounds in Silverlight?

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.

Time for action – installing tools to manipulate videos

The 3D digital artists used Blender to create an introductory video showing a high quality rendered animation for five seconds. They took advantage of Blender's animation creation features, as shown in the following screenshot:

Adding Sound, Music, and Video in 3D Game Development with Microsoft Silverlight 3: Part 1

A spaceship flies in a starry universe for a few seconds. Then, the camera navigates through the stars.

Your project manager wants you to add this video as an introduction to the game. However, as the video file is in AVI (Audio Video Interleave) format and Silverlight 3 does not support this format, you have to convert the video to an appropriate format.

The creation of video animations for a game is very complex and requires specialist skills. We are going to simplify this process by using an existing video.

First, we must download and install an additional tool that will help us in converting an existing video to the most appropriate file formats used in Silverlight 3:

The necessary tools will depend on the applications the digital artists use to create the videos. However, we will be using some tools that will work fine with our examples.

Download one of the following files:

parceApplication's name

Download link

File name

Description

Expression Encoder 2

http://www.microsoft.com/expression/try-it/try-it-v2.aspx

Encoder_Trial_en.exe

It is a commercial tool, but the trial offers a free fully functional version for 30 days. This tool will enable us to encode videos to the appropriate format to use in Silverlight 3.

Expression Encoder 3

http://www.microsoft.com/expression/try-it

Encoder_Trial_en.exe

It is the newest trial version of the aforementioned commercial tool.

  1. Run the installers and follow the steps to complete the installation wizards.
  2. If you installed Expression Encoder 2, download and install its Service Pack 1.
  3. The download link for it is http://www.microsoft.com/expression/tryit/try-it-v2.aspx#encodersp1 file name—EncoderV2SP1_en.exe.
  4. Once you have installed one of the versions of Expression Encoder, you will be able to load and encode many video files in different file formats, as shown in the following screenshot:
  5. Adding Sound, Music, and Video in 3D Game Development with Microsoft Silverlight 3: Part 1

Sign up for a Packt account to see the rest of this article

Now that you've read a few articles, you might want to consider signing up for a Packt account. It takes a matter of seconds, will give you access to all the articles on PacktPub.com, and once you've signed up you'll be returned here to carry on reading your article.

Furthermore, you'll gain access to nine free ebooks, and be offered a free trial of PacktLib, Packt's online library. Simply enter your details here, or log in to your existing account.

Log in

...or register

Post new comment

Awards Voting Nominations Previous Winners
Judges Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software
Resources
Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software
Sort A-Z