Built-in Components

Source: assets/modules/xs_components.wren


Class Transform

Component that stores position and rotation for an entity

construct new(position)

Creates a new Transform at the given position with zero rotation

position

Gets the position as a Vec2

position=(p)

Sets the position

rotation

Gets the rotation in radians

rotation=(r)

Sets the rotation in radians


Class Body

Component that provides size and velocity for physics-based movement

construct new(size, velocity)

Creates a new Body with the given size and velocity

size

Gets the size of the body

velocity

Gets the velocity as a Vec2

size=(s)

Sets the size of the body

velocity=(v)

Sets the velocity

update(dt)

Updates the position based on velocity and delta time


Class Renderable

Base class for all renderable components with layer-based sorting

construct new()

Creates a new Renderable with default layer 0

render()

Override this method in subclasses to implement rendering

<(other)

Comparison operator for sorting by layer

layer

Gets the rendering layer (higher values render on top)

layer=(l)

Sets the rendering layer

static render()

Renders all Renderable components in all entities


Class Sprite

Renders a sprite from an image or texture atlas

construct new(image)

Creates a sprite from a full image (path or image ID)

construct new(image, s0, t0, s1, t1)

Creates a sprite from a section of an image using normalized texture coordinates

initialize()

Initializes by caching reference to Transform component

render()

Renders the sprite at the Transform's position and rotation

add

Gets the additive color (0xRRGGBBAA format)

add=(a)

Sets the additive color

mul

Gets the multiply color (0xRRGGBBAA format)

mul=(m)

Sets the multiply color

flags

Gets the sprite flags (flipping, centering, etc.)

flags=(f)

Sets the sprite flags

scale

Gets the sprite scale

scale=(s)

Sets the sprite scale

sprite_=(s)

Sets the sprite ID

sprite

Gets the sprite ID


Class Shape

Renders a shape (SVG or custom mesh)

construct new(shape)

Creates a Shape component with the given shape ID

render()

Renders the shape at the Transform's position and rotation

add

Gets the additive color (0xRRGGBBAA format)

add=(a)

Sets the additive color

mul

Gets the multiply color (0xRRGGBBAA format)

mul=(m)

Sets the multiply color

flags

Gets the shape flags

flags=(f)

Sets the shape flags

scale

Gets the shape scale

scale=(s)

Sets the shape scale

shape=(s)

Sets the shape ID

shape

Gets the shape ID


Class Label

Renders text using a loaded font

construct new(font, text, size)

Creates a Label with the given font (path or font ID), text content, and size

render()

Renders the text at the Transform's position

text

Gets the text content

text=(t)

Sets the text content


Class GridSprite

Sprite that can display frames from a sprite sheet grid

construct new(image, columns, rows)

Creates a GridSprite from an image divided into columns and rows

idx=(i)

Sets the current frame index

idx

Gets the current frame index

[i]

Gets the sprite ID at the given frame index


Class AnimatedSprite

Sprite with animation support for playing frame sequences from a sprite sheet

Use addAnimation() to define named animations, then playAnimation() to start them

Call update(dt) each frame to advance the animation

construct new(image, columns, rows, fps)

Creates an AnimatedSprite with the given frame rate (frames per second)

fps determines how fast animations play - higher values = faster animations

update(dt)

Updates the animation frame based on delta time

addAnimation(name, frames)

Adds a named animation with a list of frame indices

Frame indices correspond to positions in the sprite sheet (0-indexed, left to right, top to bottom)

Example: addAnimation("walk", [0, 1, 2, 3])

playAnimation(name)

Plays the animation with the given name, restarting from the first frame

Does nothing if the animation name doesn't exist

randomizeFrame(random)

Randomizes the current frame within the current animation

mode

Gets the animation mode

mode=(m)

Sets the animation mode (once, loop, or destroy)

isDone

Checks if animation has finished (for non-looping animations)

static once

Play animation once and stop on the last frame

static loop

Loop animation continuously (default behavior)

static destroy

Delete the owning entity when animation completes (useful for effects)


Class Relation

Makes an entity follow its parent's position with an offset

construct new(parent)

Creates a Relation that follows the given parent entity

update(dt)

Updates position to follow parent (with rotation support)

offset

Gets the offset from parent position

offset=(o)

Sets the offset from parent position

parent

Gets the parent entity


Class Ownership

Deletes this entity when its parent is deleted

construct new(parent)

Creates an Ownership component tied to the given parent entity

update(dt)

Checks if parent is deleted and deletes this entity if so

parent

Gets the parent entity