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.

TextureRect

繼承: Control < CanvasItem < Node < Object

顯示紋理的控制項。

說明

顯示紋理的控制項,例如顯示 GUI 中的圖示。可以使用 stretch_mode 屬性控制紋理的放置。可以在邊界框中進行縮放、平鋪、居中。

教學

屬性

ExpandMode

expand_mode

0

bool

flip_h

false

bool

flip_v

false

MouseFilter

mouse_filter

1 (overrides Control)

StretchMode

stretch_mode

0

Texture2D

texture


列舉

enum ExpandMode: 🔗

ExpandMode EXPAND_KEEP_SIZE = 0

最小尺寸將等於紋理尺寸,即 TextureRect 不能小於紋理。

ExpandMode EXPAND_IGNORE_SIZE = 1

紋理尺寸不會用於計算最小尺寸,所以 TextureRect 可以縮減得比紋理尺寸小。

ExpandMode EXPAND_FIT_WIDTH = 2

會忽略紋理的高度。最小寬度與目前高度一致。可用於橫向佈局,例如在 HBoxContainer 中。

ExpandMode EXPAND_FIT_WIDTH_PROPORTIONAL = 3

EXPAND_FIT_WIDTH 相同,但保持紋理的長寬比。

ExpandMode EXPAND_FIT_HEIGHT = 4

會忽略紋理的寬度。最小高度與目前寬度一致。可用於縱向佈局,例如在 VBoxContainer 中。

ExpandMode EXPAND_FIT_HEIGHT_PROPORTIONAL = 5

EXPAND_FIT_HEIGHT 相同,但保持紋理的長寬比。


enum StretchMode: 🔗

StretchMode STRETCH_SCALE = 0

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

StretchMode STRETCH_TILE = 1

Tile inside the node's bounding rectangle.

Note: STRETCH_TILE mode is not supported for texture set to an AtlasTexture with non-zero AtlasTexture.margin.

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

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


屬性說明

ExpandMode expand_mode = 0 🔗

實驗性: Using EXPAND_FIT_WIDTH, EXPAND_FIT_WIDTH_PROPORTIONAL, EXPAND_FIT_HEIGHT, or EXPAND_FIT_HEIGHT_PROPORTIONAL may result in unstable behavior in some Container controls. This behavior may be re-evaluated and changed in the future.

Defines how minimum size is determined based on the texture's size.


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,紋理將垂直翻轉。


StretchMode stretch_mode = 0 🔗

Controls the texture's behavior when resizing the node's bounding rectangle.


Texture2D texture 🔗

該節點的 Texture2D 資源。