这是我的代码的一部分。我不明白为什么MotionEvent.ACTION_POINTER_DOWN
没有检测到(第二根手指触摸屏幕)。有人可以解释为什么这不起作用吗?
单人游戏很好用。两个播放器(多点触控)不是。
什么对两个玩家有效 - 当用户只按下屏幕的任一半时,它会调用goUp()
什么对两个玩家不起作用 - 当用户按下屏幕的一半,然后按下另一半时,另一半不调用goUp()
另外,有没有办法在模拟器上一次模拟多个触摸,这样我就可以看到log
s 中的 s 了logcat
吗?
private int pointerId = -1, pointerId2 = -1;
@Override
public boolean onTouch(View view, MotionEvent event) {
// Depending on the touch, depends on the direction of the ricer (up or down)
if(!TWO_PLAYER_MODE){
switch (event.getActionMasked()) {
// When finger touches the screen, ricer will accelerate up
case MotionEvent.ACTION_DOWN:
ricerView.goUp();
break;
// When finger is lifted from the screen, ricer will accelerate down
case MotionEvent.ACTION_UP:
ricerView.goDown();
}
}
else{
float touchY = event.getY();
int pointerIndex = event.getActionIndex();
int pointerID = event.getPointerId(pointerIndex);
switch (event.getActionMasked()) {
// When finger touches the screen, ricer will accelerate up
case MotionEvent.ACTION_DOWN:
case MotionEvent.ACTION_POINTER_DOWN:
if( touchOnTopOfScreen(touchY) ){
pointerId = pointerID;
ricerView.goUp();
log("RV1 down Id=" + pointerID + " Y-pos=" + touchY);
}
else{
pointerId2 = pointerID;
ricerView2.goUp();
log("RV2 down Id=" + pointerID + " Y-pos=" + touchY);
}
break;
// When finger is lifted from the screen, ricer will accelerate down
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_POINTER_UP:
if( pointerId == pointerID ){
ricerView.goDown();
pointerId = -1;
log("RV1 up Id=" + pointerID + " Y-pos=" + touchY);
}
if( pointerId2 == pointerID ){
ricerView2.goDown();
pointerId2 = -1;
log("RV2 up Id=" + pointerID + " Y-pos=" + touchY);
}
}
}
// Delegate the touch to the gestureDetector
mGestureDetector.onTouchEvent(event);
return true;
} // End of onTouchEvent
private boolean touchOnTopOfScreen(float y){
if(mDisplayHeight/2 > y)
return true;
else
return false;
}