Android - 支持多个游戏手柄

时间:2016-11-21 07:20:21

标签: android gamepad

在我的应用程序中,我处理带有事件的游戏手柄按钮:

public boolean onKeyDown(int keyCode, final KeyEvent event) 
public boolean onKeyUp(int keyCode, final KeyEvent event)

int button = keyCode;
boolean isDown = event.getAction() == KeyEvent.ACTION_DOWN;

和轴事件

public boolean onGenericMotionEvent(MotionEvent event)

float xaxis = event.getAxisValue(MotionEvent.AXIS_X);
float yaxis = event.getAxisValue(MotionEvent.AXIS_Y);
...

目前不依赖于连接了多少个游戏手柄,一切都像只连接一个游戏手柄一样。

对于触摸指针,每个触摸指针都很容易获取值:

MotionEvent event;
...
int index = event.getActionIndex();
int pointerID = event.getPointerId(index);
float x = event.getX(index);
float y = event.getY(index);

但是我怎样才能检测到哪个游戏手柄是按下了?BUTTON_X?以及如何检测哪个游戏手柄属于轴事件?

谢谢

0 个答案:

没有答案