Game Development Reference
In-Depth Information
Event listener : Any class that wishes to receive controller events must implement
the ControllerListener interface. This interface provides the callbacks to handle
button presses:
public interface ControllerListener {
public void ControllerUp(int btnCode);
public void ControllerDown(int btnCode);
}
Listing 6-10. The Controller Class SNESController.java.
package game.controller;
// ...
public class SNESController {
private Activity mView;
private ControllerListener mListener;
public SNESController(Context context) {
mView = (Activity) context;
init();
}
public SNESController(Context context, AttributeSet attrs) {
mView = (Activity) context;
init();
}
public SNESController(Context context, AttributeSet attrs, int style) {
mView = (Activity) context;
init();
}
public void setListener(ControllerListener l) {
mListener = l;
}
private void init() {
setupControls();
}
private void setupControls() {
// up
mView.findViewById(R.id.btn_up).setOnTouchListener(
new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent evt) {
final ImageButton b = (ImageButton) v;
Search WWH ::




Custom Search