【发布时间】:2011-07-22 20:23:28
【问题描述】:
我有一个 SurfaceView,我正在画一个圆圈。我知道圆的位置和半径。
我需要知道用户是否按下了圆圈。用户可能正在用一根或两根手指轻敲屏幕。如果有任何手指在圆圈区域上方,则必须按下它。
当用户将手指从屏幕上抬起,而圆圈上不再有手指时,必须停止按下圆圈。
当用户只有一根手指在屏幕上时我没有问题,但当他使用两根手指时我无法解决问题。
我遇到的问题是当我收到一个 ACTION_UP 或 ACTION_POINTER_UP 动作时,我不知道哪个指针不再出现在屏幕上,所以我不必查看它们的坐标是否在圆上。
我尝试了几次都没有成功,最后一个是:
protected boolean checkPressed(MotionEvent event) {
ColourTouchWorld w = (ColourTouchWorld)gameWorld;
int actionMasked = event.getActionMasked();
for (int i = 0; i < event.getPointerCount(); i++) {
if (i == 0 && (actionMasked == MotionEvent.ACTION_UP || actionMasked == MotionEvent.ACTION_POINTER_UP)) {
// the pointer with index 0 is no longer on screen,
// so the circle is not pressed by this pointer, even if
// it's coordinates are over the area of the circle
continue;
}
if (isPointInCicle(event.getX(i)), event.getY(i))) {
return true;
}
}
return false;
}
有什么想法吗?谢谢。
【问题讨论】:
标签: android pointers touch multi-touch