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.

TextureButton

繼承: BaseButton < Control < CanvasItem < Node < Object

基於紋理的按鈕。支援按下、懸停、停用和焦點狀態。

說明

TextureButton has the same functionality as Button, except it uses sprites instead of Godot's Theme resource. It is faster to create, but it doesn't support localization like more complex Controls.

See also BaseButton which contains common properties and methods associated with this node.

Note: Setting a texture for the "normal" state (texture_normal) is recommended. If texture_normal is not set, the TextureButton will still receive input events and be clickable, but the user will not be able to see it unless they activate another one of its states with a texture assigned (e.g., hover over it to show texture_hover).

教學

屬性

bool

flip_h

false

bool

flip_v

false

bool

ignore_texture_size

false

StretchMode

stretch_mode

2

BitMap

texture_click_mask

Texture2D

texture_disabled

Texture2D

texture_focused

Texture2D

texture_hover

Texture2D

texture_normal

Texture2D

texture_pressed


列舉

enum StretchMode: 🔗

StretchMode STRETCH_SCALE = 0

縮放以適應節點的邊界矩形。

StretchMode STRETCH_TILE = 1

在節點的邊界矩形內平鋪。

StretchMode STRETCH_KEEP = 2

紋理保持它的原始尺寸,並保持在邊界矩形的左上角。

StretchMode STRETCH_KEEP_CENTERED = 3

紋理保持其原始大小,並在節點的邊界矩形中保持居中。

StretchMode STRETCH_KEEP_ASPECT = 4

縮放紋理以適應節點的邊界矩形,但保持紋理的長寬比。

StretchMode STRETCH_KEEP_ASPECT_CENTERED = 5

縮放紋理以適應節點的邊界矩形,使其居中,並保持長寬比。

StretchMode STRETCH_KEEP_ASPECT_COVERED = 6

縮放紋理,使較短的一邊適應邊界矩形。另一邊則裁剪到節點的界限內。


屬性說明

bool flip_h = false 🔗

  • void set_flip_h(value: bool)

  • bool is_flipped_h()

若為 true,紋理將水平翻轉。


bool flip_v = false 🔗

  • void set_flip_v(value: bool)

  • bool is_flipped_v()

若為 true,紋理將垂直翻轉。


bool ignore_texture_size = false 🔗

  • void set_ignore_texture_size(value: bool)

  • bool get_ignore_texture_size()

如果為 true,則計算最小尺寸時不會考慮該紋理的大小,因此 TextureButton 能夠調整地比該紋理大小還要小。


StretchMode stretch_mode = 2 🔗

控制調整節點包圍矩形時紋理的行為。可用的選項見 StretchMode 常數。


BitMap texture_click_mask 🔗

  • void set_click_mask(value: BitMap)

  • BitMap get_click_mask()

用於點擊偵測的純黑白 BitMap 圖像。在遮罩上,白色圖元代表按鈕的可點擊區域。可用它來建立具有彎曲形狀的按鈕。


Texture2D texture_disabled 🔗

Texture to display when the node is disabled. See BaseButton.disabled. If not assigned, the TextureButton displays texture_normal instead.


Texture2D texture_focused 🔗

Texture to overlay on the base texture when the node has mouse or keyboard focus. Because texture_focused is displayed on top of the base texture, a partially transparent texture should be used to ensure the base texture remains visible. A texture that represents an outline or an underline works well for this purpose. To disable the focus visual effect, assign a fully transparent texture of any size. Note that disabling the focus visual effect will harm keyboard/controller navigation usability, so this is not recommended for accessibility reasons.


Texture2D texture_hover 🔗

Texture to display when the mouse hovers over the node. If not assigned, the TextureButton displays texture_normal instead when hovered over.


Texture2D texture_normal 🔗

節點不處於禁用、懸停、按下狀態時,預設顯示的紋理。該紋理仍會在聚焦狀態下顯示,上層繪製的是 texture_focused


Texture2D texture_pressed 🔗

Texture to display on mouse down over the node, if the node has keyboard focus and the player presses the Enter key or if the player presses the BaseButton.shortcut key. If not assigned, the TextureButton displays texture_hover instead when pressed.