2023-12-22 13:06:25 -04:00

63 lines
2.2 KiB
HTML

<html>
<head>
<meta charset="UTF-8" />
<title>spine-pixi</title>
<script src="https://cdn.jsdelivr.net/npm/pixi.js@7.2.4/dist/pixi.min.js"></script>
<script src="../dist/iife/spine-pixi.js"></script>
<script src="https://cdn.jsdelivr.net/npm/tweakpane@3.1.9/dist/tweakpane.min.js"></script>
<link rel="stylesheet" href="../../index.css">
</head>
<body>
<script>
(async function () {
var app = new PIXI.Application({
width: window.innerWidth,
height: window.innerHeight,
resolution: window.devicePixelRatio || 1,
autoDensity: true,
resizeTo: window,
backgroundColor: 0x2c3e50,
hello: true,
});
document.body.appendChild(app.view);
// Pre-load the skeleton data and atlas. You can also load .json skeleton data.
PIXI.Assets.add("spineboyData", "./assets/spineboy-pro.skel");
PIXI.Assets.add("spineboyAtlas", "./assets/spineboy-pma.atlas");
await PIXI.Assets.load(["spineboyData", "spineboyAtlas"]);
// Create the spine display object
const spineboy = spine.Spine.from("spineboyData", "spineboyAtlas", {
scale: 0.5,
});
// Set the default animation and the
// default mix for transitioning between animations.
spineboy.state.setAnimation(0, "run", true);
spineboy.state.data.defaultMix = 0.2;
// Center the spine object on screen.
spineboy.x = window.innerWidth / 2;
spineboy.y = window.innerHeight / 2 + spineboy.getBounds().height / 2;
// Make it so that you can interact with Spineboy.
// Also, handle the case that you click or tap on the screen.
// The callback function definition can be seen below.
spineboy.eventMode = 'static';
spineboy.on('pointerdown', onClick);
// Add the display object to the stage.
app.stage.addChild(spineboy);
// This callback function handles what happens
// when you click or tap on the screen.
function onClick() {
spineboy.state.addAnimation(0, "jump", false, 0);
spineboy.state.addAnimation(0, "idle", true, 0);
}
})();
</script>
</body>
</html>