Class Texture2D
- Namespace
- Godot
- Assembly
- GodotSharp.dll
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.
public class Texture2D : Texture, IDisposable
- Inheritance
-
Texture2D
- Implements
- Derived
- Inherited Members
Constructors
Texture2D()
public Texture2D()
Methods
CreatePlaceholder()
Creates a placeholder version of this resource (PlaceholderTexture2D).
public Resource CreatePlaceholder()
Returns
Draw(Rid, Vector2, Color?, bool)
Draws the texture using a CanvasItem with the RenderingServer API at the specified position
.
public void Draw(Rid canvasItem, Vector2 position, Color? modulate = null, bool transpose = false)
Parameters
canvasItem
Ridposition
Vector2modulate
Color?If the parameter is null, then the default value is
new Color(1, 1, 1, 1)
.transpose
bool
DrawRect(Rid, Rect2, bool, Color?, bool)
Draws the texture using a CanvasItem with the RenderingServer API.
public void DrawRect(Rid canvasItem, Rect2 rect, bool tile, Color? modulate = null, bool transpose = false)
Parameters
canvasItem
Ridrect
Rect2tile
boolmodulate
Color?If the parameter is null, then the default value is
new Color(1, 1, 1, 1)
.transpose
bool
DrawRectRegion(Rid, Rect2, Rect2, Color?, bool, bool)
Draws a part of the texture using a CanvasItem with the RenderingServer API.
public void DrawRectRegion(Rid canvasItem, Rect2 rect, Rect2 srcRect, Color? modulate = null, bool transpose = false, bool clipUV = true)
Parameters
canvasItem
Ridrect
Rect2srcRect
Rect2modulate
Color?If the parameter is null, then the default value is
new Color(1, 1, 1, 1)
.transpose
boolclipUV
bool
GetHeight()
Returns the texture height in pixels.
public int GetHeight()
Returns
GetImage()
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.
public Image GetImage()
Returns
GetSize()
Returns the texture size in pixels.
public Vector2 GetSize()
Returns
GetWidth()
Returns the texture width in pixels.
public int GetWidth()
Returns
HasAlpha()
Returns true
if this Texture2D has an alpha channel.
public bool HasAlpha()
Returns
HasGodotClassMethod(in godot_string_name)
Check if the type contains a method with the given name. This method is used by Godot to check if a method exists before invoking it. Do not call or override this method.
protected override bool HasGodotClassMethod(in godot_string_name method)
Parameters
method
godot_string_nameName of the method to check for.
Returns
HasGodotClassSignal(in godot_string_name)
Check if the type contains a signal with the given name. This method is used by Godot to check if a signal exists before raising it. Do not call or override this method.
protected override bool HasGodotClassSignal(in godot_string_name signal)
Parameters
signal
godot_string_nameName of the signal to check for.
Returns
InvokeGodotClassMethod(in godot_string_name, NativeVariantPtrArgs, out godot_variant)
Invokes the method with the given name, using the given arguments. This method is used by Godot to invoke methods from the engine side. Do not call or override this method.
protected override bool InvokeGodotClassMethod(in godot_string_name method, NativeVariantPtrArgs args, out godot_variant ret)
Parameters
method
godot_string_nameName of the method to invoke.
args
NativeVariantPtrArgsArguments to use with the invoked method.
ret
godot_variantValue returned by the invoked method.
Returns
_Draw(Rid, Vector2, Color, bool)
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.
public virtual void _Draw(Rid toCanvasItem, Vector2 pos, Color modulate, bool transpose)
Parameters
_DrawRect(Rid, Rect2, bool, Color, bool)
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.
public virtual void _DrawRect(Rid toCanvasItem, Rect2 rect, bool tile, Color modulate, bool transpose)
Parameters
_DrawRectRegion(Rid, Rect2, Rect2, Color, bool, bool)
Called when a part of the Texture2D specified by srcRect
'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.
public virtual void _DrawRectRegion(Rid toCanvasItem, Rect2 rect, Rect2 srcRect, Color modulate, bool transpose, bool clipUV)
Parameters
_GetHeight()
Called when the Texture2D's height is queried.
public virtual int _GetHeight()
Returns
_GetWidth()
Called when the Texture2D's width is queried.
public virtual int _GetWidth()
Returns
_HasAlpha()
Called when the presence of an alpha channel in the Texture2D is queried.
public virtual bool _HasAlpha()
Returns
_IsPixelOpaque(int, int)
Called when a pixel's opaque state in the Texture2D is queried at the specified (x, y)
position.
public virtual bool _IsPixelOpaque(int x, int y)