Game Development Reference
In-Depth Information
Main Activity Layout
The activity layout defines the main user interface. Wolf 3D has a simple UI: an image view that displays
the video buffer sent by the DSO and the controller layout explained in the “Movement Controller”
section.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<!-- GAME IMAGE -->
<ImageView android:id="@+id/wolf_iv"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:focusableInTouchMode="true"
android:focusable="true"
android:layout_centerHorizontal="true"
android:layout_centerVertical="false"/>
<!-- Controller XML removed -->
</RelativeLayout>
Main Activity Class (WolfLauncher)
Here is where all the meat resides. When this class starts, the method onCreate executes performs several
actions. First, it sets the window manager to full screen with:
getWindow().setFlags(
WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
Next, it sets the content view XML for the application using R.layout.wolf . This represents the
application layout XML containing the game image view and the controller components. It also keeps a
reference to the image view representing the video buffer ( R.id.wolf_iv ):
setContentView(R.layout.wolf);
mView = (ImageView) findViewById(R.id.wolf_iv);
It then initializes the movement controller with initController .
Finally, it starts the game using the base folder (the folder that contains the game files), the game ID
(Wolf 3D), and a Boolean value indicating if portrait or landscape mode should be used:
startGame(mGameDir, WolfTools.GAME_ID, true) .
Listing 6-2 shows the first part of WolfLauncher.java with the methods onCreate and intController .
Listing 6-2. The First Section of the Wolf 3D Main Activity WolLauncher.java
package game.wolfsw;
public class WolfLauncher extends Activity
Search WWH ::




Custom Search