问题
I am trying to add gamepad support to my game but I can't find anywhere how to get the motion events from a gamepad's joysticks.
I have something like this but it never seems to get called or do anything. I am testing on a XOOM with JellyBean and my gamepad works for navigating around the menus.
@Override
public boolean onGenericMotionEvent(MotionEvent e) {
if ((e.getDevice().getSources() & InputDevice.SOURCE_CLASS_JOYSTICK) != 0) {
float x = e.getX();
float y = e.getY();
mJoy1.set(x, y);
mJoy2.set(-1,1);
mRenderer.onAxisMoved(mJoy1, mJoy2);
return true;
}
return false;
}
How do I go about reading the axis data from the gamepad?
回答1:
I was able to get it to work. I had to add these lines to the initialization of my view.
setFocusable(true);
setFocusableInTouchMode(true);
After that I was getting the function calls.
来源:https://stackoverflow.com/questions/12123297/gamepad-support-android