0 votes

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:

InputEventScreenTouch : index=0, pressed=true, position=...
InputEventScreenTouch : index=0, pressed=false, position=...

along with some mouse events of course.

Same app run on Android, with logcat connected, it only shows me the first event (pressed=true), but the other one never arrives.
Any clue why?

in Engine by (33 points)

1 Answer

+1 vote

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
by (3,232 points)

No, that's not my case. I just touch and release the touch, without any movement.

And also I never see index different than 0, it's always 0...

And one more thing: it behaves the same on real device and on windows android emulator.

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:

  var evl = make_input_local(ev)
  if "position" in evl:
     var is_in_rect = Rect2(Vector2(0,0),rect_size).has_point(evl.position)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.