Game Development Reference
In-Depth Information
if (mSound && mAudioMgr == null)
Log.e(TAG, "Bug: Audio Mgr is NULL but sound is enabled!");
try {
if (mSound && mAudioMgr != null)
mAudioMgr.startSound(idx);
} catch (Exception e) {
Log.e(TAG, "OnStartSound: " + e.toString());
}
}
public void OnStartMusic(int idx) {
if (mSound && mAudioMgr == null)
Log.e(TAG, "Bug: Audio Mgr is NULL but sound is enabled!");
try {
if (mSound && mAudioMgr != null)
mAudioMgr.startMusic(this, idx);
} catch (Exception e) {
Log.e(TAG, "OnStartSound: " + e.toString());
}
}
Creating Movement Controller Handlers
Listing 6-8 shows the section of the main activity that handles the movement controller events. The
movement controller is an SNES-style display (see Figure 6-4),which provides navigation capabilities for
phones without a keyboard. The controller itself consists of a series of drawable resources and controller
classes (see “Creating Movement Controller Classes”), which fire the following events whenever the user
presses any of its buttons:
ControllerDown(int btnCode) : This event fires when the user presses any button
in the controller. btnCode represents the Android key code defined in the KeyEvent
class.
ControllerUp(int btnCode) : This event fires when the user releases a button in the
controller. It will always fire after ControllerDown .
As Listing 6-8 shows, the controller buttons are mapped in the following way:
Y : Strafe (or step) left
X : Strafe right
B : Fire
A : Enable running
Search WWH ::




Custom Search