← Back to 2D Structs
Texture
⚠️ Experimental - Pre-Release
Texture represents a texture resource that can be used for rendering images. Textures are loaded from file paths and can be assigned to nodes like Sprite2D.
Methods
Texture.load(path: string) → Texture
Loads a texture from the specified file path. Returns a Texture handle that can be assigned to nodes.
@script Player extends Sprite2D fn init() { // Load texture from resource path self.texture = Texture.load("res://textures/player.png") }Texture.create_from_bytes(bytes: Array<int>, width: int, height: int) → Texture
Creates a texture from raw byte data with the specified width and height.
Texture.get_width(texture: Texture) → int
Returns the width of the texture in pixels.
var width = Texture.get_width(self.texture)Console.print("Texture width: " + width)Texture.get_height(texture: Texture) → int
Returns the height of the texture in pixels.
Texture.get_size(texture: Texture) → Vector2
Returns the size of the texture as a Vector2 (width, height).
var size = Texture.get_size(self.texture)
Console.print("Size: " + size.x + "x" + size.y)Usage Example
@script Sprite extends Sprite2D fn init() { // Load texture at initialization self.texture = Texture.load("res://sprites/enemy.png") } fn change_texture() { // Change texture at runtime self.texture = Texture.load("res://sprites/enemy_hurt.png") }Related
- Sprite2D- Node that uses Texture for rendering
- All 2D Structs
