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 |
Resource | create_placeholder ( ) const2 |
void | draw ( canvas_item: RID , position: Vector2 , modulate: Color = Color(1, 1, 1, 1), transpose: bool = false ) const2 |
void | draw_rect ( canvas_item: RID , rect: Rect2 , tile: bool , modulate: Color = Color(1, 1, 1, 1), transpose: bool = false ) const2 |
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 |
int | get_height ( ) const2 |
Image | get_image ( ) const2 |
Vector2 | get_size ( ) const2 |
int | get_width ( ) const2 |
bool | has_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.
Returns the texture height in pixels.
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.
Returns the texture size in pixels.
Returns the texture width in pixels.
Returns true
if this Texture2D has an alpha channel.
本方法通常需要用户覆盖才能生效。
本方法无副作用,不会修改该实例的任何成员变量。
本方法除了能接受在此处描述的参数外,还能够继续接受任意数量的参数。
本方法用于构造某个类型。
调用本方法无需实例,可直接使用类名进行调用。
本方法描述的是使用本类型作为左操作数的有效运算符。
这个值是由下列位标志构成位掩码的整数。
无返回值。