Every draw call in Rapid.js accepts anDocumentation 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.
ITransformOptions object that describes position, rotation, scale, and pivot point. For simple cases you can pass these fields directly on the draw call options. For hierarchical scenes — cameras, grouped objects, skeleton animations — you work with rapid.matrixStack directly, pushing and popping transform state just like a 2D canvas context.
Inline Transforms on Draw Calls
The simplest way to transform a sprite is to pass transform fields directly todrawSprite (or any other draw function). The engine resolves the full world matrix before submitting the vertices.
ITransformOptions Reference
Horizontal translation in logical pixels. Applied before rotation and scale.
Vertical translation in logical pixels. Applied before rotation and scale.
Position as a
Vec2. Additive with x / y when both are provided.Rotation angle in radians. Positive values rotate clockwise in screen space (Y-down).
Uniform scale as a
number, or per-axis scale as a Vec2. A value of 2 doubles the size; 0.5 halves it.Local X offset applied after rotation and scale. Useful for nudging a sprite relative to its already-transformed origin without affecting the pivot.
Local Y offset applied after rotation and scale.
Local offset as a
Vec2. Additive with offsetX / offsetY.Normalized pivot point used for rotation and scaling.
0 is the top-left corner; 0.5 is the center; 1 is the bottom-right. Pass a Vec2 for independent X/Y pivots. The engine multiplies this value against the sprite’s width and height and subtracts it from the local offset, so the sprite rotates around that point.When
true (the default), applyTransform pushes a new level onto the matrix stack before applying the transform, and the caller is responsible for calling matrixStack.restore(). Set to false to mutate the current matrix level in place — useful for deferred / retained-mode patterns where you want to update a matrix slot without changing stack depth.An optional callback invoked immediately after the matrix stack save (if
saveTransform is true). Use it to read the just-saved matrix index for later use with updateMatrix.MatrixStack: Manual Save and Restore
For any case where you need to apply a shared transform to a group of draw calls, userapid.matrixStack directly. The API mirrors the HTML Canvas 2D context.
| Method | Description |
|---|---|
save() | Pushes a copy of the current world matrix onto the stack. |
restore() | Pops the stack, reverting to the matrix state at the last save(). |
translate(x, y) | Translates the current matrix by (x, y). |
rotate(radians) | Rotates the current matrix by the given angle. |
scale(scaleX, scaleY?) | Scales the current matrix. scaleY defaults to scaleX when omitted. |
identity() | Resets the current matrix to the identity transform. |
rapid.clear() calls matrixStack.reset() internally, which discards the entire stack and resets to identity. Never rely on matrix state surviving across frames.withTransform Convenience Wrapper
rapid.withTransform() is a helper that saves the matrix stack, optionally applies a full ITransformOptions transform (including origin resolution), calls your callback, and then restores — all with a guaranteed finally block so the stack is never left in a corrupt state even if the callback throws.
width and height of the object being transformed. These are used to resolve the origin anchor into a pixel offset — pass texture.width and texture.height for sprites.
You can also use it without a transform for a clean save/restore block:
Camera Pattern with renderCamera
rapid.renderCamera(transform) applies a transform to the matrix stack and then immediately inverts it. The result is that all subsequent world-space draw calls are offset as if the viewport has been moved or rotated — a zero-overhead scrolling camera.
rotateWithOffset: Rotating Around a Joint
matrixStack.rotateWithOffset(radians, offsetX, offsetY) rotates the current matrix around a pivot point that is offset from the current origin. Internally it translates to the pivot, rotates, and translates back — exactly the pattern needed for skeletal/limb animation.
translate → rotate → translate-back:
rotateWithOffset is cleaner and avoids off-by-one errors when composing multiple transforms.
localToWorld and worldToLocal
The matrix stack exposes two coordinate-space conversion helpers that are essential for hit testing and pointer input.
matrixStack.curWorldM). Call them while the relevant transform is active — i.e. between a save() / restore() pair that includes the object’s transforms.
updateMatrix: Deferred / Retained-Mode Transforms
For scene graphs where you want to record a matrix slot during scene traversal and update it later (without re-traversing the full tree), use updateMatrix.
matrixStack.save() returns an object { world, local, step }. Store the step value, then call matrixStack.updateMatrix(step) whenever the object’s local transform changes. Rapid will recompute the subtree rooted at that node without touching the rest of the frame.