TextureButton

Inherits: BaseButton < Control < CanvasItem < Node < Object

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

Description

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.

The "normal" state must contain a texture (texture_normal); other textures are optional.

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

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

enum StretchMode:

  • STRETCH_SCALE = 0 --- Scale to fit the node's bounding rectangle.

  • STRETCH_TILE = 1 --- Tile inside the node's bounding rectangle.

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

  • STRETCH_KEEP_CENTERED = 3 --- The texture keeps its original size and stays centered in the node's bounding rectangle.

  • STRETCH_KEEP_ASPECT = 4 --- Scale the texture to fit the node's bounding rectangle, but maintain the texture's aspect ratio.

  • STRETCH_KEEP_ASPECT_CENTERED = 5 --- Scale the texture to fit the node's bounding rectangle, center it, and maintain its aspect ratio.

  • STRETCH_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

Default

false

Setter

set_flip_h(value)

Getter

is_flipped_h()

If true, texture is flipped horizontally.


Default

false

Setter

set_flip_v(value)

Getter

is_flipped_v()

If true, texture is flipped vertically.


  • bool ignore_texture_size

Default

false

Setter

set_ignore_texture_size(value)

Getter

get_ignore_texture_size()

If true, the size of the texture won't be considered for minimum size calculation, so the TextureButton can be shrunk down past the texture size.


Default

2

Setter

set_stretch_mode(value)

Getter

get_stretch_mode()

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


Setter

set_click_mask(value)

Getter

get_click_mask()

Pure black and white BitMap 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.


Setter

set_disabled_texture(value)

Getter

get_disabled_texture()

Texture to display when the node is disabled. See BaseButton.disabled.


Setter

set_focused_texture(value)

Getter

get_focused_texture()

Texture to display when the node has mouse or keyboard focus. texture_focused is displayed over the base texture, so 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.


Setter

set_hover_texture(value)

Getter

get_hover_texture()

Texture to display when the mouse hovers the node.


Setter

set_normal_texture(value)

Getter

get_normal_texture()

Texture to display by default, when the node is not in the disabled, focused, hover or pressed state.


Setter

set_pressed_texture(value)

Getter

get_pressed_texture()

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.