Game Development Reference
In-Depth Information
android:layout_margin="0px"
android:src="@drawable/snes_x0"
android:layout_y="63px" android:layout_x="223px"/>
<ImageButton android:id="@+id/btn_Y"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#00000000"
android:layout_margin="0px"
android:src="@drawable/snes_y0"
android:layout_x="174px" android:layout_y="99px"/>
<!-- A/B -->
<ImageButton android:id="@+id/btn_A"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#00000000"
android:layout_margin="0px"
android:src="@drawable/snes_a0"
android:layout_y="99px" android:layout_x="267px"/>
<ImageButton android:id="@+id/btn_B"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#00000000"
android:layout_margin="0px"
android:src="@drawable/snes_b0"
android:layout_x="223px" android:layout_y="141px"/>
</AbsoluteLayout>
Controller Class
The controller is constructed by the class SNESController (see Listing 6-10). Some of the key aspects of
this class follow:
Constructor : The class requires an Android context that contains the layout XML
for the controller and is used for initialization.
Initialization : In this step, touch events for the buttons are set up by querying the
main activity for a button ID and setting a touch listener:
mView.findViewById(BUTTON_ID).setOnTouchListener(
new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent evt) {
}
}
Key presses : Depending on the action type, DOWN or UP , a key is sent to the listener
using sendEvent(EVENT_TYPE, ANDROID_KEY) .
Search WWH ::




Custom Search