【发布时间】:2015-03-02 16:55:27
【问题描述】:
我需要进行控制,但我遇到了多点触控问题。
这个概念很简单:
- 如果用户触摸左侧(屏幕的一半),船会向左移动
- 如果用户触摸右侧(屏幕的一半),船会向右移动。
当用户执行以下操作时会出现问题:
- 将手指放在左侧
- 不移开左手指,将手指放在右侧
- 移开左手指
- 再放左手指(我的代码无法识别,有问题)
我想要一个仅获取屏幕中最后一个手指的“X”位置的代码
我的实际代码:
@Override
public boolean onTouchEvent(MotionEvent event)
{
int index = MotionEventCompat.getPointerCount(event) - 1;
float x = (int) MotionEventCompat.getX(event, index);
@SuppressWarnings("deprecation")
int ancho = AEngine.display.getWidth();
switch (MotionEventCompat.getActionMasked(event))
{
case MotionEvent.ACTION_DOWN:
if (gameView != null)
gameView.touchNave(x, ancho);
break;
case MotionEvent.ACTION_POINTER_DOWN:
if (gameView != null)
gameView.touchNave(x, ancho);
break;
case MotionEvent.ACTION_MOVE:
if (gameView != null)
gameView.touchNave(x, ancho);
break;
case MotionEvent.ACTION_UP:
Nave.estado = AEngine.NAVE_STAY;
break;
case MotionEvent.ACTION_POINTER_UP:
Nave.estado = AEngine.NAVE_STAY;
break;
}
return false;
}
【问题讨论】:
标签: java android multi-touch motionevent