TextureButton

Inherits:BaseButton<Control<CanvasItem<Node<Object

Texture-based button. Supports Pressed, Hover, Disabled and Focused states.

Description

TextureButton has the same functionality asButton, except it uses sprites instead of Godot'sTheme resource. It is faster to create, but it doesn't support localization like more complexControls.

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

Note: Setting a texture for the "normal" state (texture_normal) is recommended. Iftexture_normal is not set, theTextureButton 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 showtexture_hover).

Tutorials

Properties

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


Enumerations

enumStretchMode:🔗

StretchModeSTRETCH_SCALE =0

Scale to fit the node's bounding rectangle.

StretchModeSTRETCH_TILE =1

Tile inside the node's bounding rectangle.

StretchModeSTRETCH_KEEP =2

The texture keeps its original size and stays in the bounding rectangle's top-left corner.

StretchModeSTRETCH_KEEP_CENTERED =3

The texture keeps its original size and stays centered in the node's bounding rectangle.

StretchModeSTRETCH_KEEP_ASPECT =4

Scale the texture to fit the node's bounding rectangle, but maintain the texture's aspect ratio.

StretchModeSTRETCH_KEEP_ASPECT_CENTERED =5

Scale the texture to fit the node's bounding rectangle, center it, and maintain its aspect ratio.

StretchModeSTRETCH_KEEP_ASPECT_COVERED =6

Scale the texture so that the shorter side fits the bounding rectangle. The other side clips to the node's limits.


Property Descriptions

boolflip_h =false🔗

Iftrue, texture is flipped horizontally.


boolflip_v =false🔗

Iftrue, texture is flipped vertically.


boolignore_texture_size =false🔗

Iftrue, the size of the texture won't be considered for minimum size calculation, so theTextureButton can be shrunk down past the texture size.


StretchModestretch_mode =2🔗

Controls the texture's behavior when you resize the node's bounding rectangle. See theStretchMode constants for available options.


BitMaptexture_click_mask🔗

Pure black and whiteBitMap image to use for click detection. On the mask, white pixels represent the button's clickable area. Use it to create buttons with curved shapes.


Texture2Dtexture_disabled🔗

Texture to display when the node is disabled. SeeBaseButton.disabled. If not assigned, theTextureButton displaystexture_normal instead.


Texture2Dtexture_focused🔗

Texture tooverlay on the base texture when the node has mouse or keyboard focus. Becausetexture_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.


Texture2Dtexture_hover🔗

Texture to display when the mouse hovers over the node. If not assigned, theTextureButton displaystexture_normal instead when hovered over.


Texture2Dtexture_normal🔗

Texture to display by default, when the node isnot in the disabled, hover or pressed state. This texture is still displayed in the focused state, withtexture_focused drawn on top.


Texture2Dtexture_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 theBaseButton.shortcut key. If not assigned, theTextureButton displaystexture_hover instead when pressed.


User-contributed notes

Please read theUser-contributed notes policy before submitting a comment.