How do you get a sprite to respond to being tapped?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By powderblue042

Hi everybody,
I’m brand new to Godot and learning slowly about the various features, so please treat me like I know nothing!
I need to get sprites to take actions when they are tapped via a touchscreen, how do I write code so that when the sprite is tapped it causes a response?
Thank you,
Powderblue042

in project settings set enable simulate touch on desktop and simulate mouse on moble

rakkarage | 2020-06-27 17:56

Hi rakkarage,
Thank you for the suggestion, I saw this in the tutorial selamba mentioned, the issue is whether tapping is treated differently from a mouse clicking and how to code it, for example it just appears, it doesn’t ‘enter’ the body of the Area2D node that I created from outside. I’m also not sure how to combine a mouse click with a check of whether the sprite is the one clicked. I’d also need to be able to tap where there are 2 or more sprites and tell Godot which sprite is being tapped, those are the two questions I need to find an answer for.
Kind regards,
Powderblue042

powderblue042 | 2020-06-27 21:25

Hey guys.
I found this video tutorial which helped a lot: youtube.com/watch?v=32VtGtVrOrw, but still not sure about the mouse vs. screen touch thing.
Kind regards,
Powderblue042

powderblue042 | 2020-07-04 11:58

:bust_in_silhouette: Reply From: selamba

The same way you would go about handling clicks. The step-by-step tutorial on the official docs that nobody seems to read is about making a mobile game, you can see the code samples there.

Hey Selamba!
Thank you for the suggestion, would you mind just pointing out which part might help? I’ve gone through that tutorial, and I think only the button section could be useful, but I need to be able to click a sprite.
Kind regards,
Powerblue042

powderblue042 | 2020-06-27 20:35

Sorry, I don’t remember. You need to find “input handling”.

selamba | 2020-06-27 21:37

Hi Selamba!
I’ve had a look through, the tutorial does address inputting, but not as specifically as I need it. My comment I attached to rakkarage’s comment explains what is it I need.
Thanks,
Powderblue042

powderblue042 | 2020-06-28 11:41