我一直在玩游戏,我正在尝试制作控制器,没什么太复杂的,为此我需要跟踪 2 个输入(手指):1 开火按钮和移动键。(上、下、左、正确的)
这就是问题所在:手指 1 向下,手指 2 向下,手指 1 向上认为它是 2,然后手指 2 向上认为它是 1。
D/Controlls(18849): Action Down 1
D/Controlls(18849): Coordinates 267.7908 415.24274
D/Controlls(18849): Action Pointer Down 2
D/Controlls(18849): Coordinates 281.11423 417.23993
D/Controlls(18849): Action Pointer UP 1
D/Controlls(18849): Coordinates 272.7869 419.23718
D/Controlls(18849): Action UP 2
D/Controlls(18849): Coordinates 1148.103 439.20947
这是处理 2 个输入的 OnTouchEvent 的代码:
@Override
public boolean onTouchEvent(MotionEvent event) {
int index = event.getActionIndex();
int pointerId = event.getPointerId(index);
int action = event.getActionMasked();
int oldX, oldY;
switch (event.getAction() & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_DOWN:
{
hero.moveControlls((int)event.getX(), (int)event.getY());
Log.d("Controlls", "Action Down "+ pointerId);
Log.d("Controlls", "Coordinates "+ event.getX() + " "+ event.getY());
break;
}
case MotionEvent.ACTION_UP:
{
hero.setScreenTouching(false);
Log.d("Controlls", "Action UP "+ pointerId);
Log.d("Controlls", "Coordinates "+ event.getX() + " "+ event.getY());
break;
}
case MotionEvent.ACTION_POINTER_DOWN:
{
Log.d("Controlls", "Action Pointer Down "+ pointerId);
Log.d("Controlls", "Coordinates "+ event.getX() + " "+ event.getY());
break;
}
case MotionEvent.ACTION_POINTER_UP:
{
Log.d("Controlls", "Action Pointer UP "+ pointerId);
Log.d("Controlls", "Coordinates "+ event.getX() + " "+ event.getY());
break;
}
}
return true;
}
现在,我查看了示例,但无法理解它们。我在 API 中查找了 MotionEvent,它说要使用 $ACTION_POINTER_INDEX_SHIFT$,我不知道如何使用,因为他们没有示例或其他东西可以使其更容易理解。有关如何执行此操作的任何帮助?