Topic was automatically imported from the old Question2Answer platform.
Asked By
jarek
Hi,
I overloaded the _gui_input method for ColorRect and I’m logging events…
On PC I have enabled touch emulation from mouse.
When clicking the ColorRect, I see two events:
I can imagine that this might happen, when the release coordinates are outside of the control.
In that case you can watch inside the _input handler (which will receive all events) to look for a touch event with the same index and pressed=false.
Roughly like that
var is_pressed=false
var pressed_index = 0
func _gui_input(ev):
if not is_pressed:
if (ev is InputEventScreenTouch) and ev.pressed:
is_pressed = true
pressed_index = ev.index
func _input(ev):
if is_pressed:
if (ev is InputEventScreenTouch) and !ev.pressed and (ev.index==pressed_index):
is_pressed = false
#do something on release here
No, that’s not my case. I just touch and release the touch, without any movement.
jarek | 2020-01-21 21:30
And also I never see index different than 0, it’s always 0…
jarek | 2020-01-21 21:31
And one more thing: it behaves the same on real device and on windows android emulator.
jarek | 2020-01-21 21:45
Index will increase if you use multiple fingers at once.
If you rely upon receiving a pressed=false event then I’d also try to work with _input(). I know that this has disadvantages as _input receives all input events and has global instead of control-local position information.
You could try this however, if you want to check if a “pressed” event occured in the rect of the current control:
_input(ev):
var evl = make_input_local(ev)
if "position" in evl:
var is_in_rect = Rect2(Vector2(0,0),rect_size).has_point(evl.position)