+1 vote

I want to be able to keep track of where the user has their finger held on the screen, separately for every touched point.

One way I can imagine doing this is to guess that a drag or release event corresponds to the touched point that is the closest to the event. I don't really have any problem with this method, but it looks like the touchscreen-related input event classes have some multitouch info included as the "index" member. The docs aren't very clear on the meaning of the variable though, so would it be possible to use it as a cleaner way of keeping track of touches?

in Engine by (238 points)

1 Answer

+1 vote
Best answer

Similarly to this question https://godotengine.org/qa/11104/how-to-detect-a-screen-touch-continuously?show=11104#q11104, I would handle touch events in _input and memorize info in some member variables, so you'll be able to know at any time where touches are.
Also, touches can be identified with their index variable http://docs.godotengine.org/en/stable/classes/class_inputeventscreentouch.html

by (27,664 points)
selected by

So if I have a touch event and a release event with the same index, I will know that they correspond to each other?

Yes, that's what I understand from the doc. I never tested it though^^

I don't see anything in the docs that guarantees this. Did you get that from the docs page for InputEventScreenTouch?

Yes. I'm forced to infer it indeed, because if it's not that, what could index possibly be? It says "in case of multitouch event", so I'm pretty sure the goal of it is to tell them apart.

Yes, the index refers to the touch that produced the original pressed event.

I don't know what happens if touch "0" releases after touch 1 then comes another touch (the new one will be "2" or "0"?), check that before making the structure that will keep your touch data.

I'll probably just use a Dict so it won't matter whether indices are recycled, as long as I clear the entries for released touches.

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.