Game Development Reference
In-Depth Information
Chapter 6
Game Environment
In this chapter, I will cover the game environment. I start off by covering the creation of sound
on Android. I cover our custom Sound class and then modifications we will need to make to
other class objects to integrate sounds into them. I then go through a hands-on example in
which we play explosion sounds when two cubes collide with each other. I then cover how to
create a heads-up display, or HUD. The new classes needed to implement the HUD are covered,
followed by a case study in which a heads-up display is created for a game. Next, I cover saving
and loading data and show how you can add code into your classes to save and load class
data. Finally, I discuss a hands-on example in which we modify our case study to preserve the
HUD item data and the orientation and physics state of the two cubes that are colliding with
each other.
Overview of Sounds on Android
In this section, I discuss the Sound class and other changes in the Object3d class that have to be
made in order to add sounds to our 3D objects.
The Sound Class
The Sound class uses the existing Android SoundPool class to play and manage sounds.
A reference to the existing SoundPool object that holds the main pool of sounds is held in
m_SoundPool .
private SoundPool m_SoundPool;
The index to the specific sound in the sound pool is held in m_SoundIndex .
private int m_SoundIndex = -1;
The Sound constructor creates a new sound. The sound is loaded from the resource ResourceID
into the SoundPool object Pool . An index is returned to the newly created sound within this sound
pool. (See Listing 6-1.)
183
 
Search WWH ::




Custom Search