Game Development Reference
In-Depth Information
SNESController controller = new SNESController(this);
controller.setListener(this);
findViewById(R.id.snes).setVisibility(View.VISIBLE);
mNavMethod = eNavMethod.PANEL;
It defines the method isPortrait() to query the orientation of the device:
public boolean isPortrait() {
return getWindowManager().getDefaultDisplay().getOrientation() == 0;
}
• It defines a method to set the size of the video buffer (using the ImageView
reference mView ) and its layout parameters:
private void setImageSize(int w, int h) {
LayoutParams lp = mView.getLayoutParams();
lp.width = w;
lp.height = h;
}
Creating the Wolf 3D Main Menu
The main menu in Wolf3D is implemented by overriding two methods: onCreateOptionsMenu and
onOptionsItemSelected (see Listing 6-3). onCreateOptionsMenu is used to add menu options that will be
displayed when the user presses the menu key on the device. Wolf3D has three options:
Toggle Screen : This option toggles the screen size between 320
×
320 pixels and 480
×
320 (full screen). It works in landscape mode only.
Navigation : This option displays the navigation method dialog. This dialog lets the
user select between keyboard navigation and a game pad controller (useful for
keyboardless phones).
Exit : This option terminates the game.
The next method ( onOptionsItemSelected ) fires when the user selects an option from the menu.
This method receives a MenuItem ; using the item's menu ID (obtained by calling item.getItemId() ), the
method can proceed appropriately. Thus when the menu ID is 0, the screen size is toggled. When it is 1,
the navigation method dialog is display. When it is 2, the game is terminated. Figure 6-3 shows the main
menu of Wolf 3D plus the navigation method dialog in action.
Listing 6-3. The Main Menu for Wolf 3D (from WolfLauncher.java).
/**
* Menu
*/
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
menu.add(0, 0, 0, "Toggle Screen").setIcon(R.drawable.view);
menu.add(0, 1, 1, "Navigation").setIcon(R.drawable.nav);
Search WWH ::




Custom Search