How to layout TouchScreenButton?

Godot Version



I need the multitouch functionality as it’s a 2-player game on the same phone. But since this node is a Node2D and not a Control, it can neither be anchored, nor be arranged by container-esque controls.

The docs says that it’s mainly used for gameplay and not UI, meaning, I would assume it’s for stuff like joystick+action1+action2 etc, and not menu buttons, but… those buttons still need to arranged on screen similar to UI nodes though? Am I missing something? Would I not expect the gameplay buttons in an action game to be pushed further apart from the center when using a wider (landscape mode) phone?

make a Control node and place the Node2D as the child of the Control node

1 Like

EDIT: Nvm, I set the alignment of the control to their respective requirements and then changed the position of the child touchscreenbutton

It stays anchored to the top left of that control when changing screen resolution then.

Default window vs wider window:

(The grey boxes are standard buttons, whereas the arrows are the sprites for the touchscreenbutton. The final product is not meant to have the gray boxes.)

you have to configure this option

here, you could simulate the mouse click using touch. I advice you, just use PRINT to analize the metadata from touch and click.

After all of this. You are going to need the resolution and the viewport size and with this information this example is possible.
use multitoucht and indentify the points you get when each touch event happens.
limit the coordinate to separate both players.
Just be creative.

0 up to 100 px player 1
900 up to 1000 px Player 2
and using multitouch you´d have the answer

EVENT InputEventMouseButton: button_index=1, mods=none, pressed=true, canceled=false, position=((982, 260)), button_mask=1, double_click=false
EVENT InputEventScreenTouch: index=0, pressed=false, canceled=false, position=((982, 260)), double_tap=false

Index is going to tell you the quantity of fingers is touching the screen