Game Development Reference
In-Depth Information
Figure 6-5. The game controller
Controller Layout
The controller UI is defined by an absolute layout XML (see Listing 6-9) within the main layout file
( wolf.xml ). All buttons are placed on screen using absolute X and Y coordinates, where the upper left
corner of the screen represents (0,0). For this reason, this controller will only work in portrait mode (it is
too big for landscape at 480 ×320). Figure 6-4 shows the background image for the controller. On top of
this image the following image buttons are placed:
Arrows for up, down, left, and right buttons
Select and start
X, Y, A, and B buttons
Drawable resources are defined using the XML android:background="@drawable/IMAGE_NAME" , where
IMAGE_NAME must exist in the res folder within the project.
Listing 6-9. Movement Controller Layout
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/snes"
android:orientation="vertical"
android:layout_width="320px"
android:layout_height="240px"
android:background="@drawable/snes"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:focusable="false"
android:focusableInTouchMode="false"
android:visibility="gone"
>
<!-- Arrows -->
<ImageButton android:id="@+id/btn_up"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Search WWH ::




Custom Search