Attention: Here be dragons

This is the latest (unstable) version of this documentation, which may document features not available in or compatible with released stable versions of Godot.

TouchScreenButton

繼承: Node2D < CanvasItem < Node < Object

觸控式螢幕裝置的按鈕,供遊戲使用。

說明

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 Node2D. 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.

屬性

String

action

""

BitMap

bitmask

bool

passby_press

false

Shape2D

shape

bool

shape_centered

true

bool

shape_visible

true

Texture2D

texture_normal

Texture2D

texture_pressed

VisibilityMode

visibility_mode

0

方法

bool

is_pressed() const


訊號

pressed() 🔗

當按鈕被按下時觸發,即向下。


released() 🔗

當按鈕被釋放時觸發,即向上。


列舉

enum VisibilityMode: 🔗

VisibilityMode VISIBILITY_ALWAYS = 0

始終可見。

VisibilityMode VISIBILITY_TOUCHSCREEN_ONLY = 1

僅在觸控式螢幕上可以看到。


屬性說明

String action = "" 🔗

按鈕的動作。動作可以用 InputEventAction 來處理。


BitMap bitmask 🔗

按鈕的位元遮罩。


bool passby_press = false 🔗

  • void set_passby_press(value: bool)

  • bool is_passby_press_enabled()

如果為 true,只要按下的手指進出按鈕,就會發出 pressedreleased 訊號,即使壓力開始於按鈕的有效區域之外。

注意:這是一種“pass-by”的按壓模式 ,而不是“bypass”。


Shape2D shape 🔗

該按鈕的形狀。


bool shape_centered = true 🔗

  • void set_shape_centered(value: bool)

  • bool is_shape_centered()

如果為 true,按鈕的形狀會在提供的紋理中居中。如果沒有使用紋理,這個屬性就沒有效果。


bool shape_visible = true 🔗

  • void set_shape_visible(value: bool)

  • bool is_shape_visible()

如果為 true,則該按鈕的形狀在編輯器中可見。


Texture2D texture_normal 🔗

該按鈕在正常狀態下的紋理。


Texture2D texture_pressed 🔗

按鈕在被按下狀態時的紋理。


VisibilityMode visibility_mode = 0 🔗

The button's visibility mode.


方法說明

bool is_pressed() const 🔗

如果這個按鈕目前被按下,則返回 true