Game Development Reference
In-Depth Information
loop loop mode (0 = no loop, -1 = loop forever)
rate playback rate (1.0 = normal playback, range 0.5 to 2.0)
*
*/
m_SoundPool.play(m_SoundIndex, m_LeftVolume, m_RightVolume, m_Priority, m_Loop, m_Rate);
}
Modifying the Object3d Class
Next, the Object3d class has to be modified to use our new Sound class.
First, new sound-related variables have to be added.
The maximum number of sounds for a single Object3d class is held in MAX_SOUNDS .
private int MAX_SOUNDS = 5;
The current number of sounds available is held in m_NumberSounds .
private int m_NumberSounds = 0;
The sound effects are actually held in the array m_SoundEffects , and each element is of type Sound.
Refer to “The Sound Class” section (preceding) for more information on the Sound class.
private Sound[] m_SoundEffects = new Sound[MAX_SOUNDS];
The m_SoundEffectsOn array holds booleans that allow you to turn the sound effects on or off.
private boolean[] m_SoundEffectsOn = new boolean[MAX_SOUNDS];
The AddSound() function adds a Sound object to the m_SoundEffects array at the next available
slot. The slot number the object is stored in is returned if the operation is successful. If there are no
available slots, a -1 is returned. (See Listing 6-3.)
Listing 6-3. Adding a Sound Object
int AddSound(Sound iSound)
{
int Index = m_NumberSounds;
if (m_NumberSounds >= MAX_SOUNDS)
{
return -1;
}
m_SoundEffects[Index] = iSound;
m_NumberSounds++;
return Index;
}
 
Search WWH ::




Custom Search