我正在使用AndEngine捕获onSceneTouchEvent的事件。
我想做的是不允许它捕获用户双击屏幕。
无论如何都要检测双击还是禁用它们?
由于
答案 0 :(得分:3)
// 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;
}