Gamepad Support Android

蹲街弑〆低调 提交于 2019-12-21 05:21:45

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!