Game Development Reference
In-Depth Information
Navigation Controls
Older Android devices feature a trackball, which is cumbersome for mobile games. In fact,
most gaming devices, such as PlayStation Portable (PSP) and Game Boy, feature multiple
keypad arrows, which are great for navigation. On the plus side, the QWERTY keyboard is
helpful for PC games. But the latest Android devices have neither a keyboard nor a trackball.
This is where the navigation controls can help. Figure 5-2 shows the navigation controls in
action during a game.
Figure 5-2. Navigation controls for Doom
The controls themselves are implemented as image buttons within the game layout (see the
“Game Layout” section). The RelativeLayout of the game allows the controls to overlap the
video ImageView , as shown in Figure 5-2 . To set up events for the buttons, simply load the
button widget using its ID and set a touch listener, like so:
findViewById(R.id.BUTTON_ID).setOnTouchListener(new View.OnTouchListener(){
public boolean onTouch(View v, MotionEvent evt) {
// ACTION_DOWN or ACTION_UP
int action = evt.getAction();
// ...
}
});
 
Search WWH ::




Custom Search