mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2025-12-20 09:16:01 +08:00
75 lines
2.3 KiB
HTML
75 lines
2.3 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>
|
|
</head>
|
|
<style>
|
|
* {
|
|
margin: 0;
|
|
padding: 0;
|
|
}
|
|
|
|
body,
|
|
html {
|
|
height: 100%;
|
|
}
|
|
|
|
canvas {
|
|
position: absolute;
|
|
width: 100%;
|
|
height: 100%;
|
|
}
|
|
</style>
|
|
|
|
<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"]);
|
|
|
|
// Manually load the data and create a Spine display object from it using
|
|
// the Spine core API. This will not use the interal cache like Spine.from(),
|
|
// so you have to cache data yourself.
|
|
const atlas = PIXI.Assets.get("spineboyAtlas");
|
|
const attachmentLoader = new spine.AtlasAttachmentLoader(atlas);
|
|
const binaryLoader = new spine.SkeletonBinary(attachmentLoader);
|
|
binaryLoader.scale = 0.5;
|
|
const skeletonData = binaryLoader.readSkeletonData(
|
|
PIXI.Assets.get("spineboyData")
|
|
);
|
|
const spineboy = new spine.Spine(skeletonData);
|
|
|
|
// Set the default mix time to use when transitioning
|
|
// from one animation to the next.
|
|
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;
|
|
|
|
// Set animation "run" on track 0, looped.
|
|
spineboy.state.setAnimation(0, "run", true);
|
|
|
|
// Add the display object to the stage.
|
|
app.stage.addChild(spineboy);
|
|
})();
|
|
</script>
|
|
</body>
|
|
</html>
|