Core API (Render, Input, etc.)

Source: resources/modules/xs/core.wren


Class ShapeHandle ↗

Handle for shapes and sprites in the rendering system.

Used to correctly manage resources via the GC. Not to be created directly.


Class Render ↗

Core rendering API for sprites, shapes, text, and debug drawing

Provides functionality for rendering images, texts and shapes

static loadImage(path: String) -> Num ↗

Loads an image from a file and returns an image ID

Supports PNG and JPG formats. Use relative paths like "[game]/textures/flower.png"

static createImage(width: Num, height: Num, pixels: List) -> Num ↗

Creates a procedural image from pixel data and returns an image ID

pixels is a flat list of width*height packed RGBA values (use ImageBuilder.pack())

static loadShape(path: String) -> Num ↗

Loads a shape from a file and returns a shape ID

Supports SVG format

static loadFont(font: String, size: Num) -> Num ↗

Loads a font into a font atlas and returns a font ID

Font will be rasterized at the specified size

static getImageWidth(imageId: Num) -> Num ↗

Gets the width in pixels of a loaded image

static getImageHeight(imageId: Num) -> Num ↗

Gets the height in pixels of a loaded image

static createSprite(imageId: Num, x0: Num, y0: Num, x1: Num, y1: Num) -> Num ↗

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

Coordinates are normalized (0.0 to 1.0): x0, y0 (top-left), x1, y1 (bottom-right)

static createShape(imageId: Num, positions: List, textureCoords: List, indices: List) -> Num ↗

Creates a custom mesh shape from vertices, texture coordinates, and indices

static destroyShape(shapeId: Num) ↗

Destroys a shape and frees its resources

static setOffset(x: Num, y: Num) ↗

Sets the offset for subsequent sprite draw calls

All sprites will be offset by (x, y) until new values are set

static sprite(spriteId: Num, x: Num, y: Num, z: Num, scale: Num, rotation: Num, mul: Num, add: Num, flags: Num) ↗

Draws a sprite with full control over appearance

- spriteId: Valid sprite ID created with createSprite (not an image ID)

- x, y: Position on screen (affected by setOffset)

- z: Sorting depth value

- scale: Scaling factor

- rotation: Rotation angle in radians

- mul: Multiply color (0xRRGGBBAA format)

- add: Additive color (0xRRGGBBAA format)

- flags: Combination of sprite flags (spriteBottom, spriteCenter, etc.)

static shape(shapeId: Num, x: Num, y: Num, z: Num, scale: Num, rotation: Num, mul: Num, add: Num) ↗

Draws a shape at a position with transformation

static text(fontId: Num, txt: String, x: Num, y: Num, z: Num, mul: Num, add: Num, flags: Num) ↗

Draws text at a position with styling

Note: Text always renders above sprites currently

static spriteNone -> Num ↗

Don't apply any flags

static spriteBottom -> Num ↗

Draw the sprite at the bottom

static spriteTop -> Num ↗

Draw the sprite at the top

static spriteCenterX -> Num ↗

Center the sprite on the x-axis

static spriteCenterY -> Num ↗

Center the sprite on the y-axis

static spriteFlipX -> Num ↗

Flip the sprite on the x-axis

static spriteFlipY -> Num ↗

Flip the sprite on the y-axis

static spriteFixed -> Num ↗

Overlay the sprite as overlay (no offset applied)

static spriteCenter -> Num ↗

Center the sprite on the x and y-axis

static spriteShape -> Num ↗

This is not a sprite but a shape, so handle it differently

static lines -> Num ↗

Primitive type for line rendering

static triangles -> Num ↗

Primitive type for triangle rendering

static dbgBegin(primitive: Num) ↗

Begins a debug primitive batch

Call dbgVertex() to add vertices, then dbgEnd() to finish

Primitive can be lines or triangles

static dbgEnd() ↗

Ends a debug primitive batch and renders it

Number of vertices must match primitive type (divisible by 2 for lines, 3 for triangles)

static dbgVertex(x: Num, y: Num) ↗

Adds a vertex to the current debug primitive

Must be called between dbgBegin() and dbgEnd()

static dbgColor(color: Num) ↗

Sets the color for the next debug vertices

Color format: 0xRRGGBBAA (e.g., 0xF0C0D0FF)

static dbgLine(x0: Num, y0: Num, x1: Num, y1: Num) ↗

Draws a debug line from (x0, y0) to (x1, y1)

static dbgText(text: String, x: Num, y: Num, size: Num) ↗

Draws debug text on screen with specified size

Uses built-in debug font

static dbgLine(a: Vec2, b: Vec2) ↗

Draws a debug line between two vector points

static dbgRect(fromX: Num, fromY: Num, toX: Num, toY: Num) ↗

Draws a filled debug rectangle

static dbgSquare(centerX: Num, centerY: Num, size: Num) ↗

Draws a filled debug square centered at position

static dbgDisk(x: Num, y: Num, r: Num, divs: Num) ↗

Draws a filled debug circle (disk)

divs controls the number of triangular segments

