mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2025-12-22 10:16:01 +08:00
79 lines
2.2 KiB
HTML
79 lines
2.2 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8" />
|
|
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
<script src="//cdn.jsdelivr.net/npm/phaser@3.60.0/dist/phaser.js"></script>
|
|
<link rel="stylesheet" href="../../index.css" />
|
|
<title>Spine Phaser Example</title>
|
|
</head>
|
|
|
|
<body class="p-4 flex flex-col items-center">
|
|
<h1>Blend test</h1>
|
|
</body>
|
|
<script>
|
|
const config = {
|
|
type: Phaser.AUTO,
|
|
width: 800,
|
|
height: 600,
|
|
type: Phaser.WEBGL,
|
|
backgroundColor: "#cdcdcd",
|
|
scene: {
|
|
preload: preload,
|
|
create: create,
|
|
update: update,
|
|
pack: {
|
|
files: [
|
|
{
|
|
type: "scenePlugin",
|
|
key: "spine.SpinePlugin",
|
|
url: "../dist/iife/spine-phaser.js",
|
|
sceneKey: "spine",
|
|
},
|
|
],
|
|
},
|
|
},
|
|
};
|
|
|
|
let controls;
|
|
const game = new Phaser.Game(config);
|
|
|
|
function preload() {
|
|
this.load.spineBinary("spineboy-data", "assets/spineboy-pro.skel");
|
|
this.load.spineAtlas("spineboy-atlas", "assets/spineboy-pma.atlas");
|
|
}
|
|
|
|
function create() {
|
|
for (var i = 0; i < 4; i++) {
|
|
const obj = this.add
|
|
.spine(i * 200, 600, "spineboy-data", "spineboy-atlas")
|
|
.setScale(0.25);
|
|
obj.setScale(0.25);
|
|
obj.animationState.setAnimation(0, "idle", true);
|
|
obj.animationState.setAnimation(1, "shoot", true);
|
|
}
|
|
const cursors = this.input.keyboard.createCursorKeys();
|
|
|
|
const controlConfig = {
|
|
camera: this.cameras.main,
|
|
left: cursors.left,
|
|
right: cursors.right,
|
|
up: cursors.up,
|
|
down: cursors.down,
|
|
zoomIn: this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.Q),
|
|
zoomOut: this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.E),
|
|
acceleration: 0.35,
|
|
drag: 0.01,
|
|
maxSpeed: 1.2,
|
|
};
|
|
|
|
controls = new Phaser.Cameras.Controls.SmoothedKeyControl(controlConfig);
|
|
}
|
|
|
|
function update(time, delta) {
|
|
controls.update(delta);
|
|
}
|
|
</script>
|
|
</html>
|