mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-02-04 22:34:53 +08:00
71 lines
2.1 KiB
HTML
71 lines
2.1 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.55.2/dist/phaser.js"></script>
|
|
<script src="../dist/iife/spine-phaser.js"></script>
|
|
<title>Spine Phaser Example</title>
|
|
</head>
|
|
<body>
|
|
<h1>Control bones</h1>
|
|
<script>
|
|
var config = {
|
|
type: Phaser.AUTO,
|
|
width: 800,
|
|
height: 600,
|
|
type: Phaser.WEBGL,
|
|
scene: {
|
|
preload: preload,
|
|
create: create,
|
|
},
|
|
plugins: {
|
|
scene: [
|
|
{ key: "spine.SpinePlugin", plugin: spine.SpinePlugin, mapping: "spine" }
|
|
]
|
|
}
|
|
};
|
|
|
|
let game = new Phaser.Game(config);
|
|
|
|
function preload () {
|
|
this.load.spineBinary("stretchyman-data", "assets/stretchyman-pro.skel");
|
|
this.load.spineAtlas("stretchyman-atlas", "assets/stretchyman-pma.atlas");
|
|
}
|
|
|
|
function create () {
|
|
let stretchyman = this.add.spine(400, 550, 'stretchyman-data', "stretchyman-atlas");
|
|
stretchyman.scale = 0.8;
|
|
stretchyman.skeleton.updateWorldTransform();
|
|
|
|
var controlBones = ["back-arm-ik-target", "back-leg-ik-target", "front-arm-ik-target", "front-leg-ik-target"];
|
|
for (var i = 0; i < controlBones.length; i++)
|
|
{
|
|
var bone = stretchyman.skeleton.findBone(controlBones[i]);
|
|
let point = {x: bone.worldX, y: bone.worldY};
|
|
stretchyman.skeletonToPhaserWorldCoordinates(point);
|
|
|
|
var control = this.add.circle(point.x, point.y, 4, 0xff00ff).setData('bone', bone);
|
|
|
|
control.setInteractive();
|
|
this.input.setDraggable(control);
|
|
this.input.on('drag', function (pointer, gameObject, dragX, dragY) {
|
|
|
|
gameObject.x = dragX;
|
|
gameObject.y = dragY;
|
|
|
|
var bone = gameObject.getData('bone');
|
|
let point = { x: dragX, y: dragY };
|
|
stretchyman.phaserWorldCoordinatesToBone(point, bone);
|
|
|
|
bone.x = point.x;
|
|
bone.y = point.y;
|
|
bone.update();
|
|
|
|
}, this);
|
|
}
|
|
}
|
|
</script>
|
|
</body>
|
|
</html> |