|
@@ -1,71 +1,72 @@
|
|
|
<!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/[email protected]/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" }
|
|
|
- ]
|
|
|
- }
|
|
|
-};
|
|
|
+ <script>
|
|
|
+ var 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" }
|
|
|
+ ]
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
|
|
|
-let game = new Phaser.Game(config);
|
|
|
+ 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 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();
|
|
|
+ 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 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);
|
|
|
+ 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) {
|
|
|
+ control.setInteractive();
|
|
|
+ this.input.setDraggable(control);
|
|
|
+ this.input.on('drag', function (pointer, gameObject, dragX, dragY) {
|
|
|
|
|
|
- gameObject.x = dragX;
|
|
|
- gameObject.y = dragY;
|
|
|
+ gameObject.x = dragX;
|
|
|
+ gameObject.y = dragY;
|
|
|
|
|
|
- var bone = gameObject.getData('bone');
|
|
|
- let point = { x: dragX, y: dragY };
|
|
|
- stretchyman.phaserWorldCoordinatesToBone(point, bone);
|
|
|
+ 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();
|
|
|
+ bone.x = point.x;
|
|
|
+ bone.y = point.y;
|
|
|
+ bone.update();
|
|
|
|
|
|
- }, this);
|
|
|
- }
|
|
|
-}
|
|
|
-</script>
|
|
|
+ }, this);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ </script>
|
|
|
</body>
|
|
|
+
|
|
|
</html>
|