Skip to content
Download
API reference

TextureButton

Inherits: BaseButton < Control < CanvasItem < Actor < Object

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

TextureButton has the same functionality as Button, except it uses sprites instead of Gobu’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 actor.

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).

TypeNameDefault
boolflip_hfalse
boolflip_vfalse
boolignore_texture_sizefalse
TextureButton.StretchModestretch_mode2
BitMaptexture_click_mask
Texture2Dtexture_disabled
Texture2Dtexture_focused
Texture2Dtexture_hover
Texture2Dtexture_normal
Texture2Dtexture_pressed

  • STRETCH_SCALE = 0 — Scale to fit the actor’s bounding rectangle.

  • STRETCH_TILE = 1 — Tile inside the actor’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 actor’s bounding rectangle.

  • STRETCH_KEEP_ASPECT = 4 — Scale the texture to fit the actor’s bounding rectangle, but maintain the texture’s aspect ratio.

  • STRETCH_KEEP_ASPECT_CENTERED = 5 — Scale the texture to fit the actor’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 actor’s limits.

bool flip_h = false

Setter/getter: set_flip_h(), is_flipped_h()

If true, texture is flipped horizontally.

bool flip_v = false

Setter/getter: set_flip_v(), is_flipped_v()

If true, texture is flipped vertically.

bool ignore_texture_size = false

Setter/getter: set_ignore_texture_size(), 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.

TextureButton.StretchMode stretch_mode = 2

Setter/getter: set_stretch_mode(), get_stretch_mode()

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

BitMap texture_click_mask

Setter/getter: set_click_mask(), 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.

Texture2D texture_disabled

Setter/getter: set_texture_disabled(), get_texture_disabled()

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

Texture2D texture_focused

Setter/getter: set_texture_focused(), get_texture_focused()

Texture to overlay on the base texture when the actor 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

Setter/getter: set_texture_hover(), get_texture_hover()

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

Texture2D texture_normal

Setter/getter: set_texture_normal(), get_texture_normal()

Texture to display by default, when the actor is not in the disabled, hover or pressed state. This texture is still displayed in the focused state, with texture_focused drawn on top.

Texture2D texture_pressed

Setter/getter: set_texture_pressed(), get_texture_pressed()

Texture to display on mouse down over the actor, if the actor 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.