|
@@ -5,27 +5,22 @@
|
|
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/pixi.min.js"></script>
|
|
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/pixi.min.js"></script>
|
|
<script src="../dist/iife/spine-pixi.js"></script>
|
|
<script src="../dist/iife/spine-pixi.js"></script>
|
|
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/tweakpane.min.js"></script>
|
|
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/tweakpane.min.js"></script>
|
|
|
|
+ <link rel="stylesheet" href="../../index.css">
|
|
</head>
|
|
</head>
|
|
- <style>
|
|
|
|
- * {
|
|
|
|
- margin: 0;
|
|
|
|
- padding: 0;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- body,
|
|
|
|
- html {
|
|
|
|
- height: 100%;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- canvas {
|
|
|
|
- position: absolute;
|
|
|
|
- width: 100%;
|
|
|
|
- height: 100%;
|
|
|
|
- }
|
|
|
|
- </style>
|
|
|
|
|
|
|
|
<body>
|
|
<body>
|
|
|
|
+ <!-- Creates a transparent logging overlay. -->
|
|
|
|
+ <div id="log" class="overlay" style="user-select: none;" max-height: 300px; overflow: auto;>
|
|
|
|
+ </div>
|
|
|
|
+
|
|
<script>
|
|
<script>
|
|
|
|
+ function log(message) {
|
|
|
|
+ const log = document.querySelector("#log");
|
|
|
|
+ log.innerText += message + "\n";
|
|
|
|
+ log.scrollTop = log.scrollHeight;
|
|
|
|
+ console.log(message);
|
|
|
|
+ }
|
|
|
|
+
|
|
(async function () {
|
|
(async function () {
|
|
var app = new PIXI.Application({
|
|
var app = new PIXI.Application({
|
|
width: window.innerWidth,
|
|
width: window.innerWidth,
|
|
@@ -43,11 +38,33 @@
|
|
PIXI.Assets.add("spineboyAtlas", "./assets/spineboy-pma.atlas");
|
|
PIXI.Assets.add("spineboyAtlas", "./assets/spineboy-pma.atlas");
|
|
await PIXI.Assets.load(["spineboyData", "spineboyAtlas"]);
|
|
await PIXI.Assets.load(["spineboyData", "spineboyAtlas"]);
|
|
|
|
|
|
- // Create the spine display object
|
|
|
|
|
|
+ // Create the Spine display object
|
|
const spineboy = spine.Spine.from("spineboyData", "spineboyAtlas", {
|
|
const spineboy = spine.Spine.from("spineboyData", "spineboyAtlas", {
|
|
scale: 0.5,
|
|
scale: 0.5,
|
|
});
|
|
});
|
|
|
|
|
|
|
|
+ // Set animation "run" on track 0, looped.
|
|
|
|
+ spineboy.state.setAnimation(0, "run", true);
|
|
|
|
+
|
|
|
|
+ // Set callbacks to receive animation state events.
|
|
|
|
+ spineboy.state.addListener({
|
|
|
|
+ start: (entry) => log(`Started animation ${entry.animation.name}`),
|
|
|
|
+ interrupt: (entry) => log(`Interrupted animation ${entry.animation.name}`),
|
|
|
|
+ end: (entry) => log(`Ended animation ${entry.animation.name}`),
|
|
|
|
+ dispose: (entry) => log(`Disposed animation ${entry.animation.name}`),
|
|
|
|
+ complete: (entry) => log(`Completed animation ${entry.animation.name}`),
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ // Add a custom event listener along with an
|
|
|
|
+ // unlooped animation to see the custom event logged.
|
|
|
|
+ const trackEntry = spineboy.state.addAnimation(0, "walk", false, 3);
|
|
|
|
+ trackEntry.listener = {
|
|
|
|
+ event: (entry, event) =>
|
|
|
|
+ log(`Custom event for ${entry.animation.name}: ${event.data.name}`),
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ spineboy.state.addAnimation(0, "run", true, 0);
|
|
|
|
+
|
|
// Set the default mix time to use when transitioning
|
|
// Set the default mix time to use when transitioning
|
|
// from one animation to the next.
|
|
// from one animation to the next.
|
|
spineboy.state.data.defaultMix = 0.2;
|
|
spineboy.state.data.defaultMix = 0.2;
|
|
@@ -56,11 +73,6 @@
|
|
spineboy.x = window.innerWidth / 2;
|
|
spineboy.x = window.innerWidth / 2;
|
|
spineboy.y = window.innerHeight / 2 + spineboy.getBounds().height / 2;
|
|
spineboy.y = window.innerHeight / 2 + spineboy.getBounds().height / 2;
|
|
|
|
|
|
- // Set animation "run" on track 0, looped.
|
|
|
|
- spineboy.state.setAnimation(0, "run", true);
|
|
|
|
-
|
|
|
|
- // Set callbacks to receive animation state events
|
|
|
|
-
|
|
|
|
// Add the display object to the stage.
|
|
// Add the display object to the stage.
|
|
app.stage.addChild(spineboy);
|
|
app.stage.addChild(spineboy);
|
|
})();
|
|
})();
|