Texture2D

继承: Texture < Resource < RefCounted < Object

派生: AnimatedTexture, AtlasTexture, CameraTexture, CanvasTexture, CompressedTexture2D, CurveTexture, CurveXYZTexture, ExternalTexture, GradientTexture1D, GradientTexture2D, ImageTexture, MeshTexture, NoiseTexture2D, PlaceholderTexture2D, PortableCompressedTexture2D, Texture2DRD, ViewportTexture

Texture for 2D and 3D.

描述

A texture works by registering an image in the video hardware, which then can be used in 3D models or 2D Sprite2D or GUI Control.

Textures are often created by loading them from a file. See @GDScript.load.

Texture2D is a base for other resources. It cannot be used directly.

Note: The maximum texture size is 16384×16384 pixels due to graphics hardware limitations. Larger textures may fail to import.

方法

void_draw ( to_canvas_item: RID, pos: Vector2, modulate: Color, transpose: bool ) virtual1 const2
void_draw_rect ( to_canvas_item: RID, rect: Rect2, tile: bool, modulate: Color, transpose: bool ) virtual1 const2
void_draw_rect_region ( to_canvas_item: RID, rect: Rect2, src_rect: Rect2, modulate: Color, transpose: bool, clip_uv: bool ) virtual1 const2
int_get_height ( ) virtual1 const2
int_get_width ( ) virtual1 const2
bool_has_alpha ( ) virtual1 const2
bool_is_pixel_opaque ( x: int, y: int ) virtual1 const2
Resourcecreate_placeholder ( ) const2
voiddraw ( canvas_item: RID, position: Vector2, modulate: Color = Color(1, 1, 1, 1), transpose: bool = false ) const2
voiddraw_rect ( canvas_item: RID, rect: Rect2, tile: bool, modulate: Color = Color(1, 1, 1, 1), transpose: bool = false ) const2
voiddraw_rect_region ( canvas_item: RID, rect: Rect2, src_rect: Rect2, modulate: Color = Color(1, 1, 1, 1), transpose: bool = false, clip_uv: bool = true ) const2
intget_height ( ) const2
Imageget_image ( ) const2
Vector2get_size ( ) const2
intget_width ( ) const2
boolhas_alpha ( ) const2

方法说明

void _draw ( to_canvas_item: RID, pos: Vector2, modulate: Color, transpose: bool ) virtual1 const2

Called when the entire Texture2D is requested to be drawn over a CanvasItem, with the top-left offset specified in pos. modulate specifies a multiplier for the colors being drawn, while transpose specifies whether drawing should be performed in column-major order instead of row-major order (resulting in 90-degree clockwise rotation).

Note: This is only used in 2D rendering, not 3D.


void _draw_rect ( to_canvas_item: RID, rect: Rect2, tile: bool, modulate: Color, transpose: bool ) virtual1 const2

Called when the Texture2D is requested to be drawn onto CanvasItem's specified rect. modulate specifies a multiplier for the colors being drawn, while transpose specifies whether drawing should be performed in column-major order instead of row-major order (resulting in 90-degree clockwise rotation).

Note: This is only used in 2D rendering, not 3D.


void _draw_rect_region ( to_canvas_item: RID, rect: Rect2, src_rect: Rect2, modulate: Color, transpose: bool, clip_uv: bool ) virtual1 const2

Called when a part of the Texture2D specified by src_rect's coordinates is requested to be drawn onto CanvasItem's specified rect. modulate specifies a multiplier for the colors being drawn, while transpose specifies whether drawing should be performed in column-major order instead of row-major order (resulting in 90-degree clockwise rotation).

Note: This is only used in 2D rendering, not 3D.


int _get_height ( ) virtual1 const2

Called when the Texture2D's height is queried.


int _get_width ( ) virtual1 const2

Called when the Texture2D's width is queried.


bool _has_alpha ( ) virtual1 const2

Called when the presence of an alpha channel in the Texture2D is queried.


bool _is_pixel_opaque ( x: int, y: int ) virtual1 const2

Called when a pixel's opaque state in the Texture2D is queried at the specified (x, y) position.


Resource create_placeholder ( ) const2

Creates a placeholder version of this resource (PlaceholderTexture2D).


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

Draws the texture using a CanvasItem with the RenderingServer API at the specified position.


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

Draws the texture using a CanvasItem with the RenderingServer API.


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

Draws a part of the texture using a CanvasItem with the RenderingServer API.


int get_height ( ) const2

Returns the texture height in pixels.


Image get_image ( ) const2

Returns an Image that is a copy of data from this Texture2D (a new Image is created each time). Image s 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.


Vector2 get_size ( ) const2

Returns the texture size in pixels.


int get_width ( ) const2

Returns the texture width in pixels.


bool has_alpha ( ) const2

Returns true if this Texture2D has an alpha channel.

1

本方法通常需要用户覆盖才能生效。

2

本方法无副作用,不会修改该实例的任何成员变量。

3

本方法除了能接受在此处描述的参数外,还能够继续接受任意数量的参数。

4

本方法用于构造某个类型。

5

调用本方法无需实例,可直接使用类名进行调用。

6

本方法描述的是使用本类型作为左操作数的有效运算符。

7

这个值是由下列位标志构成位掩码的整数。

8

无返回值。