Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am making a simple american football game, and I'm having an issue with the onSceneTouchEvent function, I have this code:

public boolean onSceneTouchEvent(final Scene pScene, final TouchEvent pSceneTouchEvent) {

    if (hiking == 0) {
        Log.v("me", "Only the player should move");
        return hike();
    } else {
        Log.v("me", "this shouldn't ever happen on first click");
        return throwBall(pSceneTouchEvent);


Inside hike() I set hiking to 1, so that theoretically, the player should be able to click anywhere to hike the ball, (all the other sprites start moving and the ball is not thrown). Then on the second click the ball is thrown. But with one click on the emulator, the ball is hiked and thrown at the same time, I also see this in the log (after only one click):

12-21 14:34:32.113: V/me(1189): Only the player should move

12-21 14:34:32.143: V/me(1189): this shouldn't ever happen on first click

12-21 14:34:32.183: V/me(1189): this shouldn't ever happen on first click

So it appears that it's triggering three times on one click? Why is this happening? How can I make it only run the code once per click?


Perhaps I could just prevent any events by using a timer? Like disable the listener for a second after the hike? I'm hoping there is a better solution though.

share|improve this question
up vote 2 down vote accepted

I think you didn't know the working of the onSceneTouchEvent().

The onSceneTouchEvent() method execute three times when user one time touch on the device. This happen three times because it calls three events on single touch.

1) touch down 2) touch move 3) touch up

As per your requirement you have to change your code in following manner.

public boolean onSceneTouchEvene(){

         // you code goes here

This way three other method exist that also you can use based on requirement.

share|improve this answer
Ah makes sense! I didn't realize that, thanks for the clarification! :) – SSH This Dec 24 '12 at 22:15

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.