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.

Texture2D

繼承: Texture < Resource < RefCounted < Object

被繼承: AnimatedTexture, AtlasTexture, CameraTexture, CanvasTexture, CompressedTexture2D, CurveTexture, CurveXYZTexture, DPITexture, DrawableTexture2D, ExternalTexture, GradientTexture1D, GradientTexture2D, ImageTexture, MeshTexture, NoiseTexture2D, PlaceholderTexture2D, PortableCompressedTexture2D, Texture2DRD, ViewportTexture

用於 2D 和 3D 的紋理。

說明

紋理的工作原理是在影片硬體中註冊圖像,該圖像在註冊後就可以在 3D 模型、2D Sprite2D、GUI Control 中使用。

紋理通常是通過從檔中載入來建立的。見 @GDScript.load()

Texture2D 是其他資源的基底類別,無法直接使用。

注意:由於圖形硬體的限制,最大的紋理尺寸是 16384×16384 圖元。較大的紋理可能無法匯入。

方法

void

_draw(to_canvas_item: RID, pos: Vector2, modulate: Color, transpose: bool) virtual const

void

_draw_rect(to_canvas_item: RID, rect: Rect2, tile: bool, modulate: Color, transpose: bool) virtual const

void

_draw_rect_region(to_canvas_item: RID, rect: Rect2, src_rect: Rect2, modulate: Color, transpose: bool, clip_uv: bool) virtual const

Format

_get_format() virtual const

int

_get_height() virtual required const

Image

_get_image() virtual const

int

_get_mipmap_count() virtual const

int

_get_width() virtual required const

bool

_has_alpha() virtual const

bool

_has_mipmaps() virtual const

bool

_is_pixel_opaque(x: int, y: int) virtual const

Resource

create_placeholder() const

void

draw(canvas_item: RID, position: Vector2, modulate: Color = Color(1, 1, 1, 1), transpose: bool = false) const

void

draw_rect(canvas_item: RID, rect: Rect2, tile: bool, modulate: Color = Color(1, 1, 1, 1), transpose: bool = false) const

void

draw_rect_region(canvas_item: RID, rect: Rect2, src_rect: Rect2, modulate: Color = Color(1, 1, 1, 1), transpose: bool = false, clip_uv: bool = true) const

Format

get_format() const

int

get_height() const

Image

get_image() const

int

get_mipmap_count() const

Vector2

get_size() const

int

get_width() const

bool

has_alpha() const

bool

has_mipmaps() const


方法說明

void _draw(to_canvas_item: RID, pos: Vector2, modulate: Color, transpose: bool) virtual const 🔗

當請求在 CanvasItem 上繪製整個 Texture2D 時呼叫,左上角的偏移量由 pos 指定。modulate 指定繪製顏色的乘數,transpose 指定繪製是否應按列主順序而不是行主循序執行(會導致順時針旋轉 90 度)。

注意:僅用於 2D 算繪,不用於 3D。


void _draw_rect(to_canvas_item: RID, rect: Rect2, tile: bool, modulate: Color, transpose: bool) virtual const 🔗

請求將 Texture2D 繪製到 CanvasItem 的指定 rect 上時呼叫。modulate 指定的是繪製時顏色的乘數,而 transpose 指定的是繪製時是否使用列優先順序,而不是使用行優先順序(產生順時針 90 度旋轉)。

注意:僅在 2D 算繪時使用,3D 不使用。


void _draw_rect_region(to_canvas_item: RID, rect: Rect2, src_rect: Rect2, modulate: Color, transpose: bool, clip_uv: bool) virtual const 🔗

請求將 Texture2Dsrc_rect 的座標指定的部分繪製到 CanvasItem 的指定 rect 上時呼叫。modulate 指定的是繪製時顏色的乘數,而 transpose 指定的是繪製時是否使用列優先順序,而不是使用行優先順序(產生順時針 90 度旋轉)。

注意:僅在 2D 算繪時使用,3D 不使用。


Format _get_format() virtual const 🔗

Called when get_format() is called.


int _get_height() virtual required const 🔗

查詢該 Texture2D 的高度時呼叫。


Image _get_image() virtual const 🔗

Called when get_image() is called.


int _get_mipmap_count() virtual const 🔗

Called when get_mipmap_count() is called.


int _get_width() virtual required const 🔗

查詢該 Texture2D 的寬度時呼叫。


bool _has_alpha() virtual const 🔗

查詢該 Texture2D 是否存在 alpha 通道時呼叫。


bool _has_mipmaps() virtual const 🔗

Called when has_mipmaps() is called.


bool _is_pixel_opaque(x: int, y: int) virtual const 🔗

查詢 Texture2D 中指定位置 (x, y) 的圖元的不透明狀態時呼叫。


Resource create_placeholder() const 🔗

建立該資源的預留位置版本(PlaceholderTexture2D)。


void draw(canvas_item: RID, position: Vector2, modulate: Color = Color(1, 1, 1, 1), transpose: bool = false) const 🔗

使用 RenderingServer API 在 CanvasItem 上的指定位置 position 繪製該紋理。


void draw_rect(canvas_item: RID, rect: Rect2, tile: bool, modulate: Color = Color(1, 1, 1, 1), transpose: bool = false) const 🔗

使用 RenderingServer API 在 CanvasItem 上繪製該紋理。


void draw_rect_region(canvas_item: RID, rect: Rect2, src_rect: Rect2, modulate: Color = Color(1, 1, 1, 1), transpose: bool = false, clip_uv: bool = true) const 🔗

使用 RenderingServer API 在 CanvasItem 上繪製紋理的一部分。


Format get_format() const 🔗

Returns the image format of the texture.


int get_height() const 🔗

返回該紋理的高度,單位為圖元。


Image get_image() const 🔗

Returns an Image that is a copy of data from this Texture2D (a new Image is created each time). Images can be accessed and manipulated directly.

Note: This will return null if this Texture2D is invalid.

Note: This will fetch the texture data from the GPU, which might cause performance problems when overused. Avoid calling get_image() every frame, especially on large textures.


int get_mipmap_count() const 🔗

Returns the number of mipmaps of the texture.


Vector2 get_size() const 🔗

返回該紋理的大小,單位為圖元。


int get_width() const 🔗

返回該紋理的寬度,單位為圖元。


bool has_alpha() const 🔗

如果該 Texture2D 具有 Alpha 通道,則返回 true


bool has_mipmaps() const 🔗

Returns true if the texture has mipmaps.