Rapid.js is published to npm under the package nameDocumentation 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.
rapid-render. It ships as a native ES module with a companion UMD bundle for environments that require CommonJS. TypeScript declarations are included in the package — no @types package is needed.
Install the Package
Import in Your Project
Import the classes and enums you need directly fromrapid-render. The package is fully tree-shakeable, so unused exports are removed by your bundler at build time.
TypeScript
JavaScript (ESM)
Rapid, Color, BlendMode, MaskType, TextureFilterMode, CanvasScaleMode, RenderTexture, Texture, TextureManager, MatrixStack, Vec2, CustomGlShader, and more. See the API reference for the complete list.
CDN / UMD Usage
If you are not using a bundler, thedist folder exposes two ready-to-use builds:
| File | Format | Use case |
|---|---|---|
dist/rapid.js | ES module | Modern bundlers, <script type="module"> |
dist/rapid.umd.cjs | UMD / CommonJS | Legacy bundlers, Node.js require() |
CDN via script module
Set Up the Canvas
Rapid.js renders into a standard HTML<canvas> element. Add one to your HTML file and give it an id so you can reference it from JavaScript.
HTML
width and height attributes set the canvas’s initial pixel dimensions. Rapid.js will resize the backing framebuffer based on the IAppOptions you pass to the constructor, so these attributes primarily serve as fallbacks.
Create the Rapid Instance
Pass anIAppOptions object to the Rapid constructor to configure the renderer. The only required field is canvas; all others have sensible defaults.
TypeScript
IAppOptions Reference
| Option | Type | Default | Description |
|---|---|---|---|
canvas | HTMLCanvasElement | (required) | The canvas element to render into. |
logicWidth | number | canvas CSS width | Logical viewport width in CSS pixels. All draw-call coordinates use this space. |
logicHeight | number | canvas CSS height | Logical viewport height in CSS pixels. |
physicsWidth | number | canvas CSS width × dpr | Actual GPU framebuffer width in device pixels. |
physicsHeight | number | canvas CSS height × dpr | Actual GPU framebuffer height in device pixels. |
backgroundColor | Color | Color.Black | Default clear color applied by rapid.clear(). |
antialias | boolean | false | Whether to enable MSAA antialiasing on the WebGL canvas. |
textureFilter | TextureFilterMode | NEAREST | Default texture sampling mode: LINEAR (smooth) or NEAREST (pixel-art). |
premultipliedAlpha | boolean | true | Whether textures are uploaded with premultiplied alpha. |
roundPixels | boolean | false | Snap sprite positions to integer pixels to avoid sub-pixel blurring. |
scaleMode | CanvasScaleMode | CanvasItem | How the canvas scales: CanvasItem (rasterize at display resolution) or Viewport (stretch the logical-size bitmap). |
Logical vs. Physical Dimensions
logicWidth / logicHeight define the coordinate space your game uses. Every draw call uses these units. physicsWidth / physicsHeight are the actual GPU pixel dimensions of the WebGL framebuffer — on HiDPI / Retina displays these are typically canvas CSS width × devicePixelRatio.
- Use
logicWidth/logicHeightwhen you want your game to work in consistent CSS-pixel coordinates on all screens. - Use
physicsWidth/physicsHeightwhen you need to control the exact GPU resolution, for example to lock a pixel-art game to its native resolution regardless of the display DPR.