static dbgCircle(x: Num, y: Num, r: Num, divs: Num) ↗

Draws a debug circle outline

divs controls the number of line segments

static dbgArc(x: Num, y: Num, r: Num, angle: Num, divs: Num) ↗

Draws a debug arc (partial circle outline)

angle is in radians, divs controls line segment count

static dbgPie(x: Num, y: Num, r: Num, angle: Num, divs: Num) ↗

Draws a filled debug pie/wedge shape

angle is in radians, divs controls triangle count

static dbgVertex(v: Vec2) ↗

Adds a vector point as a debug vertex

static sprite(spriteId: Num, x: Num, y: Num) ↗

Draws a sprite at position with default settings

Equivalent to: sprite(spriteId, x, y, 0.0, 1.0, 0.0, 0xFFFFFFFF, 0x00000000, spriteBottom)

static sprite(spriteId: Num, x: Num, y: Num, z: Num) ↗

Draws a sprite at position with z-sorting

static sprite(spriteId: Num, x: Num, y: Num, z: Num, flags: Num) ↗

Draws a sprite at position with z-sorting and custom flags

static createGridSprite(imageId: Num, columns: Num, rows: Num, c: Num, r: Num) -> Num ↗

Creates a sprite from a grid/sprite sheet by column and row

static createGridSprite(imageId: Num, columns: Num, rows: Num, idx: Num) -> Num ↗

Creates a sprite from a grid/sprite sheet by index

Index starts at 0 from top-left, going row by row


Class File ↗

File I/O operations

static read(src: String) -> String ↗

Reads the contents of a file as a string

static write(text: String, dst: String) ↗

Writes text content to a file

static exists(src: String) -> Bool ↗

Checks if a file exists at the given path


Class Json ↗

Fast JSON parsing and serialization (C++ implementation)

Much faster than the pure Wren json.wren parser

static load(path: String) ↗

Loads and parses a JSON file, returns the parsed value (Map, List, String, Num, Bool, or null)

Returns null if the file doesn't exist or parsing fails

static parse(jsonString: String) ↗

Parses a JSON string, returns the parsed value

Returns null if parsing fails

static save(path: String, value) -> Bool ↗

Saves a value to a JSON file with pretty formatting

Returns true on success, false on failure

Note: Map serialization has limited support

static stringify(value) -> String ↗

Converts a value to a JSON string with pretty formatting

Note: Map serialization has limited support


Class TouchData ↗

Data class for touch input information


Class Input ↗

Input handling for keyboard, mouse, gamepad, and touch

static getAxis(axis: Num) -> Num ↗

Gets the current value of a gamepad axis (-1.0 to 1.0)

static getAxisOnce(axis: Num, threshold: Num) -> Num ↗

Gets axis value once when it crosses threshold (prevents repeating)

static getButton(button: Num) -> Bool ↗

Checks if a gamepad button is currently pressed

static getButtonOnce(button: Num) -> Bool ↗

