我正在使用AndEngine捕获onSceneTouchEvent事件。
我想做的是不允许它捕获用户双击屏幕的操作。
是否有任何方法可以检测双击或禁用双击?
谢谢。
我正在使用AndEngine捕获onSceneTouchEvent事件。
我想做的是不允许它捕获用户双击屏幕的操作。
是否有任何方法可以检测双击或禁用双击?
谢谢。
编辑:经过进一步查找,我认为这个可能更适合你:
// in an onUpdate method
onUpdate(float secondsElapsed){
if(touched){
if(seconds > 2){
doSomething();
touched = false;
seconds = 0;
} else{
seconds += secondsElapsed;
}
}
}
摘自:http://www.andengine.org/forums/gles1/delay-in-touchevent-t6087.html
根据上面的评论,我相信您也可以使用SystemClock来处理以下内容。
您可以通过添加延迟来解决问题,类似于以下代码:
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
if(firstTap){
thisTime = SystemClock.uptimeMillis();
firstTap = false;
}else{
prevTime = thisTime;
thisTime = SystemClock.uptimeMillis();
//Check that thisTime is greater than prevTime
//just incase system clock reset to zero
if(thisTime > prevTime){
//Check if times are within our max delay
if((thisTime - prevTime) <= DOUBLE_CLICK_MAX_DELAY){
//We have detected a double tap!
Toast.makeText(DoubleTapActivity.this, "DOUBLE TAP DETECTED!!!", Toast.LENGTH_LONG).show();
//PUT YOUR LOGIC HERE!!!!
}else{
//Otherwise Reset firstTap
firstTap = true;
}
}else{
firstTap = true;
}
}
return false;
}
Taken from OnTap listener implementation