@melonjs/spine-plugin 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -13,7 +13,7 @@ a [Spine](http://en.esotericsoftware.com/spine-in-depth) 4.1 plugin implementati
13
13
 
14
14
  Installation
15
15
  -------------------------------------------------------------------------------
16
- this plugin is already bundled with the require Spine runtime, so there is no need to install it separately.
16
+ this plugin is already bundled with the required Spine runtime, so there is no need to install it separately.
17
17
  >Note: this plugin requires melonJS version 15.9 or higher.
18
18
 
19
19
  To install the plugin using npm :
@@ -29,8 +29,8 @@ Spine.assetManager.loadAsset("alien.atlas", "alien-ess.json");
29
29
 
30
30
  // create new Spine Renderable
31
31
  export default class AlienSpine extends Spine {
32
- constructor(x, y, settings ){
33
- super(x, y, settings);
32
+ constructor(x, y, settings ){
33
+ super(x, y, settings);
34
34
  ...
35
35
  }
36
36
  }
@@ -370,6 +370,8 @@ declare class Spine extends Renderable$1 {
370
370
  mixTime: any;
371
371
  jsonFile: any;
372
372
  atlasFile: any;
373
+ set debugRendering(arg: boolean);
374
+ get debugRendering(): boolean;
373
375
  setSkeleton(atlasFile: any, jsonFile: any): void;
374
376
  loadSpineAssets(atlasFile: any, jsonFile: any): void;
375
377
  rotate(angle: any, v: any): void;
@@ -4073,8 +4075,8 @@ declare class SkeletonRenderer {
4073
4075
  runtime: any;
4074
4076
  tempColor: Color;
4075
4077
  tintColor: Color$1;
4078
+ debugRendering: boolean;
4076
4079
  draw(renderer: any, skeleton: any): void;
4077
- updateSkeleton(skeleton: any): void;
4078
4080
  }
4079
4081
  import { Vector2d } from 'melonjs';
4080
4082
  /******************************************************************************
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * melonJS Spine plugin - v1.0.0
2
+ * melonJS Spine plugin - v1.1.0
3
3
  * http://www.melonjs.org
4
4
  * @melonjs/spine-plugin is licensed under the MIT License.
5
5
  * http://www.opensource.org/licenses/mit-license
@@ -14938,6 +14938,7 @@ class SkeletonRenderer {
14938
14938
  runtime;
14939
14939
  tempColor = new Color();
14940
14940
  tintColor = new Color$1();
14941
+ debugRendering = false;
14941
14942
 
14942
14943
  constructor(runtime) {
14943
14944
  this.runtime = runtime;
@@ -14950,6 +14951,10 @@ class SkeletonRenderer {
14950
14951
  let drawOrder = skeleton.drawOrder;
14951
14952
  let skeletonColor = skeleton.color;
14952
14953
 
14954
+ if (this.debugRendering === true) {
14955
+ renderer.setColor("green");
14956
+ }
14957
+
14953
14958
  for (var i = 0, n = drawOrder.length; i < n; i++) {
14954
14959
  let slot = drawOrder[i];
14955
14960
  let bone = slot.bone;
@@ -14996,17 +15001,13 @@ class SkeletonRenderer {
14996
15001
  renderer.setBlendMode(blendModeLUT[blendMode]);
14997
15002
  renderer.setGlobalAlpha(color.a);
14998
15003
  renderer.drawImage(image, image.width * region.u, image.height * region.v, w, h, 0, 0, w, h);
15004
+ if (this.debugRendering === true) {
15005
+ renderer.strokeRect(0, 0, w, h);
15006
+ }
14999
15007
  renderer.restore();
15000
15008
  }
15001
15009
  }
15002
15010
  }
15003
-
15004
- updateSkeleton(skeleton) {
15005
- // for update skeleton
15006
- //if (this.isWebGLRenderer === false) {
15007
- skeleton.scaleY = -1;
15008
- //}
15009
- }
15010
15011
  }
15011
15012
 
15012
15013
  let assetManager = new AssetManager();
@@ -15055,9 +15056,19 @@ class Spine extends Renderable$1 {
15055
15056
  }
15056
15057
  }
15057
15058
 
15059
+ get debugRendering() {
15060
+ return this.skeletonRenderer.debugRendering;
15061
+ }
15062
+
15063
+ set debugRendering(value) {
15064
+ this.skeletonRenderer.debugRendering = value;
15065
+ }
15066
+
15058
15067
  setSkeleton(atlasFile, jsonFile) {
15059
15068
  this.loadSpineAssets(atlasFile, jsonFile);
15060
15069
  this.root = this.skeleton.getRootBone();
15070
+ // Spine uses Y-up, melonJS uses Y-down
15071
+ this.root.scaleY *= -1;
15061
15072
  }
15062
15073
 
15063
15074
  loadSpineAssets(atlasFile, jsonFile) {
@@ -15139,7 +15150,7 @@ class Spine extends Renderable$1 {
15139
15150
  * @param {number} dt - time since the last update in milliseconds.
15140
15151
  * @returns {boolean} true if the renderable is dirty
15141
15152
  */
15142
- update(dt) { // eslint-disable-line no-unused-vars
15153
+ update(dt) {
15143
15154
  if (typeof this.skeleton !== "undefined") {
15144
15155
  let rootBone = this.skeleton.getRootBone();
15145
15156
 
@@ -15151,7 +15162,6 @@ class Spine extends Renderable$1 {
15151
15162
  rootBone.y = this.pos.y;
15152
15163
  }
15153
15164
 
15154
- this.skeletonRenderer.updateSkeleton(rootBone);
15155
15165
  // Update and apply the animation state, update the skeleton's
15156
15166
  // world transforms and render the skeleton.
15157
15167
  this.animationState.update(dt / 1000);
@@ -15176,12 +15186,12 @@ class Spine extends Renderable$1 {
15176
15186
  this.skeletonRenderer.draw(renderer, this.skeleton);
15177
15187
  }
15178
15188
 
15179
-
15180
15189
  setAnimationByIndex(track_index, index, loop = false) {
15181
- if (index < 0 || index >= this.skeleton.data.animations.length)
15182
- { return (console.log("Animation Index not found")); }
15183
- else
15184
- { this.animationState.setAnimation(track_index, this.skeleton.data.animations[index].name, loop); }
15190
+ if (index < 0 || index >= this.skeleton.data.animations.length) {
15191
+ return (console.log("Animation Index not found"));
15192
+ } else {
15193
+ this.animationState.setAnimation(track_index, this.skeleton.data.animations[index].name, loop);
15194
+ }
15185
15195
  }
15186
15196
 
15187
15197
  setAnimation(track_index, name, loop = false) {
@@ -15189,10 +15199,11 @@ class Spine extends Renderable$1 {
15189
15199
  }
15190
15200
 
15191
15201
  addAnimationByIndex(track_index, index, loop = false, delay = 0) {
15192
- if (index < 0 || index >= this.skeleton.data.animations.length)
15193
- { return (console.log("Animation Index not found")); }
15194
- else
15195
- { this.animationState.addAnimation(track_index, this.skeleton.data.animations[index].name, loop, delay); }
15202
+ if (index < 0 || index >= this.skeleton.data.animations.length) {
15203
+ return (console.log("Animation Index not found"));
15204
+ } else {
15205
+ this.animationState.addAnimation(track_index, this.skeleton.data.animations[index].name, loop, delay);
15206
+ }
15196
15207
  }
15197
15208
 
15198
15209
  addAnimationByName(track_index, animationName, loop = false, delay = 0) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@melonjs/spine-plugin",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "melonJS Spine plugin",
5
5
  "type": "module",
6
6
  "keywords": [
@@ -52,7 +52,7 @@
52
52
  "@babel/eslint-parser": "^7.22.0",
53
53
  "@babel/plugin-syntax-import-assertions": "^7.22.5",
54
54
  "@rollup/plugin-commonjs": "^25.0.4",
55
- "@rollup/plugin-node-resolve": "^15.1.0",
55
+ "@rollup/plugin-node-resolve": "^15.2.0",
56
56
  "@rollup/plugin-replace": "^5.0.2",
57
57
  "del-cli": "^5.0.0",
58
58
  "eslint": "^8.47.0",
@@ -70,7 +70,7 @@
70
70
  "clean": "del-cli --force dist/*",
71
71
  "types": "tsc"
72
72
  },
73
- "homepage": "https://github.com/melonjs/debug-spine#readme",
73
+ "homepage": "https://github.com/melonjs/spine-plugin#readme",
74
74
  "directories": {
75
75
  "test": "test"
76
76
  }
@@ -10,6 +10,7 @@ export default class SkeletonRenderer {
10
10
  runtime;
11
11
  tempColor = new Color();
12
12
  tintColor = new MColor();
13
+ debugRendering = false;
13
14
 
14
15
  constructor(runtime) {
15
16
  this.runtime = runtime;
@@ -22,6 +23,10 @@ export default class SkeletonRenderer {
22
23
  let drawOrder = skeleton.drawOrder;
23
24
  let skeletonColor = skeleton.color;
24
25
 
26
+ if (this.debugRendering === true) {
27
+ renderer.setColor("green");
28
+ }
29
+
25
30
  for (var i = 0, n = drawOrder.length; i < n; i++) {
26
31
  let slot = drawOrder[i];
27
32
  let bone = slot.bone;
@@ -68,15 +73,11 @@ export default class SkeletonRenderer {
68
73
  renderer.setBlendMode(blendModeLUT[blendMode]);
69
74
  renderer.setGlobalAlpha(color.a);
70
75
  renderer.drawImage(image, image.width * region.u, image.height * region.v, w, h, 0, 0, w, h);
76
+ if (this.debugRendering === true) {
77
+ renderer.strokeRect(0, 0, w, h);
78
+ }
71
79
  renderer.restore();
72
80
  }
73
81
  }
74
82
  }
75
-
76
- updateSkeleton(skeleton) {
77
- // for update skeleton
78
- //if (this.isWebGLRenderer === false) {
79
- skeleton.scaleY = -1;
80
- //}
81
- }
82
83
  }
package/src/index.js CHANGED
@@ -53,9 +53,19 @@ export default class Spine extends Renderable {
53
53
  }
54
54
  }
55
55
 
56
+ get debugRendering() {
57
+ return this.skeletonRenderer.debugRendering;
58
+ }
59
+
60
+ set debugRendering(value) {
61
+ this.skeletonRenderer.debugRendering = value;
62
+ }
63
+
56
64
  setSkeleton(atlasFile, jsonFile) {
57
65
  this.loadSpineAssets(atlasFile, jsonFile);
58
66
  this.root = this.skeleton.getRootBone();
67
+ // Spine uses Y-up, melonJS uses Y-down
68
+ this.root.scaleY *= -1;
59
69
  }
60
70
 
61
71
  loadSpineAssets(atlasFile, jsonFile) {
@@ -137,7 +147,7 @@ export default class Spine extends Renderable {
137
147
  * @param {number} dt - time since the last update in milliseconds.
138
148
  * @returns {boolean} true if the renderable is dirty
139
149
  */
140
- update(dt) { // eslint-disable-line no-unused-vars
150
+ update(dt) {
141
151
  if (typeof this.skeleton !== "undefined") {
142
152
  let rootBone = this.skeleton.getRootBone();
143
153
 
@@ -149,7 +159,6 @@ export default class Spine extends Renderable {
149
159
  rootBone.y = this.pos.y;
150
160
  }
151
161
 
152
- this.skeletonRenderer.updateSkeleton(rootBone);
153
162
  // Update and apply the animation state, update the skeleton's
154
163
  // world transforms and render the skeleton.
155
164
  this.animationState.update(dt / 1000);
@@ -174,12 +183,12 @@ export default class Spine extends Renderable {
174
183
  this.skeletonRenderer.draw(renderer, this.skeleton);
175
184
  }
176
185
 
177
-
178
186
  setAnimationByIndex(track_index, index, loop = false) {
179
- if (index < 0 || index >= this.skeleton.data.animations.length)
180
- { return (console.log("Animation Index not found")); }
181
- else
182
- { this.animationState.setAnimation(track_index, this.skeleton.data.animations[index].name, loop); }
187
+ if (index < 0 || index >= this.skeleton.data.animations.length) {
188
+ return (console.log("Animation Index not found"));
189
+ } else {
190
+ this.animationState.setAnimation(track_index, this.skeleton.data.animations[index].name, loop);
191
+ }
183
192
  }
184
193
 
185
194
  setAnimation(track_index, name, loop = false) {
@@ -187,10 +196,11 @@ export default class Spine extends Renderable {
187
196
  }
188
197
 
189
198
  addAnimationByIndex(track_index, index, loop = false, delay = 0) {
190
- if (index < 0 || index >= this.skeleton.data.animations.length)
191
- { return (console.log("Animation Index not found")); }
192
- else
193
- { this.animationState.addAnimation(track_index, this.skeleton.data.animations[index].name, loop, delay); }
199
+ if (index < 0 || index >= this.skeleton.data.animations.length) {
200
+ return (console.log("Animation Index not found"));
201
+ } else {
202
+ this.animationState.addAnimation(track_index, this.skeleton.data.animations[index].name, loop, delay);
203
+ }
194
204
  }
195
205
 
196
206
  addAnimationByName(track_index, animationName, loop = false, delay = 0) {