Sprite2D

Hereda: Node2D < CanvasItem < Node < Object

Nodo de sprites de propósito general.

Descripción

Un nodo que muestra una textura 2D. La textura mostrada puede ser una región de una textura de atlas más grande, o un cuadro de una animación de hoja de sprite.

Tutoriales

Propiedades

bool

centered

true

bool

flip_h

false

bool

flip_v

false

int

frame

0

Vector2i

frame_coords

Vector2i(0, 0)

int

hframes

1

Vector2

offset

Vector2(0, 0)

bool

region_enabled

false

bool

region_filter_clip_enabled

false

Rect2

region_rect

Rect2(0, 0, 0, 0)

Texture2D

texture

int

vframes

1

Métodos

Rect2

get_rect() const

bool

is_pixel_opaque(pos: Vector2) const


Señales

frame_changed() 🔗

Emitida cuando frame cambia.


texture_changed() 🔗

Emitida cuando texture cambia.


Descripciones de Propiedades

bool centered = true 🔗

  • void set_centered(value: bool)

  • bool is_centered()

Si es true, la textura se centra.

Nota: Para juegos con una estética de pixel art, las texturas pueden aparecer deformadas cuando se centran. Esto se debe a que su posición está entre píxeles. Para evitar esto, establece esta propiedad en false, o considera habilitar ProjectSettings.rendering/2d/snap/snap_2d_vertices_to_pixel y ProjectSettings.rendering/2d/snap/snap_2d_transforms_to_pixel.


bool flip_h = false 🔗

  • void set_flip_h(value: bool)

  • bool is_flipped_h()

Si es true, la textura se voltea horizontalmente.


bool flip_v = false 🔗

  • void set_flip_v(value: bool)

  • bool is_flipped_v()

Si es true, la textura se voltea verticalmente.


int frame = 0 🔗

  • void set_frame(value: int)

  • int get_frame()

Fotograma actual que se mostrará de la hoja de sprite. hframes o vframes deben ser mayores que 1. Esta propiedad se ajusta automáticamente cuando se cambian hframes o vframes para seguir apuntando al mismo fotograma visual (misma columna y fila). Si eso es imposible, este valor se restablece a 0.


Vector2i frame_coords = Vector2i(0, 0) 🔗

Coordinates of the frame to display from sprite sheet. This is as an alias for the frame property. hframes or vframes must be greater than 1.


int hframes = 1 🔗

  • void set_hframes(value: int)

  • int get_hframes()

El número de columnas en la hoja de sprite. Cuando se cambia esta propiedad, frame se ajusta para que se mantenga el mismo fotograma visual (misma fila y columna). Si eso es imposible, frame se restablece a 0.


Vector2 offset = Vector2(0, 0) 🔗

El desplazamiento de dibujo de la textura.

Nota: Cuando aumentas offset.y en Sprite2D, el sprite se mueve hacia abajo en la pantalla (es decir, +Y es hacia abajo).


bool region_enabled = false 🔗

  • void set_region_enabled(value: bool)

  • bool is_region_enabled()

If true, texture is cut from a larger atlas texture. See region_rect.

Note: When using a custom Shader on a Sprite2D, the UV shader built-in will refer to the entire texture space. Use the REGION_RECT built-in to get the currently visible region defined in region_rect instead. See CanvasItem shaders for details.


bool region_filter_clip_enabled = false 🔗

  • void set_region_filter_clip_enabled(value: bool)

  • bool is_region_filter_clip_enabled()

Si es true, el área fuera de region_rect se recorta para evitar el sangrado de los píxeles de la textura circundante. region_enabled debe ser true.


Rect2 region_rect = Rect2(0, 0, 0, 0) 🔗

  • void set_region_rect(value: Rect2)

  • Rect2 get_region_rect()

La región de la textura del atlas a mostrar. region_enabled debe ser true.


Texture2D texture 🔗

Objeto Texture2D a dibujar.


int vframes = 1 🔗

  • void set_vframes(value: int)

  • int get_vframes()

El número de filas en la hoja de sprites. Cuando se cambia esta propiedad, frame se ajusta para que se mantenga el mismo cuadro visual (misma fila y columna). Si eso es imposible, frame se restablece a 0.


Descripciones de Métodos

Rect2 get_rect() const 🔗

Returns a Rect2 representing the Sprite2D's boundary in local coordinates.

Example: Detect if the Sprite2D was clicked:

func _input(event):
    if event is InputEventMouseButton and event.pressed and event.button_index == MOUSE_BUTTON_LEFT:
        if get_rect().has_point(to_local(event.position)):
            print("A click!")

bool is_pixel_opaque(pos: Vector2) const 🔗

Devuelve true si el píxel en la posición dada es opaco y false en caso contrario. La posición está en coordenadas locales.

Nota: También devuelve false si la textura del sprite es null o si la posición dada no es válida.