Touch held problem between scenes

Hi guys,
I have a problem that I havent been able to resolve for a few days now.

I’m making an Android game. Let’s say the character dies in the game and the player has two options. Either touch Yes or No, depending on whether he wants to play again or not.
If he touches Yes, the game starts over again. If he touches No, the player is returned to the Main Menu.
The problem is that, for some reason, if the player touches No and is immediately returned back to the Main Menu, the touch is registered in the Main Menu as well (on the wrong place too). Then, for example, the game quits (because the touch is registered on the Exit sprite).
How the hell can this be resolved? I know how to do it with mouse clicks but what about touches? Thanks for help!!

Use a global boolean variable. Set it to true when the touch is down, and false when touch isn’t down. When you check the touch is on a button, also check that this global boolean variable is false (and set it to true in the actions).

Using a global variable means it persists between scenes.

1 Like

I understand this logic but it doesn’t seem to work.
The condition that checks if the touch is held doesnt return true for some reason.
It’s absolutely frustrating to me now because I think the logic is correct. :pensive:

I have tried to reproduce the problem in this example:

From the shared file :

You’re setting the boolean after you change scenes. That bit of code won’t get actioned.

Switch the commands around, so you set the boolean before you change scenes.

And is there a reason you’re using Pause and start new scene, rather than change scene?

Also add a trigger once on the condition. It’s good practice; things could get messy otherwise.

I’ve made all the changes but the problem still persists.

Ok, I missed adding this comment to my previous post - you also need to add the condition that “Touch or left mouse button is down” as well as checking that “The cursor/touch is on …”. Just checking if the mouse is over an object isn’t enough.


omg, that works!! thank you so much!! I forgot that there is a difference between Touch is on and Touch is down and that you need both.
What’s the difference between Pause and start a new scene and change scene actions?
Is it better to use the latter?

If you don’t intend to go back to the first scene, then yes, use the change scene action. I believe the “Pause the scene” action stores the state of the scene so you can go back to it from the scene you’re moving to.

1 Like