|Topic was automatically imported from the old Question2Answer platform.
|Daniel G. Machado Jr
TLDR; I don’t understand touch indexes and can’t find who does. I want to handle two or more simultaneous touch events but simply can’t figure how.
I’m quite new to Godot engine. But I’m a programmer, so I kinda can get myself around the documentation and understand things from there.
So I’m trying to make a dual analog stick scene. I did a stick scene which handles events through _gui_event(), (which seems to handle events in local space, which is good in this case).
I have an analog stick scene that I want to be able to handle it’s events inputs independently (encapsulation, basically).
So in this scene I create a local “index” variable which is supposed to filter the events so that it only handles the event with it’s own index, unless this local index is set to null, on that case it will accept any event. It works wonderfully alone…
code is something like this:
if (event is InputEventScreenTouch) or
(event is InputEventScreenDrag):
if (index == null or index == event.index):
index = event.index;
//...handle the event
index = null; //on release, the joystick index is null
//...some other stuff
What actually happens though is that somehow the sticks are always responding only to the last touch index (even with an if statement blocking that) as if the two events with different indexes are the same instance of the last event.
But there’s absolutely ZERO explaining on how to use indexes. ZERO.
I’m obviously doing something VERY VERY wrong here. But I can’t figure what because I simply can’t find any more detailed documentation.
Sorry for being so ranty on it. But I’m already two days straight dealing with it.
See my answer below with code. But to add to that: the trick is to listen for events, and then place your analog stick graphic to follow the touch when the touch is in the right region, not the otherway around. This is anyway how a lot of games handle it, “floating stick” is what it’s often called.
billyb | 2018-06-13 15:10