ImageTexture

Hereda: Texture2D < Texture < Resource < RefCounted < Object

Una Texture2D basada en una Image.

Descripción

A Texture2D based on an Image. For an image to be displayed, an ImageTexture has to be created from it using the create_from_image() method:

var image = Image.load_from_file("res://icon.svg")
var texture = ImageTexture.create_from_image(image)
$Sprite2D.texture = texture

This way, textures can be created at run-time by loading images both from within the editor and externally.

Warning: Prefer to load imported textures with @GDScript.load() over loading them from within the filesystem dynamically with Image.load(), as it may not work in exported projects:

var texture = load("res://icon.svg")
$Sprite2D.texture = texture

This is because images have to be imported as a CompressedTexture2D first to be loaded with @GDScript.load(). If you'd still like to load an image file just like any other Resource, import it as an Image resource instead, and then load it normally using the @GDScript.load() method.

Note: The image can be retrieved from an imported texture using the Texture2D.get_image() method, which returns a copy of the image:

var texture = load("res://icon.svg")
var image = texture.get_image()

An ImageTexture is not meant to be operated from within the editor interface directly, and is mostly useful for rendering images on screen dynamically via code. If you need to generate images procedurally from within the editor, consider saving and importing images as custom texture resources implementing a new EditorImportPlugin.

Note: The maximum texture size is 16384×16384 pixels due to graphics hardware limitations.

Tutoriales

Propiedades

bool

resource_local_to_scene

false (overrides Resource)

Métodos

ImageTexture

create_from_image(image: Image) static

Format

get_format() const

void

set_image(image: Image)

void

set_size_override(size: Vector2i)

void

update(image: Image)


Descripciones de Métodos

ImageTexture create_from_image(image: Image) static 🔗

Crea una nueva ImageTexture y la inicializa asignando y estableciendo los datos de una Image.


Format get_format() const 🔗

Devuelve el formato de la textura.


void set_image(image: Image) 🔗

Reemplaza los datos de la textura con una nueva Image. Esto volverá a asignar nueva memoria para la textura.

Si quieres actualizar la imagen, pero no necesitas cambiar sus parámetros (formato, tamaño), usa update() en su lugar para un mejor rendimiento.


void set_size_override(size: Vector2i) 🔗

Redimensiona la ImageTexture a las dimensiones especificadas.


void update(image: Image) 🔗

Reemplaza los datos de la textura con una nueva Image.

Nota: La textura tiene que ser creada usando create_from_image() o inicializada primero con el método set_image() antes de que pueda ser actualizada. Las nuevas dimensiones de la imagen, el formato y la configuración de mipmaps deben coincidir con la configuración de la imagen de la textura existente.

Usa este método en lugar de set_image() si necesitas actualizar la textura con frecuencia, lo cual es más rápido que asignar memoria adicional para una nueva textura cada vez.