TextureButton

Inherits: BaseButton < Control < CanvasItem < Node < Object

基于纹理的按钮。支持按下、悬停、停用和焦点状态。

描述

TextureButton 的功能与 Button 相同,只是它使用精灵而不是 Godot 的 Theme 主题资源。它的创建速度更快,但它不像更复杂的 Control 那样支持本地化。

“正常”状态必须包含一个纹理(texture_normal);其他纹理是可选的。

也请参阅 BaseButton,它包含了与该节点相关的通用属性和方法。

教程

属性

bool

expand

false

bool

flip_h

false

bool

flip_v

false

StretchMode

stretch_mode

0

BitMap

texture_click_mask

Texture

texture_disabled

Texture

texture_focused

Texture

texture_hover

Texture

texture_normal

Texture

texture_pressed

枚举

enum StretchMode:

  • STRETCH_SCALE = 0 —- 缩放以适应节点的边界矩形。

  • STRETCH_TILE = 1 —- 在节点的边界矩形内平铺。

  • STRETCH_KEEP = 2 —- 纹理保持它的原始尺寸,并保持在边界矩形的左上角。

  • STRETCH_KEEP_CENTERED = 3 —- 纹理保持其原始大小,并在节点的边界矩形中保持居中。

  • STRETCH_KEEP_ASPECT = 4 —- 缩放纹理以适应节点的边界矩形,但保持纹理的长宽比。

  • STRETCH_KEEP_ASPECT_CENTERED = 5 —- 缩放纹理以适应节点的边界矩形,使其居中,并保持长宽比。

  • STRETCH_KEEP_ASPECT_COVERED = 6 —- 缩放纹理,使较短的一边适应边界矩形。另一边则裁剪到节点的界限内。

属性说明

Default

false

Setter

set_expand(value)

Getter

get_expand()

true 时纹理会使用 stretch_mode 拉伸到节点的边界矩形的边缘。为 false 时纹理将不随节点缩放。


Default

false

Setter

set_flip_h(value)

Getter

is_flipped_h()

true 时纹理将被水平翻转。


Default

false

Setter

set_flip_v(value)

Getter

is_flipped_v()

true 时纹理将被垂直翻转。


Default

0

Setter

set_stretch_mode(value)

Getter

get_stretch_mode()

控制纹理在你调整节点的边界矩形时的行为,只有在expandtrue 的情况下。把它设置为 StretchMode 常量之一。请看常量来了解更多。


Setter

set_click_mask(value)

Getter

get_click_mask()

用于点击检测的纯黑白BitMap图像。在遮罩上,白色像素代表按钮的可点击区域。可用它来创建具有弯曲形状的按钮。


Setter

set_disabled_texture(value)

Getter

get_disabled_texture()

节点被禁用时显示的纹理。参阅BaseButton.disabled


Setter

set_focused_texture(value)

Getter

get_focused_texture()

当节点具有鼠标或键盘焦点时显示的纹理。


Setter

set_hover_texture(value)

Getter

get_hover_texture()

当鼠标悬停在节点上时显示的纹理。


Setter

set_normal_texture(value)

Getter

get_normal_texture()

节点不处于禁用、聚焦、悬停、按下状态时,默认显示的纹理。


Setter

set_pressed_texture(value)

Getter

get_pressed_texture()

如果节点有键盘焦点且玩家按下回车键,或者玩家按下 BaseButton.shortcut 键,则鼠标悬停在节点上时显示的纹理。