@spritestudio/ssplayer-pixi-ui
v7.0.0-beta.1
Published
SpriteStudio Player for Web on PixiJS v8, as UI: a SpriteStudio animation as a @pixi/ui button whose states play its labels, hit-tested on its parts.
Readme
@spritestudio/ssplayer-pixi-ui
A SpriteStudio animation as a @pixi/ui button in a PixiJS v8 app.
SSButton is a ButtonContainer whose look is one animation: hover, press, keyboard focus and
enabled = false each play a section of it, and a pointer can be made to count only on some of its
parts.
Who this is for: apps on PixiJS v8 that want a button, a menu item or a toggle drawn by a SpriteStudio animation. Install:
npm install @spritestudio/ssplayer-pixi-ui @pixi/ui pixi.js(@pixi/ui@^2.4andpixi.js@^8.19are peer dependencies). It brings@spritestudio/ssplayer-pixiwith it and re-exports it, soSSPlayercomes from here too. Not what you need? → ssplayer-pixi to play animations without the button.
▶️ Live demo — two buttons drawn by Ringo, one taking a pointer only on the parts you pick.
Part of the SSPlayerForWeb monorepo. For the guide, see
UI buttons; the same pages for this
version are in this package's docs/ (start at docs/README.md), and in skills/ssplayer-pixi-ui/ as
an Agent Skill.
Quick start
Author the states in one animation: a label named after each state —
normal,hover,pressed,disabled,focused— where that state's loop starts. Each runs to the frame before the next label. A state without a label falls back (pressedtohover, the rest tonormal), and with no labels at all the whole animation plays.Convert the
.sspjas for any animation (Preparing assets).Make the button:
import { Application } from 'pixi.js'; import { SSButton, SSPlayer } from '@spritestudio/ssplayer-pixi-ui'; await SSPlayer.initialize(); // once for the whole app const app = new Application(); await app.init({ width: 1280, height: 720 }); document.body.appendChild(app.canvas); const start = new SSButton({ hitParts: ['face'], accessibleTitle: 'Start' }); await start.player.load('/ui/start/start.ssab'); start.position.set(640, 360); start.onPress.connect(() => console.log('start')); app.stage.addChild(start);
Under prefers-reduced-motion each state holds its first frame; normal, and the states that fall back
to it, play a reduced_motion label instead when the animation has one. Without accessibleTitle the button is
decoration to a screen reader.
Read next: UI buttons · PixiJS guide
License
BSD-3-Clause — see LICENSE.md.
For contributors — building from source
Consumers can stop here — everything below is for hacking on this package.
From the repo root, after the WASM is in place (see ssplayer-pixi):
pnpm run build # build all TS packages
pnpm --filter @spritestudio/ssplayer-pixi-ui test
pnpm run deploy-examples # once: the sample assets (not tracked in git)
pnpm --filter pixi-example dev # then open /ui.html