[Tutorial] first object pressed and released touch activated only

Hi, I have tested that my method of touch activation works consistently, but it might include too many events/code. I would like to find out if there is a shorter or simpler way to activate touches so that the first object I press down and release is the only one that can be activated? (The intended action is different from the first object activated as soon as touch is down)

For example, if I press and hold down ‘play’ button with mouse/touch then drag/move touch off it then back on ‘play’, no action activation happens.

Here is my method (video demo and events) on my approach to it. This is the intended result I was looking for. The difference in the video demo and screenshots is the 3 hidden objects visible in the video I used for the cursor/touch (eg. bugbase) to show what it looks like. The blue highlightb1 is created at position button.


I also used 2 scene variables,

  • ‘pickno’ = 1 (only if first object is chosen)
  • ‘nom’ = number of objects pressed down on before touch is released (if at least 2 objects chosen, then ‘pickno’ becomes 0

NOTE: I also delete (highlightb1) object and set ‘pickno’ to 0 if I activate an object without changing scene. I only don’t need to include this if I change scene as an action.

I’m not sure if this topic has been mentioned before, but hopefully my method is not too complex and can help GDevelop users if there is no easier/shorter way.

Yes, there is. This is a lot simpler, and works:

  1. Set up one button object, with an animation for each button type. Use the scene name opened by the button as the animation name:


  2. Place the buttons on screen, and change the animation in the editor

  3. Use the following events to control the buttons:

And that should be all you need.

1 Like

Thank you very much for your help. I tested your method and it works consistently. I just adjusted a few things. Even if booleen variable is scene variable I think it still works instead of repeating process ‘clicked’ as an object variable. Anyway, here are my events.

I think I got the idea now. This would definitely help for future projects as well.