sprite
2d · render · 10 properties · 2D
A textured 2D quad at the node, sized from its image at pixels_per_unit texture pixels per world unit. A columns x rows sheet makes it a flipbook frame steps through.
In a scene, sprite is the node key that applies it. A script reaches the same properties through node.sprite.get() and node.sprite.set(table).
Properties
| property | type | default | description |
|---|---|---|---|
color | color | [0.8,0.8,0.8,1] | Tint, as channel floats or #rrggbb / #rrggbbaa |
columns | float | 0 | Sheet grid columns for flipbook sprites; 0 means a single image At least 0. |
flip_x | bool | false | Mirror horizontally |
flip_y | bool | false | Mirror vertically |
frame | float | 0 | Current sheet cell, counted left-to-right then top-to-bottom At least 0. |
half_extents | vec2 | [0,0] | Size override in world units; [0, 0] sizes from the texture |
material | asset · material | — | The material this draws with; empty draws with the built-in one |
pixels_per_unit | float | 100 | Texture pixels per world unit At least 0.01. |
rows | float | 0 | Sheet grid rows for flipbook sprites; 0 means a single image At least 0. |
texture | string | — | Image file, project-relative; required |
Asset types this component references: material.
Script functions
Methods of node.sprite, the handle a node carrying this component exposes. Each is also a free function on its module, taking the node as its first argument. Every handle also has get(), set(table), has() and remove().
From render:
| method | what it does |
|---|---|
color() -> float, float, float, float | The node's tint as r, g, b, a channel floats; opaque white when the node draws nothing at all. |
set_color(float, float, float, float?) | Tint whatever the node draws, as r, g, b channel floats and an optional alpha, one meaning opaque. |
set_sprite(string) | Draw the node as a quad textured with a project image, sized from it at 100 texture pixels per world unit. |
set_sprite_frame(int) | Show a sheet cell, numbered left to right then top to bottom; only the UVs move, so it is cheap per frame. |
set_sprite_sheet(string, int, int) | Draw the node as one cell of a columns-by-rows sheet, sizing the quad to a single frame, not the whole image. |
set_sprite_size(float, float) | Override the size the sprite took from its image, giving half-extents in world units instead. |
sprite() -> string, int, int, int | The texture path, sheet columns and rows, and current frame; empty and zeros when the node has no sprite. |