classes/class_touchscreenbutton #80
Replies: 4 comments 5 replies
-
|
"Unlike with Control nodes, you cannot set anchors on it." In case you do want to anchor the touchscreenbutton to anything other then the top left corner of the screen you can make the node a child of a Control node that has it's anchors set. I spend some time scratching my head on how to make right handed touchscreenbuttons responsive, hope this saves you some time! |
Beta Was this translation helpful? Give feedback.
-
|
"Unlike with Control nodes, you cannot set anchors on it." Besides the solution shared by @lukky-dev, you can also intercept the touch events directly. Here's a c# example: using Godot;
public partial class TouchButton : Control
{
public override void _Input(InputEvent @event)
{
switch (@event)
{
case InputEventScreenTouch touchEvent:
if (GetGlobalRect().HasPoint(touchEvent.Position))
{
if (touchEvent.Pressed)
GD.Print($"touched down!");
else
GD.Print($"touched up!");
GetViewport().SetInputAsHandled();
}
break;
case InputEventScreenDrag dragEvent:
if (GetGlobalRect().HasPoint(dragEvent.Position))
{
GD.Print($"dragged!");
GetViewport().SetInputAsHandled();
}
break;
}
}
} |
Beta Was this translation helpful? Give feedback.
-
They don't have to be, though. Handling them via the |
Beta Was this translation helpful? Give feedback.
-
|
What does mean "action" in its property's? |
Beta Was this translation helpful? Give feedback.

Uh oh!
There was an error while loading. Please reload this page.
-
classes/class_touchscreenbutton
Inherits: Node2D< CanvasItem< Node< Object Button for touch screen devices for gameplay use. Description: TouchScreenButton allows you to create on-screen buttons for touch devices. It's intended f...
https://docs.godotengine.org/en/stable/classes/class_touchscreenbutton.html
Beta Was this translation helpful? Give feedback.
All reactions