Up to date

This page is up to date for Godot 4.2. If you still find outdated information, please open an issue.

TouchScreenButton

继承: Node2D < CanvasItem < Node < Object

触摸屏设备的按钮,供游戏使用。

描述

TouchScreenButton 允许你为触摸设备创建屏幕上的按钮。其为游戏使用,比如在必须触摸才能移动的设备。与 Button 不同,TouchScreenButton 原生支持多点触摸。几个 TouchScreenButton 可以通过触摸输入同时被按下。

这个节点继承自 Node2D。与 Control 节点不同,你不能在它上面设置锚点。如果要创建菜单或用户界面,可用 Button 节点代替。为了使按钮节点对触摸事件作出反应,可在项目设置中启用模拟鼠标选项。

可将 TouchScreenButton 配置为只在触摸设备上可见,有助你同时为桌面和移动设备开发游戏。

属性

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 ( bool value )

  • bool is_passby_press_enabled ( )

如果为 true,只要按下的手指进出按钮,就会发出 pressedreleased 信号,即使压力开始于按钮的有效区域之外。

注意:这是一种“pass-by”的按压模式 ,而不是“bypass”。


Shape2D shape

该按钮的形状。


bool shape_centered = true

  • void set_shape_centered ( bool value )

  • bool is_shape_centered ( )

如果为 true,按钮的形状会在提供的纹理中居中。如果没有使用纹理,这个属性就没有效果。


bool shape_visible = true

  • void set_shape_visible ( bool value )

  • bool is_shape_visible ( )

如果为 true,则该按钮的形状在编辑器中可见。


Texture2D texture_normal

该按钮在正常状态下的纹理。


Texture2D texture_pressed

按钮在被按下状态时的纹理。


VisibilityMode visibility_mode = 0

按钮的可见性模式。可能的取值见 VisibilityMode


方法说明

bool is_pressed ( ) const

如果这个按钮当前被按下,则返回 true