2023-12-06 04:02:56 +01:00

71 lines
1.8 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>
<script src="../dist/iife/spine-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>Basic example</h1>
</body>
<script>
const config = {
type: Phaser.AUTO,
width: 800,
height: 600,
type: Phaser.WEBGL,
scene: {
preload: preload,
create: create,
pack: {
files: [
{
type: "scenePlugin",
key: "spine.SpinePlugin",
url: "../dist/iife/spine-phaser.js",
sceneKey: "spine",
},
],
},
},
};
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() {
const spineboy = this.add.spine(
250,
500,
"spineboy-data",
"spineboy-atlas"
);
spineboy.scale = 0.5;
spineboy.animationState.setAnimation(0, "walk", true);
const spineboy2 = this.add.spine(
550,
500,
"spineboy-data",
"spineboy-atlas"
);
spineboy2.scale = 0.5;
spineboy2.animationState.setAnimation(0, "run", true);
this.input.on(
"pointerdown",
() => (spineboy2.visible = !spineboy2.visible)
);
}
</script>
</html>