Skip to content

JavaScript

Copy as Markdown
  1. Install the player.

    Terminal window
    npm i @rupamotion/player
  2. Put hero.rupaplay (export as Player file in Rupamotion) in public/ (or wherever your build serves static files), and an empty element in the page:

    <div id="hero"></div>
  3. Mount the file into it. markup: "auto" writes the file’s markup into the empty element:

    import { mountFile } from "@rupamotion/player/file";
    await mountFile(document.querySelector("#hero"), "/hero.rupaplay", { markup: "auto" });

That’s it: the animation plays.

This demo loads a .rupaplay file: it plays once JavaScript runs.

mountFile resolves { player } or { error }. Keep the player to control it:

import { mountFile } from "@rupamotion/player/file";
const root = document.querySelector("#hero");
if (root) {
const { player, error } = await mountFile(root, "/hero.rupaplay", { markup: "auto" });
if (error) console.warn(error.message);
else player.play();
}

mountFile never rejects: it resolves { player } or { error }. Call player.destroy() when you take the root out of the page. See control playback, events and errors.