TouchScreenButton
Button for touch screen devices for gameplay use.
Button for touch screen devices for gameplay use.
TouchScreenButton allows you to create on-screen buttons for touch devices. It's intended for gameplay use, such as a unit you have to touch to move. Unlike Button, TouchScreenButton supports multitouch out of the box. Several TouchScreenButtons can be pressed at the same time with touch input.
This node inherits from Entity2D. Unlike with Control nodes, you cannot set anchors on it. If you want to create menus or user interfaces, you may want to use Button nodes instead. To make button nodes react to touch events, you can enable ProjectSettings.input_devices/pointing/emulate_mouse_from_touch in the Project Settings.
You can configure TouchScreenButton to be visible only on touch devices, helping you develop your game both for desktop and mobile devices.
Declarations checked against C# SDK 1.0.0. Expand a name to see declarations and documentation.
Constructors1
TouchScreenButtonConstructor
public TouchScreenButton();Properties9
ActionProperty
public string Action { get; set; }The button's action. Actions can be handled with InputEventAction.
BitmaskProperty
public Bitmap Bitmask { get; set; }The button's bitmask.
PassbyPressProperty
public bool PassbyPress { get; set; }If true, the TouchScreenButton.Pressed and TouchScreenButton.Released signals are emitted whenever a pressed finger goes in and out of the button, even if the pressure started outside the active area of the button.
Note: This is a "pass-by" (not "bypass") press mode.
ShapeProperty
public Shape2D Shape { get; set; }The button's shape.
ShapeCenteredProperty
public bool ShapeCentered { get; set; }If true, the button's shape is centered in the provided texture. If no texture is used, this property has no effect.
ShapeVisibleProperty
public bool ShapeVisible { get; set; }If true, the button's shape is visible in the editor.
TextureNormalProperty
public Texture2D TextureNormal { get; set; }The button's texture for the normal state.
TexturePressedProperty
public Texture2D TexturePressed { get; set; }The button's texture for the pressed state.
VisibilityModeProperty
public TouchScreenButton.VisibilityModeEnum VisibilityMode { get; set; }The button's visibility mode.
Methods19
GetActionstring
public string GetAction();stringGetBitmaskBitmap
public Bitmap GetBitmask();BitmapGetShapeShape2D
public Shape2D GetShape();Shape2DGetTextureNormalTexture2D
public Texture2D GetTextureNormal();Texture2DGetTexturePressedTexture2D
public Texture2D GetTexturePressed();Texture2DGetVisibilityModeTouchScreenButton.VisibilityModeEnum
public TouchScreenButton.VisibilityModeEnum GetVisibilityMode();TouchScreenButton.VisibilityModeEnumIsPassbyPressEnabledbool
public bool IsPassbyPressEnabled();boolIsPressedbool
public bool IsPressed();Returns true if this button is currently pressed.
boolIsShapeCenteredbool
public bool IsShapeCentered();boolIsShapeVisiblebool
public bool IsShapeVisible();boolSetActionvoid
public void SetAction(string action);| Name | Type | Default |
|---|---|---|
action | string | — |
SetBitmaskvoid
public void SetBitmask(Bitmap bitmask);| Name | Type | Default |
|---|---|---|
bitmask | Bitmap | — |
SetPassbyPressvoid
public void SetPassbyPress(bool enabled);| Name | Type | Default |
|---|---|---|
enabled | bool | — |
SetShapevoid
public void SetShape(Shape2D shape);| Name | Type | Default |
|---|---|---|
shape | Shape2D | — |
SetShapeCenteredvoid
public void SetShapeCentered(bool @bool);| Name | Type | Default |
|---|---|---|
bool | bool | — |
SetShapeVisiblevoid
public void SetShapeVisible(bool @bool);| Name | Type | Default |
|---|---|---|
bool | bool | — |
SetTextureNormalvoid
public void SetTextureNormal(Texture2D texture);| Name | Type | Default |
|---|---|---|
texture | Texture2D | — |
SetTexturePressedvoid
public void SetTexturePressed(Texture2D texture);| Name | Type | Default |
|---|---|---|
texture | Texture2D | — |
SetVisibilityModevoid
public void SetVisibilityMode(TouchScreenButton.VisibilityModeEnum mode);| Name | Type | Default |
|---|---|---|
mode | TouchScreenButton.VisibilityModeEnum | — |
Signals and events2
PressedEvent
public event Action Pressed;Emitted when the button is pressed (down).
ReleasedEvent
public event Action Released;Emitted when the button is released (up).
TouchScreenButton.VisibilityModeEnum
| Value | Description |
|---|---|
Always = 0 | Always visible. |
TouchscreenOnly = 1 | Visible on touch screens only. |