Game Development Reference
In-Depth Information
Listing 7-2. Main Activity Life Cycle
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Full screen
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
// No title
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.doom);
mView = (ImageView)findViewById(R.id.doom_iv);
if (mGameStarted) {
setGameUI();
setupPanControls();
return;
}
// Pan controls
setupPanControls();
}
onCreate is the very first function called when the game starts, and it is called only once while the
application is in memory. Next, let's look at the game layout loaded by this function.
Game Layout
GUIs in Android are defined by XML layouts, where visual components are placed in a variety of layout
schemes. Doom's layout ( doom.xml ) is a relative layout, which has widgets placed relative to each other
(meaning they can overlap depending on the widget size). The master layout contains an image view
and two table layouts.
In Android, an image view encapsulates an array of pixels representing an image. The great thing
about image views is that they have efficient automatic resize capabilities. This will allow the game to be
resized on the fly!
The two table layouts are for the navigation controls (see Figure 7-2). The first table layout defines a
three-row table that contains image buttons for up, down, left, and right navigation. The second table
layout is a one-row table that contains buttons for the level map, object pick up, and strafing left and
right.
Search WWH ::




Custom Search