Touch - what am I doing wrong?

So for over a month now my game mightymowerr has been a touch any part of the screen to jump and when youdieyou touch again to restart.

Here is the game:

I just use a touched command like this in main:

function touched(touch)
    if lost==0 and game==Gmenu and state==stopped then state=startscreen ohno=1
    if game==Ggo and state==moving and m.Moy==scalerY*34.5 then state=jump
        sound(SOUND_JUMP, 1232)

The first if statement is when the game loads you click to start playing.
The second one detects if game is in motion and then let’s you jump.

Now when you die I now have two buttons. One to start over and one to rate the game.

I have a piece of code in the draw function of a class called Gameover

The code is like this:

if st==1 then
        if CurrentTouch.x > scalerX*58.5 and CurrentTouch.x < scalerX*93.5
        and CurrentTouch.y > scalerY*12.5 and CurrentTouch.y < scalerY*25.5 then

St is a state for when the Gameover graphics finish animating into place. But some times it just launches resetGame() because it remembers it’s pressed from before.

I think its to do with a double tap of the button. Is there a way to make sure a tap is a single tap? That way the start over button won’t be tricked out.

This has only been since I’ve switched from detecting a button area call on the game over screen instead of the whole screen I used to do at game over.



touch.tapCount counts how many times the touch has been tapped

Thanks @cabernet so do I need to count the times tapped? Is it even times? Or something else? Thanks Major


It was so simple, I just needed to take the touch.current statements out of the draw of gameOver class and put it within touched in the main class. Tweak the if statement so it checked if st==01 and touch.current etc then it works!

No need for tap count. Just have it with an if statement within your main touch function

Thanks all

@Majormorgan, there should be no need to move the touch code into main. From the problem, my best guess is that you are not checking the state of the touch?

If so, adding either an if touch.state == BEGAN or a if touch.state == ENDED (You have to use the same one everywhere for this to work) to your checks will ensure that once it switches to the other screen, the conditional is now false and the previous touch won’t activate something on the new screen.