Checks if a gamepad button was just pressed (doesn't repeat while held)

static getKey(key: Num) -> Bool ↗

Checks if a keyboard key is currently pressed

static getKeyOnce(key: Num) -> Bool ↗

Checks if a keyboard key was just pressed (doesn't repeat while held)

static getMouse() ↗

Gets mouse state information

static getMouseButton(button: Num) -> Bool ↗

Checks if a mouse button is currently pressed

static getMouseButtonOnce(button: Num) -> Bool ↗

Checks if a mouse button was just pressed (doesn't repeat while held)

static getMouseX() -> Num ↗

Gets the current mouse X position in screen coordinates

static getMouseY() -> Num ↗

Gets the current mouse Y position in screen coordinates

static getMouseWheel() -> Num ↗

Gets the mouse wheel delta for this frame

static getNrTouches() -> Num ↗

Gets the number of active touch points

static getTouchId(index: Num) -> Num ↗

Gets the unique ID for a touch at the given index

static getTouchX(index: Num) -> Num ↗

Gets the X position for a touch at the given index

static getTouchY(index: Num) -> Num ↗

Gets the Y position for a touch at the given index

static setPadVibration(lowRumble: Num, highRumble: Num, time: Num) ↗

Sets gamepad vibration motors (DualSense, Xbox controllers)

time is in milliseconds

static setPadLightbarColor(red: Num, green: Num, blue: Num) ↗

Sets the gamepad lightbar color (DualSense controller)

Colors are 0-255

static resetPadLightbarColor() ↗

Resets gamepad lightbar to default color

static getTouchData() -> List ↗

Gets all touch data as a list of TouchData objects

static getTouchData(index: Num) -> TouchData ↗

Gets touch data for a specific touch index

static getMousePosition() -> List ↗

Gets the mouse position as a two-element list [x, y]


Class Audio ↗

Audio playback using FMOD

static load(name: String, groupId: Num) -> Num ↗

Loads a sound file into a group and returns a sound ID

static play(soundId: Num) -> Num ↗

Plays a loaded sound and returns a channel ID

static getGroupVolume(groupId: Num) -> Num ↗

Gets the volume level of a sound group (0.0 to 1.0)

static setGroupVolume(groupId: Num, volume: Num) ↗

Sets the volume level of a sound group (0.0 to 1.0)

static getChannelVolume(channelId: Num) -> Num ↗

Gets the volume level of a specific channel (0.0 to 1.0)

static setChannelVolume(channelId: Num, volume: Num) ↗

Sets the volume level of a specific channel (0.0 to 1.0)

static getBusVolume(busName: String) -> Num ↗

Gets the volume level of an FMOD bus by name (0.0 to 1.0)

static setBusVolume(busName: String, volume: Num) ↗

Sets the volume level of an FMOD bus by name (0.0 to 1.0)

static loadBank(bankId: String) ↗

Loads an FMOD sound bank

static unloadBank(bankId: String) ↗

Unloads an FMOD sound bank

static startEvent(eventName: String) -> Num ↗

Starts an FMOD event and returns an event instance ID

static setParameterNumber(eventId: Num, paramName: String, newValue: Num) ↗

Sets a numeric parameter on an FMOD event instance

static setParameterLabel(eventId: Num, paramName: String, newValue: String) ↗

Sets a labeled parameter on an FMOD event instance

static load(path: String) -> Num ↗

Load an audio file and return an audio id

static play(audioId: Num, volume: Num) -> Num ↗

Play a loaded audio file with specified volume (0.0 to 1.0)

static play(audioId: Num) -> Num ↗

Play a loaded audio file with default volume (1.0)

static setVolume(channelId: Num, volume: Num) ↗

Set the volume of a playing channel (0.0 to 1.0)

static getVolume(channelId: Num) -> Num ↗

Get the volume of a playing channel

static stop(channelId: Num) ↗

Stop a playing channel

static stopAll() ↗

Stop all playing channels

static isPlaying(channelId: Num) -> Bool ↗

Check if a channel is currently playing

static getNumber(name: String) -> Num ↗

Gets a number value from the game scope

static getColor(name: String) -> Num ↗

Gets a color value from the game scope

static getBool(name: String) -> Bool ↗

Gets a boolean value from the game scope

static getNumber(name: String, type: Num) -> Num ↗

Gets a number value from a specific data scope

static getColor(name: String, type: Num) -> Num ↗

Gets a color value from a specific data scope

static getBool(name: String, type: Num) -> Bool ↗

Gets a boolean value from a specific data scope

static getString(name: String, type: Num) -> String ↗

Gets a string value from a specific data scope

static setNumber(name: String, value: Num, type: Num) ↗

Sets a number value in a specific data scope

static setColor(name: String, value: Num, type: Num) ↗

Sets a color value in a specific data scope

static setBool(name: String, value: Bool, type: Num) ↗

Sets a boolean value in a specific data scope

static setString(name: String, value: String, type: Num) ↗

Sets a string value in a specific data scope

static save(type: Num) ↗

Saves all data of a specific data scope to its own file


Class Device ↗

Platform and device information

static getPlatform() -> Num ↗

Gets the current platform identifier

static canClose() -> Bool ↗

Checks if the application can be closed (always false on consoles)

static requestClose() ↗

Requests the application to close


Class Profiler ↗

CPU profiling utilities

static begin(name: String) ↗

Begins a named profiler section

static end(name: String) ↗

Ends a named profiler section


Class Inspector ↗

ImGui-based inspector utilities for entity debugging

static text(label: String) ↗

Displays text in the inspector

static treeNode(label: String) -> Bool ↗

Starts a collapsible tree node, returns true if open

static treePop() ↗

Ends a tree node (must be called if treeNode returned true)

static separator() ↗

Draws a horizontal separator line

static separatorText(text: String) ↗

Draws a horizontal separator line with text in the middle

static sameLine() ↗

Places the next widget on the same line

static indent() ↗

Increases indent level

static unindent() ↗

Decreases indent level

static spacing() ↗

Adds vertical spacing

static selectable(label: String, selected: Bool) -> Bool ↗

Selectable item for lists, returns true if clicked

static inputFloat(label: String, value: Num) -> Num ↗

Input field for float values, returns new value

static dragFloat(label: String, value: Num) -> Num ↗

Drag widget for float values, returns new value

static checkbox(label: String, value: Bool) -> Bool ↗

Checkbox for boolean values, returns new value

static collapsingHeader(label: String) -> Bool ↗

Creates a collapsing header section (cleaner than treeNode for headers)

Returns true if the section is open/expanded

static beginChild(label: String, width: Num, height: Num, border: Bool) ↗

Begins a child window region with optional border

width and height: size in pixels (0 = auto-size)

border: whether to draw a border around the child

static endChild() ↗

Ends the current child window region

Must be called after beginChild

static dragFloat2_(label: String, x: Num, y: Num) -> List ↗

Private: Drag widget for 2D float vector (x, y as separate params)

Returns a list [x, y] with the new values

static dragFloat2(label: String, vec: Vec2) -> Vec2 ↗

Drag widget for 2D vector, returns new Vec2 value

Works with xs_math Vec2 objects