Sprites are the primary drawing primitive in Rapid.js. Every image you display — a character, a background tile, a UI icon — is drawn as a sprite quad that maps aDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/Nightre/Rapid.js/llms.txt
Use this file to discover all available pages before exploring further.
Texture onto two GPU triangles. Under the hood, Rapid batches sprites that share the same texture atlas into a single instanced draw call, so you can render thousands of sprites per frame without thrashing the GPU.
Drawing a Basic Sprite
Load a texture throughrapid.texture.load() (or create one synchronously with rapid.texture.create()), then pass it to drawSprite. The quad is placed at the world origin by default.
ISpriteOptions Reference
drawSprite accepts a single options object that combines sprite-specific fields with the shared ITransformOptions.
Sprite fields
The texture to render. Must be a valid
Texture instance returned by rapid.texture.load(), rapid.texture.create(), or splitGrid().A tint color multiplied against every texel. Defaults to opaque white (
0xFFFFFFFF), which renders the texture unchanged. Set the alpha channel below 255 for transparency.Mirrors the sprite horizontally by swapping UV coordinates on the X axis. Defaults to
false.Mirrors the sprite vertically. The final flip is XOR’d with any
flipY flag stored on the texture itself (e.g. from a RenderTexture). Defaults to false.Extra pixels added around the rendered quad. This expands the quad beyond the texture’s logical size so that filter shaders (blur, glow, outline) have room to sample neighbouring pixels without clipping. Only needed when pairing
drawSprite with a custom filter shader; leave it unset for normal sprites.A custom
GLShader or CustomGlShader that overrides the region’s default program for this draw call. Use this to apply per-sprite effects such as dissolve, palette swap, or outline.Transform fields (ITransformOptions)
All transform fields are optional. When none are provided, no matrix push/pop is performed, making the call as cheap as possible.Horizontal position in logical pixels.
Vertical position in logical pixels.
Position as a
Vec2. Equivalent to setting x and y together.Rotation in radians, applied around the
origin anchor.Uniform scale as a number, or non-uniform scale as a
Vec2. A value of 2 doubles both axes.Normalized anchor point used for rotation and scale (0 = top-left corner, 0.5 = center, 1 = bottom-right corner). A single number applies to both axes; a
Vec2 sets them independently.Additional pixel offset applied along the X axis after all other transforms.
Additional pixel offset applied along the Y axis after all other transforms.
Combined pixel offset as a
Vec2. Equivalent to setting offsetX and offsetY together.Whether to push/pop the matrix stack around this call. Defaults to
true. Set to false if you want subsequent draw calls to inherit the transformed state.Positioning and Transforming Sprites
Passx, y, rotation, scale, and origin directly in the options object. The origin field is a normalized anchor: 0 is the top-left corner, 0.5 centers around the sprite’s midpoint.
Color Tinting
Thecolor field multiplies each pixel of the texture by the given color. Use this for hit-flash effects, transparency, or colorizing a grayscale sprite.
Color.White (the default) leaves the texture unchanged. Setting alpha to 0 makes the sprite invisible.
Flipping Sprites
UseflipX and flipY to mirror a sprite without needing a separate texture asset. This is useful for characters that need to face left or right.
flipY is XOR’d with the flipY flag stored on the texture object. RenderTexture instances have flipY = true by default to correct the framebuffer’s inverted Y axis, so setting flipY: true on the options will cancel that and render the texture upright.Sprite Sheet Animation
Usetexture.splitGrid() to slice a sprite sheet into an array of Texture sub-regions. Each sub-texture shares the same underlying GPU resource — no extra uploads.
splitGrid(cellWidth, cellHeight, cols?, rows?) reads left-to-right, top-to-bottom. You can pass explicit cols and rows to limit the region it slices.
Custom Shaders
Pass ashader to override the sprite region’s default program for a single draw call. This lets you apply per-sprite screen-space effects without switching pipelines globally.
Performance: Instanced Batching
Rapid uses GPU instancing for sprites. EachdrawSprite call appends transform and UV data to a CPU-side typed array. All sprites that share the same texture and shader are flushed together in one drawArraysInstanced call when the texture or shader changes.
The drawcallCount property on the Rapid instance tracks how many draw calls were issued in the last frame — useful for profiling: