Appearance
Put an animation on your web page in five minutes
HereSplash publishes an animation as a small folder: an HTML page, the pixi-hm05 player, the animation's JSON and its pictures. You can upload the folder as it is, show it in an <iframe>, or play the animation inside a page of your own with one line of JavaScript.
1. Publish
- Open your document and choose File › Publish (Shift+F12).
- Leave Type on HTML online (the default). Publish scale (Fit to window / Keep 100%) and Publish align (Centre / Top left) decide how the stage sits in the page; Draw art outside the stage off means only what is inside the stage rectangle shows.
- Press Publish. The web editor downloads
<name>.zip; the desktop app writes the files to the project folder'soutput/.
You get:
text
index.html the page
pixi-hm05.js the player (global PixiHm05)
entry.js what the page runs when it opens
My_Animation.json the animation (runtime format)
atlas/ images/ … pictures, sounds, fonts, vectors (only the ones it uses)
My_Animation.scripts.js only when the document has player scripts
pixi-filters.js desktop app only, when the animation uses filtersindex.html loads pixi.js (from the jsDelivr CDN), the player, the page settings and entry.js. The default entry.js is one call:
js
PixiHm05.play("My_Animation.json", {
responsive: false,
scale: "fit",
align: "center",
overflow: false,
autoScale: true,
}).then(function (r) {
// for the browser console
window.app = r.app;
window.asset = r.asset;
window.clip = r.clip;
window.stage = r.stage;
window.sound = PixiHm05.sound;
});Open it from a web server
The page loads the JSON and pictures with fetch, which browsers refuse for file:// pages. Opened by double-click it shows "This page must be opened from a web server". Test it with any static server in the folder, for example npx serve, or upload the folder.
To get a page that plays from disk, choose Type › HTML offline (one file): one index.html holds pixi.js, the player and every picture and sound.
Pages published from the free web editor carry a small HereSplash watermark and are drawn at 1× resolution.
2. Embed it
In an iframe (no code)
Upload the folder (say to /animations/hero/) and point an <iframe> at it. Keep the trailing slash: the page loads its files relative to its own URL, and some servers (npx serve among them) redirect …/index.html to …/hero without one. With Fit to window the stage scales to the iframe's size.
html
<iframe
src="/animations/hero/"
title="Hero animation"
style="width: 100%; aspect-ratio: 16 / 9; border: 0"
></iframe>The player pauses itself while the iframe is scrolled out of view, and goes on when it comes back.
In your own page
Copy the player and the animation files next to your page (everything from the published folder except index.html and entry.js), load pixi.js and the player the same way index.html does, and call PixiHm05.play with a canvas option: a CSS selector (or an element) the canvas goes into. The canvas follows that element's size, so give it one.
html
<div id="hero" style="width: 640px; height: 360px"></div>
<script src="https://cdn.jsdelivr.net/npm/pixi.js@8.22.0/dist/pixi.min.js"></script>
<script src="/animations/hero/pixi-hm05.js"></script>
<script>
PixiHm05.play("/animations/hero/My_Animation.json", { canvas: "#hero" }).then(function (r) {
var clip = r.clip; // the main timeline (a SymbolInstance)
});
</script>- Pictures and sounds are loaded relative to the JSON's URL, so keep the folder together.
- If the published
index.htmlalso loads pixi-filters (the animation uses filters), copy that<script>tag too, after pixi.js. canvasmay also be a<canvas>element; it is then sized to its parent.- Options you leave out use the defaults: a fixed stage of the animation's size, fitted (
scale: "fit") and centred (align: "center"), clipped to the stage, at the screen's pixel density, on the stage colour of the document. The full list isStageOptionsplusscriptsandonProgressofLoadOptions. - Call
playonce per animation; each one gets its own canvas.
3. Control it
play resolves to a PlayResult: app (the pixi Application), stage, asset and clip, the main timeline. clip.timeline is the movie-clip API you know from Flash: frame numbers are the ones the editor's timeline shows (from 1), labels work wherever a frame does.
js
PixiHm05.play("/animations/hero/My_Animation.json", { canvas: "#hero" }).then(function (r) {
var clip = r.clip;
clip.timeline.gotoAndStop(1);
document.querySelector("#start").onclick = function () {
clip.timeline.gotoAndPlay("walk"); // a frame label of the main timeline
};
// a Playback action "emit" in the animation tells your page something happened
clip.on("land", function (e) {
console.log("landed at frame", e.frame, "with", e.value);
});
});clip.timeline:play(),stop(),gotoAndPlay,gotoAndStop,playTo,nextFrame,currentFrame,totalFrames,currentLabel,labels… — seeTimeline.- Named objects:
clip.find("door")returns the clip of the instance nameddoor,clip.findText("score")a live text whosetextyou can set. - Events: an emit action in the animation calls
clip.on(name, …)listeners on its clip and every clip holding it (ClipEvent:name,value,frame,section,target,stopPropagation()). - Sound:
PixiHm05.soundplays the animation's sounds. Browsers start sound only after the visitor touched the page, so an animation with sound shows a click-to-play cover first.
Banners without pixi.js: hm05-lite
For HTML5 display ads (Google Display Network), choose Type › GDN HTML5 banner. The page is then played by hm05-lite, a small SVG player (global Hm05Lite, no pixi.js) that keeps classic tweens, masks, colour effects, a few filters, nested clips and Playback actions. Its entry.js is the same idea:
js
Hm05Lite.play("Banner.json").then(function (r) {
r.clip.timeline.gotoAndPlay("loop");
});Hm05Lite.play(url, { host, scale, align, overflow, responsive, autoplay }) puts the <svg> into host (default: the page body).
With a bundler
The player is also the npm package pixi-hm05 (import { play, Asset } from "pixi-hm05", with pixi.js v8 as a peer dependency); the Asset class lets you load an animation and add its clips to a pixi application of your own:
ts
import { Application } from "pixi.js";
import { Asset } from "pixi-hm05";
const app = new Application();
await app.init({ width: 960, height: 540 });
document.body.appendChild(app.canvas);
const asset = await Asset.load("hero/My_Animation.json");
const hero = asset.create(); // the main timeline; asset.create("hero") = the symbol whose Script ID is "hero"
app.stage.addChild(hero);
hero.timeline.gotoAndPlay("walk");Not on npm yet
pixi-hm05 and hm05-lite are not published to npm yet. Until they are, use the pixi-hm05.js file Publish writes (it is the same player).
Next
- External player scripts: write Behaviours in VS Code.
- pixi-hm05 reference: every class and option.
- Runtime format: read the JSON in your own engine.