游戏手柄支持Android [英] Gamepad Support Android

查看:643
本文介绍了游戏手柄支持Android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想加入游戏手柄的支持我的比赛,但我找不到任何地方如何从一个游戏手柄的摇杆获得移动事件。

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.

我有这样的事情,但它似乎永远不会被调用或做任何事情。我正在测试一个XOOM与软糖和我的作品手柄供浏览菜单。

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?

推荐答案

我能得到它的工作。我必须将这些行添加到我的观点的初始化。

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.

这篇关于游戏手柄支持Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