Skip to main content

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

propertytypedefaultdescription
colorcolor[0.8,0.8,0.8,1]Tint, as channel floats or #rrggbb / #rrggbbaa
columnsfloat0Sheet grid columns for flipbook sprites; 0 means a single image At least 0.
flip_xboolfalseMirror horizontally
flip_yboolfalseMirror vertically
framefloat0Current sheet cell, counted left-to-right then top-to-bottom At least 0.
half_extentsvec2[0,0]Size override in world units; [0, 0] sizes from the texture
materialasset · materialThe material this draws with; empty draws with the built-in one
pixels_per_unitfloat100Texture pixels per world unit At least 0.01.
rowsfloat0Sheet grid rows for flipbook sprites; 0 means a single image At least 0.
texturestringImage 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:

methodwhat it does
color() -> float, float, float, floatThe 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, intThe texture path, sheet columns and rows, and current frame; empty and zeros when the node has no sprite.