4

I am capturing the event of onSceneTouchEvent using AndEngine.

What i want to do is not allow it to capture the user double tapping the screen.

Is there anyway to detect double taps or disable them?

Thanks

coder_For_Life22
  • 26,645
  • 20
  • 86
  • 118
  • 1
    Have you seen this solution? http://stackoverflow.com/questions/6716224/ontap-listener-implementation using the systemclock to time a delay? That may help. – TryTryAgain Jan 14 '12 at 07:17
  • Hmm. interesting, if you provide an example of such as a answer i will mark it correctly. – coder_For_Life22 Jan 14 '12 at 07:28
  • Happy that helped. I added another solution to the top of an answer I just posted. Might as well try that too :-) – TryTryAgain Jan 14 '12 at 07:38

1 Answers1

3

EDIT: After looking around some more, I think this may better suit you:

// in an onUpdate method

onUpdate(float secondsElapsed){

if(touched){
if(seconds > 2){
doSomething();
touched = false;
seconds = 0;
} else{
seconds += secondsElapsed;
}
}

}

Taken from: http://www.andengine.org/forums/gles1/delay-in-touchevent-t6087.html

Based on the comment above, I'm sure you can finagle something with the following too, using SystemClock.

You can get away with adding a delay, something similar to this:

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

Community
  • 1
  • 1
TryTryAgain
  • 7,632
  • 11
  • 46
  • 82