Skip to content

A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.

examples(spine-demo): new Spine skeletal-animation example

esengined6909b6a3a38
diff --git a/examples/ASSETS.md b/examples/ASSETS.md
index 6095bd686..37753efef 100644
--- a/examples/ASSETS.md
+++ b/examples/ASSETS.md
@@ -16,6 +16,15 @@ starting point for a real game. This credit is a courtesy, not an obligation.
| [UI Pack](https://kenney.nl/assets/ui-pack) | CC0 | sprite-rendering (arrow) |
| [Pixel Platformer](https://kenney.nl/assets/pixel-platformer) | CC0 | tilemap-demo (`tileset.png` terrain atlas; `props.png` is a handful of its tiles repacked into a second tileset) |
+## Spine
+
+`spine-demo` uses **Spineboy**, Esoteric Software's official Spine example skeleton
+(`spineboy-pro.skel` / `spineboy.atlas` / `spineboy.png`), © Esoteric Software LLC. Unlike
+the CC0 art above it is licensed under the **[Spine Runtimes License](https://esotericsoftware.com/spine-runtimes-license)**:
+using the Spine runtime (and this asset) requires your own Spine Editor license, and any
+redistribution must keep the copyright notice. It is **not** CC0 and not free to reuse the
+way the Kenney art is.
+
## Audio
`audio-demo` uses short synthesized drum one-shots (`assets/audio/*.wav`) generated for
diff --git a/examples/README.md b/examples/README.md
index 7801384f1..a567e8e45 100644
--- a/examples/README.md
+++ b/examples/README.md
@@ -17,6 +17,7 @@ for your own game.
| **event-system** | ECS | Decoupled gameplay with typed events — collect, score, react. |
| **sprite-rendering** | Rendering | Draw sprites with rotation, tint and flipping. |
| **sprite-animation** | Animation | Frame animation via `.esanim` clips with an idle/walk switcher. |
+| **spine-demo** | Animation | A Spine skeleton cycling idle/walk/run/jump/shoot (1-5 to switch). |
| **tween-animation** | Animation | Ease positions, scales and colors over time. |
| **input-demo** | Input | Keyboard, mouse and pointer input with a motion trail. |
| **audio-demo** | Audio | One-shot SFX and a beat visualizer driven by playback. |
@@ -45,6 +46,10 @@ The concept demos (ECS, events, tweens, collision, spinner) intentionally render
show *what the system is doing*, and it's the same convention most engine examples use.
The UI examples use the engine's built-in UI theme.
+**Exception — `spine-demo`.** It ships Esoteric Software's *Spineboy* under the **Spine
+Runtimes License** (not CC0). Using Spine at all requires your own Spine Editor license,
+so this asset is not free to reuse the way the CC0 art is — see [ASSETS.md](./ASSETS.md).
+
## Structure & conventions
See [ARCHITECTURE.md](./ARCHITECTURE.md) for the layout every example follows and the
diff --git a/examples/spine-demo/.gitignore b/examples/spine-demo/.gitignore
new file mode 100644
index 000000000..359472ac2
--- /dev/null
+++ b/examples/spine-demo/.gitignore
@@ -0,0 +1,7 @@
+node_modules/
+dist/
+.vscode/
+.idea/
+.DS_Store
+Thumbs.db
+.esengine/cache/
diff --git a/examples/spine-demo/assets/scenes/main.esscene b/examples/spine-demo/assets/scenes/main.esscene
new file mode 100644
index 000000000..856ec892e
--- /dev/null
+++ b/examples/spine-demo/assets/scenes/main.esscene
@@ -0,0 +1,43 @@
+{
+ "version": "1.0",
+ "name": "SpineDemo",
+ "entities": [
+ {
+ "id": 0,
+ "name": "Camera",
+ "parent": null,
+ "children": [],
+ "components": [
+ { "type": "Transform", "data": { "position": { "x": 0, "y": 0, "z": 10 } } },
+ { "type": "Camera", "data": { "projectionType": 1, "orthoSize": 300, "isActive": true, "priority": 0 } }
+ ],
+ "visible": true
+ },
+ {
+ "id": 1,
+ "name": "Spineboy",
+ "parent": null,
+ "children": [],
+ "components": [
+ { "type": "Transform", "data": { "position": { "x": 0, "y": -180, "z": 0 } } },
+ {
+ "type": "SpineAnimation",
+ "data": {
+ "skeletonPath": "assets/spine/spineboy-pro.skel",
+ "atlasPath": "assets/spine/spineboy.atlas",
+ "animation": "idle",
+ "skin": "default",
+ "loop": true,
+ "playing": true,
+ "skeletonScale": 0.6,
+ "color": { "r": 1, "g": 1, "b": 1, "a": 1 },
+ "layer": 0,
+ "enabled": true
+ }
+ },
+ { "type": "AnimState", "data": { "timer": 0, "index": 0 } }
+ ],
+ "visible": true
+ }
+ ]
+}
diff --git a/examples/spine-demo/assets/scenes/main.esscene.meta b/examples/spine-demo/assets/scenes/main.esscene.meta
new file mode 100644
index 000000000..b9b708eee
--- /dev/null
+++ b/examples/spine-demo/assets/scenes/main.esscene.meta
@@ -0,0 +1,8 @@
+{
+ "uuid": "fab0d42c-c44b-439a-abb5-6ede7fd9b6d1",
+ "version": "2.0",
+ "type": "scene",
+ "importer": {
+ "autoMigrate": true
+ }
+}
diff --git a/examples/spine-demo/assets/spine/spineboy-pro.skel b/examples/spine-demo/assets/spine/spineboy-pro.skel
new file mode 100644
index 000000000..09e564b7e
Binary files /dev/null and b/examples/spine-demo/assets/spine/spineboy-pro.skel differ
diff --git a/examples/spine-demo/assets/spine/spineboy.atlas b/examples/spine-demo/assets/spine/spineboy.atlas
new file mode 100644
index 000000000..eca542b71
--- /dev/null
+++ b/examples/spine-demo/assets/spine/spineboy.atlas
@@ -0,0 +1,94 @@
+spineboy.png
+ size: 1024, 256
+ filter: Linear, Linear
+ scale: 0.5
+crosshair
+ bounds: 352, 7, 45, 45
+eye-indifferent
+ bounds: 862, 105, 47, 45
+eye-surprised
+ bounds: 505, 79, 47, 45
+front-bracer
+ bounds: 826, 66, 29, 40
+front-fist-closed
+ bounds: 786, 65, 38, 41
+front-fist-open
+ bounds: 710, 51, 43, 44
+ rotate: 90
+front-foot
+ bounds: 210, 6, 63, 35
+front-shin
+ bounds: 665, 128, 41, 92
+ rotate: 90
+front-thigh
+ bounds: 2, 2, 23, 56
+ rotate: 90
+front-upper-arm
+ bounds: 250, 205, 23, 49
+goggles
+ bounds: 665, 171, 131, 83
+gun
+ bounds: 798, 152, 105, 102
+head
+ bounds: 2, 27, 136, 149
+hoverboard-board
+ bounds: 2, 178, 246, 76
+hoverboard-thruster
+ bounds: 722, 96, 30, 32
+ rotate: 90
+hoverglow-small
+ bounds: 275, 81, 137, 38
+mouth-grind
+ bounds: 614, 97, 47, 30
+mouth-oooo
+ bounds: 612, 65, 47, 30
+mouth-smile
+ bounds: 661, 64, 47, 30
+muzzle-glow
+ bounds: 382, 54, 25, 25
+muzzle-ring
+ bounds: 275, 54, 25, 105
+ rotate: 90
+muzzle01
+ bounds: 911, 95, 67, 40
+ rotate: 90
+muzzle02
+ bounds: 792, 108, 68, 42
+muzzle03
+ bounds: 956, 171, 83, 53
+ rotate: 90
+muzzle04
+ bounds: 275, 7, 75, 45
+muzzle05
+ bounds: 140, 3, 68, 38
+neck
+ bounds: 250, 182, 18, 21
+portal-bg
+ bounds: 140, 43, 133, 133
+portal-flare1
+ bounds: 554, 65, 56, 30
+portal-flare2
+ bounds: 759, 112, 57, 31
+ rotate: 90
+portal-flare3
+ bounds: 554, 97, 58, 30
+portal-shade
+ bounds: 275, 121, 133, 133
+portal-streaks1
+ bounds: 410, 126, 126, 128
+portal-streaks2
+ bounds: 538, 129, 125, 125
+rear-bracer
+ bounds: 857, 67, 28, 36
+rear-foot
+ bounds: 663, 96, 57, 30
+rear-shin
+ bounds: 414, 86, 38, 89
+ rotate: 90
+rear-thigh
+ bounds: 756, 63, 28, 47
+rear-upper-arm
+ bounds: 60, 5, 20, 44
+ rotate: 90
+torso
+ bounds: 905, 164, 49, 90
diff --git a/examples/spine-demo/assets/spine/spineboy.png b/examples/spine-demo/assets/spine/spineboy.png
new file mode 100644
index 000000000..0ea9737f3
Binary files /dev/null and b/examples/spine-demo/assets/spine/spineboy.png differ
diff --git a/examples/spine-demo/project.esproject b/examples/spine-demo/project.esproject
new file mode 100644
index 000000000..efc0be655
--- /dev/null
+++ b/examples/spine-demo/project.esproject
@@ -0,0 +1,13 @@
+{
+ "formatVersion": "1",
+ "name": "Spine Animation",
+ "description": "A Spine skeleton that cycles idle/walk/run/jump/shoot — press 1-5 to switch.",
+ "tag": "Animation",
+ "version": "0.1.0",
+ "defaultScene": "assets/scenes/main.esscene",
+ "designResolution": {
+ "width": 800,
+ "height": 600
+ },
+ "spineVersion": "4.2"
+}
diff --git a/examples/spine-demo/src/components.ts b/examples/spine-demo/src/components.ts
new file mode 100644
index 000000000..beaba8987
--- /dev/null
+++ b/examples/spine-demo/src/components.ts
@@ -0,0 +1,6 @@
+import { defineComponent } from 'esengine';
+
+export const AnimState = defineComponent('AnimState', {
+ timer: 0,
+ index: 0,
+});
diff --git a/examples/spine-demo/src/main.ts b/examples/spine-demo/src/main.ts
new file mode 100644
index 000000000..7688d596c
--- /dev/null
+++ b/examples/spine-demo/src/main.ts
@@ -0,0 +1,8 @@
+import { addSystemToSchedule, Schedule } from 'esengine';
+
+import './components';
+import { switchSystem } from './systems/switch';
+
+console.log('[spine-demo] press 1-5 to switch: idle / walk / run / jump / shoot');
+
+addSystemToSchedule(Schedule.Update, switchSystem);
diff --git a/examples/spine-demo/src/systems/switch.ts b/examples/spine-demo/src/systems/switch.ts
new file mode 100644
index 000000000..02017ed86
--- /dev/null
+++ b/examples/spine-demo/src/systems/switch.ts
@@ -0,0 +1,36 @@
+import {
+ defineSystem, Query, Mut, Res, Time, Input,
+ SpineAnimation,
+} from 'esengine';
+import { Spine } from 'esengine/spine';
+import { AnimState } from '../components';
+
+const CYCLE = ['idle', 'walk', 'run', 'jump', 'shoot'];
+const ONE_SHOT = new Set(['jump', 'shoot']); // played once, the skeleton settles back
+
+const HOLD_SECONDS = 2.5;
+
+export const switchSystem = defineSystem(
+ [Query(Mut(AnimState), SpineAnimation), Res(Spine), Res(Input), Res(Time)],
+ (query, spine, input, time) => {
+ for (const [entity, state] of query) {
+ let target = -1;
+ for (let i = 0; i < CYCLE.length; i++) {
+ if (input.isKeyPressed(`Digit${i + 1}`)) target = i;
+ }
+
+ state.timer += time.delta;
+ if (target < 0 && state.timer >= HOLD_SECONDS) {
+ target = (state.index + 1) % CYCLE.length;
+ }
+
+ if (target >= 0) {
+ state.index = target;
+ state.timer = 0;
+ const name = CYCLE[target];
+ spine.setAnimation(entity, name, !ONE_SHOT.has(name));
+ }
+ }
+ },
+ { name: 'SwitchSystem' }
+);
diff --git a/examples/spine-demo/tsconfig.json b/examples/spine-demo/tsconfig.json
new file mode 100644
index 000000000..713cf1ea2
--- /dev/null
+++ b/examples/spine-demo/tsconfig.json
@@ -0,0 +1,23 @@
+{
+ "compilerOptions": {
+ "target": "ES2020",
+ "module": "ESNext",
+ "moduleResolution": "bundler",
+ "strict": true,
+ "esModuleInterop": true,
+ "skipLibCheck": true,
+ "forceConsistentCasingInFileNames": true,
+ "declaration": false,
+ "outDir": "./dist",
+ "rootDir": ".",
+ "baseUrl": ".",
+ "paths": {
+ "esengine": ["./.esengine/sdk/index.d.ts"],
+ "esengine/wasm": ["./.esengine/sdk/wasm.d.ts"],
+ "esengine/spine": ["./.esengine/sdk/spine/index.d.ts"],
+ "@esengine/editor": ["./.esengine/editor/index.d.ts"]
+ }
+ },
+ "include": ["src/**/*"],
+ "exclude": ["node_modules"]
+}