I should mention right off the bat I only have limited experience with Godot and mobile platforms, so I'd take what I say with a grain of salt.
I think the problem is how you are handling touches.
For every finger tapped on the screen, a new InputEventScreenTouch
event is created, where index
is the ID for each finger. For example, if I touch the screen with my thumbs, holding with my left thumb and then holding with my right thumb, two InputEventScreenTouch
events will be created, one for my left thumb and one for my right.
Because the left thumb input event was the first to touch the screen (because I tapped with my left, and then my right), it will have a index of 0
. My right thumb input event will have a index of 1
, because it is the second finger to touch the screen.
This is a problem in your case because you are only checking for touches, not when the fingers move or when they are held down, just when they press and release.
Here's how I would fix this (untested code, so it may not work):
"I'm going to use empty strings to work around the forums code thingy"
"not liking blank lines in code, just as a FWI"
extends Node
"We need to store a few things for each touch"
var touch_one = {"down":false, "position":Vector2(0,0)}
var touch_two = {"down":false, "position":Vector2(0,0)}
""
func _input(event):
if (event is InputEventScreenTouch):
if (event.index == 0):
touch_one["down"] = event.is_pressed()
"I've never used something like the line below before"
"but I'm going to assume it works"
touch_one["position"] = make_input_local(event).position;
elif (event.index == 1):
touch_two["down"] = event.is_pressed()
touch_two["position"] = make_input_local(event).position;
""
func _process(delta):
if (touch_one["down"] == true and touch_two["down"] == true):
dir = "both";
$Label.text = "Both";
elif (touch_one["down"] == true or touch_two["down"] == true):
var touch_position = null;
""
if (touch_one["down"] == true):
touch_position = touch_one["position"];
elif (touch_two["down"] == true):
touch_position = touch_two["position"];
else:
print ("Error: Unknown touch!");
return;
""
if (touch_position.x < 0):
dir = "left";
$Label.text = "Left";
else
dir = "right";
$Label.text = "Right";
else:
dir = "none";
$Label.text = "None";