Texture2D
Texture for 2D and 3D.
Texture2D.swift:18class Texture2D
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.
Superclasses
class Texture
Base class for all texture types.
Citizens in SwiftGodot
Conformances
protocol CustomStringConvertible
A type with a customized textual representation.
protocol Equatable
A type that can be compared for value equality.
protocol Hashable
A type that can be hashed into a
Hasher
to produce an integer hash value.protocol Identifiable<ID>
A class of types whose instances hold the value of an entity with stable identity.
protocol VariantRepresentable
Types that conform to VariantRepresentable can be stored directly in
Variant
with no conversion. These include all of the Variant types from Godot (for exampleGString
,Rect
,Plane
), Godot objects (those that subclass SwiftGodot.Object) as well as the built-in Swift types UInt8, Int64 and Double.protocol VariantStorable
Types that conform to VariantStorable can be stored in a Variant and can be extracted back out of a Variant.
Type members
Instance members
func createPlaceholder(
) -> Resource? Creates a placeholder version of this resource (
PlaceholderTexture2D
).func draw(canvasItem: RID, position: Vector2, modulate: Color, transpose: Bool
) Draws the texture using a
CanvasItem
with theRenderingServer
API at the specifiedposition
.func drawRect(canvasItem: RID, rect: Rect2, tile: Bool, modulate: Color, transpose: Bool
) Draws the texture using a
CanvasItem
with theRenderingServer
API.func drawRectRegion(canvasItem: RID, rect: Rect2, srcRect: Rect2, modulate: Color, transpose: Bool, clipUv: Bool
) Draws a part of the texture using a
CanvasItem
with theRenderingServer
API.func getHeight(
) -> Int32 Returns the texture height in pixels.
func getImage(
) -> Image? Returns an
Image
that is a copy of data from thisTexture2D
(a newImage
is created each time).Image
s can be accessed and manipulated directly.func getSize(
) -> Vector2 Returns the texture size in pixels.
func getWidth(
) -> Int32 Returns the texture width in pixels.
func hasAlpha(
) -> Bool Returns
true
if thisTexture2D
has an alpha channel.
Show implementation details (7)
Hide implementation details
func _draw(toCanvasItem: RID, pos: Vector2, modulate: Color, transpose: Bool
) Called when the entire
Texture2D
is requested to be drawn over aCanvasItem
, with the top-left offset specified inpos
.modulate
specifies a multiplier for the colors being drawn, whiletranspose
specifies whether drawing should be performed in column-major order instead of row-major order (resulting in 90-degree clockwise rotation).func _drawRect(toCanvasItem: RID, rect: Rect2, tile: Bool, modulate: Color, transpose: Bool
) Called when the
Texture2D
is requested to be drawn ontoCanvasItem
’s specifiedrect
.modulate
specifies a multiplier for the colors being drawn, whiletranspose
specifies whether drawing should be performed in column-major order instead of row-major order (resulting in 90-degree clockwise rotation).func _drawRectRegion(toCanvasItem: RID, rect: Rect2, srcRect: Rect2, modulate: Color, transpose: Bool, clipUv: Bool
) Called when a part of the
Texture2D
specified bysrcRect
’s coordinates is requested to be drawn ontoCanvasItem
’s specifiedrect
.modulate
specifies a multiplier for the colors being drawn, whiletranspose
specifies whether drawing should be performed in column-major order instead of row-major order (resulting in 90-degree clockwise rotation).func _getHeight(
) -> Int32 Called when the
Texture2D
’s height is queried.func _getWidth(
) -> Int32 Called when the
Texture2D
’s width is queried.func _hasAlpha(
) -> Bool Called when the presence of an alpha channel in the
Texture2D
is queried.func _isPixelOpaque(x: Int32, y: Int32
) -> Bool Called when a pixel’s opaque state in the
Texture2D
is queried at the specified(x, y)
position.
Subclasses
class AnimatedTexture
Proxy texture for simple frame-based animations.
class AtlasTexture
A texture that crops out part of another Texture2D.
class CameraTexture
Texture provided by a
CameraFeed
.class CanvasTexture
Texture with optional normal and specular maps for use in 2D rendering.
class CompressedTexture2D
Texture with 2 dimensions, optionally compressed.
class CurveTexture
A 1D texture where pixel brightness corresponds to points on a curve.
class CurveXYZTexture
A 1D texture where the red, green, and blue color channels correspond to points on 3 curves.
class GradientTexture1D
A 1D texture that uses colors obtained from a
Gradient
.class GradientTexture2D
A 2D texture that creates a pattern with colors obtained from a
Gradient
.class ImageTexture
A
Texture2D
based on anImage
.class MeshTexture
Simple texture that uses a mesh to draw itself.
class NoiseTexture2D
A 2D texture filled with noise generated by a
Noise
object.class PlaceholderTexture2D
Placeholder class for a 2-dimensional texture.
class PortableCompressedTexture2D
Provides a compressed texture for disk and/or VRAM in a way that is portable.
class Texture2DRD
Texture for 2D that is bound to a texture created on the
RenderingDevice
.class ViewportTexture
Provides the content of a
Viewport
as a dynamic texture.