【发布时间】:2015-06-23 20:36:02
【问题描述】:
如何检测双击拖动? 我正在制作一个类似于宝石迷阵的游戏,并想检测到这一点。 在我当前的实现中,我能够获得滑动效果。我还想检测游戏中不同功能的双击拖动效果。
代码:
@Override
public boolean onTouch(MotionEvent e, int scaledX, int scaledY) {
if (e.getAction() == MotionEvent.ACTION_DOWN && board.touchBoard(scaledX, scaledY) ) {
recentTouchY = scaledY;
recentTouchX = scaledX;
board.whichCell(scaledX,scaledY);
touchedCell = board.whichCellTouched(scaledX,scaledY);
//board.swapClearShape(touchedCell.getOffX(),touchedCell.getOffY());
} else if (e.getAction() == MotionEvent.ACTION_UP) { //NEED TO ADD IF TOUCH BOARD AREA
//swipe event
if (scaledX - recentTouchX < -25) {
System.out.println("SWAPPED LEFT");
Assets.playSound(Assets.swapSound);
board.setSwapLeft(true);
}
else if (scaledX - recentTouchX > 25) {
System.out.println("SWAPPED RIGHT");
Assets.playSound(Assets.swapSound);
board.setSwapRight(true);
}
//swap down
else if(scaledY- recentTouchY > 25){
System.out.println("SWAPPED DOWN");
Assets.playSound(Assets.swapSound);
board.setSwapDown(true);
}
//swap up
else if(scaledY- recentTouchY < -25){
System.out.println("SWAPPED UP");
Assets.playSound(Assets.swapSound);
board.setSwapUp(true);
}
}
return true;
}
我不是在寻找两个手指拖动,而是一个触摸,然后另一个触摸,然后拖动
【问题讨论】:
-
这个问题有一个很好的答案stackoverflow.com/a/14873942/1061944
-
我不是在寻找两个手指拖动,而是一个触摸,然后另一个触摸,然后拖动。 @Syeda Zunairah
标签: java android touch logic drag