Draws a sprite or a texture inside a User Interface. The texture can tile or not.
    public class TextureRect : Control

Use TextureRect to draw icons and sprites in your User Interfaces. To create panels and menu boxes, take a look at NinePatchFrame. Its Stretch Mode property controls the texture’s scale and placement. It can scale, tile and stay centered inside its bounding rectangle. TextureRect is one of the 5 most common nodes to create game UI.

Inheritance Chain


    public TextureRect()


    public bool Expand { get; set; }

If true, the texture scales to fit its bounding rectangle. Default value: false.

    public StretchModeEnum StretchMode { get; set; }

Controls the texture’s behavior when you resize the node’s bounding rectangle. Set it to one of the STRETCH_* constants. See the constants to learn more.

    public Texture Texture { get; set; }

The node’s Texture resource.


    public StretchModeEnum GetStretchMode()

Getter for StretchMode

    public Texture GetTexture()

Getter for Texture

    public bool HasExpand()

Getter for Expand

    public void SetExpand(bool enable)

Setter for Expand

    public void SetStretchMode(StretchModeEnum stretchMode)

Setter for StretchMode

    public void SetTexture(Texture texture)

Setter for Texture

Inner Types


Name Value Description
ScaleOnExpand 0 Scale to fit the node’s bounding rectangle, only if [code]expand[/code] is [code]true[/code]. Default [code]stretch_mode[/code], for backwards compatibility. Until you set [code]expand[/code] to [code]true[/code], the texture will behave like [code]STRETCH_KEEP[/code].
Scale 1 Scale to fit the node’s bounding rectangle.
Tile 2 Tile inside the node’s bounding rectangle.
Keep 3 The texture keeps its original size and stays in the bounding rectangle’s top-left corner.
KeepCentered 4 The texture keeps its original size and stays centered in the node’s bounding rectangle.
KeepAspect 5 Scale the texture to fit the node’s bounding rectangle, but maintain the texture’s aspect ratio.
KeepAspectCentered 6 Scale the texture to fit the node’s bounding rectangle, center it and maintain its aspect ratio.
KeepAspectCovered 7 Scale the texture so that the shorter side fits the bounding rectangle. The other side clips to the node’s limits.