Audio/Music
From TDN
|
Introduction
The following has been taken largly from the In-game music article by Matt Webster. It has been slightly tweaked and updated for the purpose of this document.
Setup
The sound file
So you got that cool music you made from your pots and pans at home, or some cool remix of your favorite Backstreet Boys song? Good!
For organization's sake, I put my music files in a seperate folder. I use .wav files for my music, but this works just fine with the Ogg Vorbis code which can be found here Thanks Kurtis Seebaldt!
As for the seperate folder, this tutorial assumes you're putting the music files in the "music" folder.
/data/sound/music
Audio description
Now you have to make a description for the music.
The description contains simple details like the standard volume, looping, 3d sound, and audio type.
First, you should (not required) add a new channel type for music. It's easier to keep things seperate, so...
In client\scripts\audioProfiles.cs add:
$MusicAudioType = 3; to the existing channel list
like:
$DefaultAudioType = 0; $GuiAudioType = 1; $SimAudioType = 2; $MusicAudioType = 3;
Then, add the actual audio description in the same file:
new AudioDescription(MusicLooping)
{
volume = 2.0;
isLooping= true;
is3D = false;
type = $MusicAudioType;
};
Audio profile
The audio profile contains the information specific to the sound file. Place this in the same file (audioprofile.cs) as the code in previous sections:
new AudioProfile(Music_MainMenu)
{
filename = "~/data/sound/music/music.wav";
description = "MusicLooping";
preload = true;
};
In this case, the audio profile's name is "Music_MainMenu". I did this just so it's easy to read, but you can use anything as long as you remember it!
Preload allows you to load the music up when the program is started. This will make the game run smoother since the song file is already loaded. I recommend setting this to true.
Playing the music
Now if you want to play the music (which I assume you do, otherwise reading this would just be weird) just add:
$musicHandle = alxPlay(Music_MainMenu);
Edit by Stephen Lujan 4/01/07:
Adding the music to loadMainMenu() will only play music when the menu first loads, not when it is returned to.
Instead add this function to to client\init.cs or create a new mainmenugui.cs and execute it in client\init.cs
function MainMenuGui::onWake(%this)
{
// Play music...
$musicHandle = alxPlay(Music_MainMenu);
}
That will play the music file to loop constantly when the main menu is loaded up.
Now, $musicHandle is your handle to adjust that sound later on (like when we have to turn it off).
Make it stop, oh PLEASE make it stop!
To turn it off (which you'll want to do once you go into a mission)
in client\mission.cs put:
alxStop($musicHandle);
in the function clientCmdMissionStart, like this:
function clientCmdMissionStart(%seq)
{
alxStop($musicHandle);
// The client recieves a mission start right before
// being dropped into the game.
}
Notes
Other method of shutting off the music are discussed in the talks and comments of the resource post. They will be updated here later.
Categories: Audio | TGE | Tutorial



