Game Development Reference
In-Depth Information
Because of all these extras that are added to the code, in combination with
the lack of code optimization, the resulting application will not be that effi-
cient. The debug configuration is, therefore, mainly useful for the developers.
When you actually want to release your game to the public, you should use
the release configuration to build the game. In this configuration, the com-
piler tries to optimize the code in order to make it more efficient. Also, there
is no debugging information in the executable, resulting in a smaller file. In
the Visual Studio development environment, you can choose which configu-
ration you want to build by selecting it in the menu. If you want, you can even
design your own configurations with different compiler settings. A common
configuration you might want to add is optimized debug . This configuration
performs all the code optimizations but still contains debugging information.
This way, you can check whether the optimizations that the compiler performs
have somehow introduced new bugs.
Once you are sure that the release version of your game works as intended.
You can publish your game by building an installer. By right-clicking on the
project and selecting 'Publish', you can create an installer for your game.
18.5 Adding Music and Sound Effects
Just like in the Painter game, we would like to add music and sound effects to the
game to make it more attractive. Since we now made this nice AssetManager class,
let us extend it with some functionality to play music and sound effects. We are
going to do this similar to the way that we deal with sprites in that class. First, we
add a PlaySound method that plays a sound effect:
public void PlaySound( string assetName)
{
SoundEffect snd = contentManager.Load<SoundEffect>(assetName);
snd.Play();
}
So, let us declare two Dictionary member variables, one for music, and one for sound
effects:
protected Dictionary< string , SoundEffect> sounds;
protected Dictionary< string , Song> music;
The PlayMusic method has an additional parameter that indicates if the music should
be repeated or not. The method is then given as follows:
Search WWH ::




Custom Search