Skip to content

sprite

A 'sprite' is a simple struct for 2D drawing. It stores a rectangle (pos + size), UV coordinates, color, and layer, as well as an associated 'image' object. The sprite can be drawn via GPU or SDL_Renderer. Freed when no JS references remain.

set_affine(transform) function

Update this sprite's position and size from a transform's pos and scale.

transform: The transform whose pos/scale will overwrite the sprite's rect.

Returns: None

set_rect(rect) function

Set the sprite's rect (x, y, w, h) directly.

rect: An object or array specifying x, y, width, and height.

Returns: None

set_image(image) function

Assign or replace the sprite's underlying image. Automatically updates UV if the image has a 'rect' property.

image: A JS object representing the image (with .texture, .rect, etc.).

Returns: None

layer accessor

Get or set the sprite's z-layer integer. Sprites with higher layers typically draw on top of lower layers.

value: (when setting) An integer specifying the layer.

Returns: The current layer (when getting), or None (when setting).

color accessor

Get or set the sprite's color tint as [r, g, b, a].

value: (when setting) An array [r, g, b, a] in the 0.0..1.0 range.

Returns: The current color array (when getting), or None (when setting).