Game Development Reference
In-Depth Information
The
SetSFXOnOff()
function turns on or off all the sounds associated with this Object3d class.
(See Listing 6-4.)
Listing 6-4. Turning the SFX On or Off
void SetSFXOnOff(boolean Value)
{
for (int i = 0; i < m_NumberSounds;i++)
{
m_SoundEffectsOn[i] = Value;
}
}
The
AddSound()
function creates a new Sound class object from a resource
ResourceID
and the
sound pool
Pool
and adds the sound to the
m_SoundEffects
array that holds the sound effects for
this class. (See Listing 6-5.)
Listing 6-5. Creating a New Sound from a Resource
int AddSound(SoundPool Pool, int ResourceID)
{
int SoundIndex = -1;
Sound SFX = new Sound(m_Context, Pool, ResourceID);
SoundIndex = AddSound(SFX);
return SoundIndex;
}
The
PlaySound()
function plays the sound effect that is associated with the
SoundIndex
input
parameter for this class. Recall that each time a new sound is added to this Object3d class, an index
handle is returned. You must use this index handle as input to the
PlaySound()
function, if you want
to play the sound back. (See Listing 6-6.)
Listing 6-6. Playing the Sound
void PlaySound(int SoundIndex)
{
if ((SoundIndex < m_NumberSounds) &&
(m_SoundEffectsOn[SoundIndex]))
{
// Play Sound
m_SoundEffects[SoundIndex].PlaySound();
}
else
{
Log.e("OBJECT3D", "ERROR IN PLAYING SOUND, SOUNDINDEX = " + SoundIndex);
}
}