Music


You can handle music in much the same way as the simple sound effect I showed you at the beginning of this chapter. A useful way to employ music is to provide a background for the different dialog boxes or menu screens in the GUI. Of course, you can also insert music into the game as AudioEmitters or even attach it to vehicles or players.

We'll take a slightly more conventional approach and put in some start-up music. First, locate the file C:\3DGPAi1\RESOURCES\CH20\TWLOGO.WAV and copy it over to C:\koob\control\data\sounds\.

Next, open the file C:\koob\control\client\misc\initialize.cs and add the following code to the top of the file:

 new AudioDescription(AudioMusic) {    volume   = 0.8;    isLooping= false;    is3D     = false;    type     = $MusicAudioType; }; new AudioProfile(AudioIntroMusicProfile) {    filename = "~/data/sound/twlogo.wav";    description = "AudioMusic";    preload = true; }; function PlayMusic(%handle) {    if (!alxIsPlaying(%handle))      alxPlay(%handle); } function StopMusic(%handle) {    if (alxIsPlaying(%handle))      alxStop(%handle); } 

Now scroll down a bit until you find this line:

    SetNetPort(0); 

Add the following after it:

    StartMusic(AudioIntroMusicProfile); 

This will start the opening music playing shortly after the first window appears once the game application has been launched.

Now open the file C:\koob\control\client\client.cs and insert the following line as the first line in the LaunchGame() function:

    StopMusic(AudioIntroMusicProfile); 

This line will ensure that if the opening music is still playing when you actually go to start the game, it will be turned off.

Now go ahead and launch the game and listen to the music.

You can use the same technique in combination with the CommandToClient(XXXX)/clientCmdXXXX system that we've used in earlier chapters to have the server trigger music cues on all or selected clients whenever you want.




3D Game Programming All in One
3D Game Programming All in One (Course Technology PTR Game Development Series)
ISBN: 159200136X
EAN: 2147483647
Year: 2006
Pages: 197

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net