3D Game Programming All in One (Course Technology PTR Game Development Series)
In the following chapter, and in later chapters, we will be using audio features a great deal more, so take the time in the balance of this chapter to add some more files to your sample program.
First, copy your Emaga6 directory and name the copy "koob". Or use any other name— but I'll be using koob.
Now create a new directory: C:\koob\control\data\sound. Record a sound, any sound, in a WAV file. Make sure that the file is not a stereo file. Copy your new sound file into C:\koob\control\data\sound and name it "
Next create a new script file: C:\koob\control\client\misc\sndprofiles.cs. Insert the following lines of code:
// Channel assignments (channel 0 is unused in-game). $GuiAudioType = 1; $SimAudioType = 2; $MessageAudioType = 3; new AudioDescription(AudioGui) { volume = 1.0; isLooping= false; is3D = false; type = $GuiAudioType; }; new AudioDescription(AudioMessage) { volume = 1.0; isLooping= false; is3D = false; type = $MessageAudioType; }; new AudioProfile(AudioButtonOver) { filename = "~/data/sound/buttonOver.wav"; description = "AudioGui"; preload = true; };
This sets up some datablocks and a profile for use on our client.
Next create a new script file: C:\koob\control\server\misc\sndprofiles.cs. Insert the following lines of code:
datablock AudioDescription(AudioDefault3d) { volume = 1.0; isLooping= false; is3D = true; ReferenceDistance= 20.0; MaxDistance= 100.0; type = $SimAudioType; }; datablock AudioDescription(AudioClose3d) { volume = 1.0; isLooping= false; is3D = true; ReferenceDistance= 10.0; MaxDistance= 60.0; type = $SimAudioType; }; datablock AudioDescription(AudioClosest3d) { volume = 1.0; isLooping= false; is3D = true; ReferenceDistance= 5.0; MaxDistance= 30.0; type = $SimAudioType; }; // Looping sounds datablock AudioDescription(AudioDefaultLooping3d) { volume = 1.0; isLooping= true; is3D = true; ReferenceDistance= 20.0; MaxDistance= 100.0; type = $SimAudioType; }; datablock AudioDescription(AudioCloseLooping3d) { volume = 1.0; isLooping= true; is3D = true; ReferenceDistance= 10.0; MaxDistance= 50.0; type = $SimAudioType; }; datablock AudioDescription(AudioClosestLooping3d) { volume = 1.0; isLooping= true; is3D = true; ReferenceDistance= 5.0; MaxDistance= 30.0; type = $SimAudioType; }; // Used for non-looping environmental sounds (like power on, power off) datablock AudioDescription(Audio2D) { volume = 1.0; isLooping = false; is3D = false; type = $SimAudioType; }; datablock AudioDescription(AudioLooping2D) { volume = 1.0; isLooping = true; is3D = false; type = $SimAudioType; };
All of this sets up some datablocks for the server—we will use them in the next chapter. I include them here for you to peruse within the context of what we've covered in this chapter. For practice, you can try various calls to alxPlay and create some profiles that use these descriptions.
Категории