classes/class_touchscreenbutton #80
Replies: 2 comments 3 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.
3 replies
-
"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.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
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