Game Development Reference
In-Depth Information
m_SoundPool = new SoundPool(maxStreams, streamType, srcQuality);
if (m_SoundPool == null)
{
Log.e("RENDERER " , "m_SoundPool creation
failure!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
}
}
The CreateSound() function creates and adds a sound to our cubes, using as input the sound pool
and the resource id of the specific sound effect. The sound effects for each cube are also turned on.
(See Listing 6-8.)
Listing 6-8. Creating the Sounds for Our Cubes
void CreateSound(Context iContext)
{
m_SoundIndex1 = m_Cube.AddSound(m_SoundPool, R.raw.explosion2);
m_Cube.SetSFXOnOff(m_SFXOn);
m_SoundIndex2 = m_Cube2.AddSound(m_SoundPool, R.raw.explosion5);
m_Cube2.SetSFXOnOff(m_SFXOn);
}
We create the sound pool and the sound effects for each of the cubes by calling CreateSoundPool()
and CreateSound() from the onSurfaceCreated() function, which is called when our OpenGL surface
is created. (See Listing 6-9.)
Listing 6-9. Creating the Sound Pool and Sound Effects for Our Cubes
@Override
public void onSurfaceCreated(GL10 unused, EGLConfig config)
{
m_PointLight = new PointLight(m_Context);
SetupLights();
// Create a 3d Cube
CreateCube(m_Context);
// Create a Second Cube
CreateCube2(m_Context);
// Create a new gravity grid
CreateGrid(m_Context);
// Create SFX
CreateSoundPool();
CreateSound(m_Context);
}
 
Search WWH ::




Custom Search