Getting Started
The Cavalry Web Player is currently in beta and so subject to change.
Intro
The Cavalry Web Player is a WebAssembly-based runtime for rendering and playing Cavalry animations (.cv files) in web browsers.
Create bespoke, fully customisable animations that can be viewed and exported from modern web browsers. With native support for Cavalry’s extensive features, designers and animators can now work unshackled by the limits of formats like Lottie meaning non-technical teams can create and deliver design systems to their clients in a light-weight, easy to use format.
The Web Player API can be used to update Layer attributes from a Scene embedded in the Web Player.
Check out this fantastic project by the amazing team at Algo in collaboration with various artists on scenery.io using the Web Player to get a flavour of the kinds of things that are possible.
The example below is a custom integration that uses the Web Player and the API to load a .cv file along with a custom UI which can be used to update the Scene based on Attributes added to the Control Centre.
Quick Start
Download the Cavalry Web Player↓ Download- Download the Cavalry Web Player package.
- Unzip.
- Start the included server:
# macOS
cd /path/to/cavalry-web-player
# Windows
cd \path\to\cavalry-web-player
python3 serve.py - Open a browser window and load localhost:8000.
- Try the 'Minimal Player' example, load a
.cvscene file and use the playback controls.
Integration
Integration Example
// Import the Cavalry module
const CavalryModule = await import('/CavalryWasm.js');
// Initialise the module
const Module = await CavalryModule.default({
locateFile: (path) => `/wasm-lib/${path}`,
canvas: document.getElementById('canvas')
});
// Load a scene file
Module.FS.writeFile('scene.cv', sceneData);
const app = Module.Cavalry.MakeWithPath('scene.cv');
// Set up rendering surface
const canvas = document.getElementById('canvas');
let surface = Module.makeWebGLSurfaceFromElement(canvas, 800, 600);
// Render current frame
app.render(surface);
// Start playback
app.play();
// Animation loop using requestAnimationFrame (for display sync and power efficient playback)
let animationFrameId = null;
function runPlaybackLoop() {
const tick = (timestamp) => {
if (!app.isPlaying()) return;
// tick() advances the frame based on elapsed time and renders
const status = app.tick(surface, timestamp);
// Optionally update UI when frame changes
if (status.frameChanged) {
console.log(`Frame: ${status.currentFrame}`);
}
animationFrameId = requestAnimationFrame(tick);
};
animationFrameId = requestAnimationFrame(tick);
}
runPlaybackLoop();
// To stop playback:
// app.stop();
// cancelAnimationFrame(animationFrameId);
Server Requirements
For production deployment, ensure your server:
- Sets proper MIME types:
Content-Type: application/wasmfor.wasmfilesContent-Type: application/javascriptfor.jsfiles
- Serves over HTTPS.
File Size Optimisation
The Cavalry Web Player files are relatively large due to the comprehensive feature set. We intend to work on reducing the size in the future, however for now, if file size is an issue, you can:
- Pre-compress the
.wasmfile with gzip. - Set
Content-Encoding: gzipheader. - Use a CDN for better distribution.
- Most servers automatically compress these files.
Browser Compatibility
Requirements:
- WebAssembly support
- WebGL 2.0
- Modern JavaScript (ES6 modules)
Multiplayer Functionality
Multiple Cavalry Web Players can be used on the same page, simply add more than one player modules to your page. The demos contain lots of examples of making player modules.
Shadow Dom
Web Player supports usage inside a Shadow DOM, where the canvas element is hidden from the public DOM. This can be configured via shadowHost and Shadow DOM settings in your HTML. See demos.
Video Assets
We include a video example which demonstrates playing back video with the Web Player. Please see webcodec-helper.js file as a starting point if further features are required. See demos.
Notes
Scene files (.cv) should be saved to a minimum of file version 1.0.55 which is supported from Cavalry 2.5.0.
Unsupported features:
- Audio (audio support is in progress).
Unsupported Layers: