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.


1 Answer 1


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.

  • \$\begingroup\$ Ah makes sense! I didn't realize that, thanks for the clarification! :) \$\endgroup\$
    – SSH This
    Dec 24, 2012 at 22:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .