Detect if a Sprite is touched

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

I want an action to be executed when a sprite is clicked (with touch). I have tried to solve this with the following post ( but unfortunately it does not work as expected… It does not react to anything anymore. With my previous code I was able to capture at least a touch input on the whole screen.
Here is my code where the touch input on the hole screen works and how I built the scene.

extends Area2D

func _ready():
	pass # Replace with function body.

func _input(event: InputEvent) -> void:
	if event is InputEventScreenTouch and event.is_pressed():

Scene Build pictures: Godot Game post - Album on Imgur

This scene

I want to instantiate the scene with the sprite into the main scene, where by pressing the sprite values should be changed.

Code of the main scene:

extends Node

onready var touches_label : Label = $Container/VBoxContainer/Touches

var click_count := 0.0

func _ready() -> void:

func update_touches_label() -> void:
	touches_label.text = str(click_count)
:bust_in_silhouette: Reply From: Krippi

Hey, I also had a problem that when I used touch, nothing ever happened.
I was able to solve it and it currently looks like this:

func _input(event):
   if event is InputEventScreenTouch and event.is_pressed():

Oh, I’m sorry I didn’t look at the translation again.
So the touch recognition sort of works… But only on the full screen. I want the sprite to only detect the touches.

freaki2010 | 2020-03-15 20:21

:bust_in_silhouette: Reply From: Krippi

Oh okay then try this. Area2D has a node method called input_event(). Connect it.

func _input_event(viewport, event, shape_idx):

Now it finally worked!
I started a new project and just inserted the sprite and tested it. I guess that the container or something else in between sparked and therefore it didn’t work.
Thanks a lot for your help!

freaki2010 | 2020-03-16 08:55

:bust_in_silhouette: Reply From: freaki2010

After a lot of research I finally found out why the sprite did not recognize the touch when a control node was added. To make the sprite recognize the touch you have to set the filter of the control node in the inspector under mouse to “Ignore”.

Overwiev of the Config