Android Gamepad Support

I'm trying to add gamepad support to my game, but I can't find anywhere else to get movement events from the gamepad joystick.

I have something like this, but it never seems to have called or done anything. I am testing XOOM with JellyBean and my gamepad works for menu navigation.

@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 switch to reading axis data from a gamepad?

+4
source share
1 answer

I was able to make it work. I had to add these lines to the initialization of my view.

  setFocusable(true); setFocusableInTouchMode(true); 

After that I received function calls.

+5
source

All Articles