melonjs 14.4.0 → 14.5.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.
Files changed (207) hide show
  1. package/README.md +11 -55
  2. package/dist/melonjs.mjs/_virtual/_commonjsHelpers.js +1 -1
  3. package/dist/melonjs.mjs/_virtual/arraymultimap.js +1 -1
  4. package/dist/melonjs.mjs/_virtual/earcut.js +1 -1
  5. package/dist/melonjs.mjs/_virtual/howler.js +1 -1
  6. package/dist/melonjs.mjs/_virtual/index.js +1 -1
  7. package/dist/melonjs.mjs/_virtual/index2.js +1 -1
  8. package/dist/melonjs.mjs/_virtual/multimap.js +1 -1
  9. package/dist/melonjs.mjs/_virtual/setmultimap.js +1 -1
  10. package/dist/melonjs.mjs/application/application.js +1 -1
  11. package/dist/melonjs.mjs/application/header.js +1 -1
  12. package/dist/melonjs.mjs/application/resize.js +1 -1
  13. package/dist/melonjs.mjs/application/settings.js +1 -1
  14. package/dist/melonjs.mjs/audio/audio.js +4 -4
  15. package/dist/melonjs.mjs/camera/camera2d.js +1 -1
  16. package/dist/melonjs.mjs/const.js +1 -1
  17. package/dist/melonjs.mjs/entity/entity.js +43 -9
  18. package/dist/melonjs.mjs/geometries/ellipse.js +2 -3
  19. package/dist/melonjs.mjs/geometries/line.js +1 -1
  20. package/dist/melonjs.mjs/geometries/path2d.js +18 -42
  21. package/dist/melonjs.mjs/geometries/point.js +1 -6
  22. package/dist/melonjs.mjs/geometries/poly.js +2 -5
  23. package/dist/melonjs.mjs/geometries/rectangle.js +13 -9
  24. package/dist/melonjs.mjs/geometries/roundrect.js +1 -1
  25. package/dist/melonjs.mjs/index.js +8 -6
  26. package/dist/melonjs.mjs/input/gamepad.js +10 -16
  27. package/dist/melonjs.mjs/input/input.js +1 -1
  28. package/dist/melonjs.mjs/input/keyboard.js +1 -1
  29. package/dist/melonjs.mjs/input/pointer.js +1 -1
  30. package/dist/melonjs.mjs/input/pointerevent.js +2 -16
  31. package/dist/melonjs.mjs/lang/console.js +1 -1
  32. package/dist/melonjs.mjs/lang/deprecated.js +1 -1
  33. package/dist/melonjs.mjs/level/level.js +3 -3
  34. package/dist/melonjs.mjs/level/tiled/TMXGroup.js +1 -1
  35. package/dist/melonjs.mjs/level/tiled/TMXLayer.js +1 -8
  36. package/dist/melonjs.mjs/level/tiled/TMXObject.js +1 -1
  37. package/dist/melonjs.mjs/level/tiled/TMXTile.js +1 -1
  38. package/dist/melonjs.mjs/level/tiled/TMXTileMap.js +8 -4
  39. package/dist/melonjs.mjs/level/tiled/TMXTileset.js +5 -5
  40. package/dist/melonjs.mjs/level/tiled/TMXTilesetGroup.js +1 -1
  41. package/dist/melonjs.mjs/level/tiled/TMXUtils.js +1 -1
  42. package/dist/melonjs.mjs/level/tiled/constants.js +1 -1
  43. package/dist/melonjs.mjs/level/tiled/renderer/TMXHexagonalRenderer.js +1 -1
  44. package/dist/melonjs.mjs/level/tiled/renderer/TMXIsometricRenderer.js +1 -1
  45. package/dist/melonjs.mjs/level/tiled/renderer/TMXOrthogonalRenderer.js +1 -1
  46. package/dist/melonjs.mjs/level/tiled/renderer/TMXRenderer.js +1 -1
  47. package/dist/melonjs.mjs/level/tiled/renderer/TMXStaggeredRenderer.js +1 -1
  48. package/dist/melonjs.mjs/level/tiled/renderer/autodetect.js +1 -1
  49. package/dist/melonjs.mjs/loader/cache.js +24 -0
  50. package/dist/melonjs.mjs/loader/loader.js +331 -716
  51. package/dist/melonjs.mjs/loader/loadingscreen.js +4 -4
  52. package/dist/melonjs.mjs/loader/melonjs_logo.png.js +1 -1
  53. package/dist/melonjs.mjs/loader/parser.js +281 -0
  54. package/dist/melonjs.mjs/loader/settings.js +91 -0
  55. package/dist/melonjs.mjs/math/color.js +1 -1
  56. package/dist/melonjs.mjs/math/math.js +1 -1
  57. package/dist/melonjs.mjs/math/matrix2.js +7 -9
  58. package/dist/melonjs.mjs/math/matrix3.js +18 -21
  59. package/dist/melonjs.mjs/math/observable_vector2.js +3 -3
  60. package/dist/melonjs.mjs/math/observable_vector3.js +3 -4
  61. package/dist/melonjs.mjs/math/vector2.js +3 -3
  62. package/dist/melonjs.mjs/math/vector3.js +3 -4
  63. package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/arraymultimap.js +1 -1
  64. package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/index.js +1 -1
  65. package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/multimap.js +1 -1
  66. package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/setmultimap.js +1 -1
  67. package/dist/melonjs.mjs/node_modules/earcut/src/earcut.js +1 -1
  68. package/dist/melonjs.mjs/node_modules/eventemitter3/index.js +1 -1
  69. package/dist/melonjs.mjs/node_modules/eventemitter3/index2.js +1 -1
  70. package/dist/melonjs.mjs/node_modules/howler/dist/howler.js +1 -1
  71. package/dist/melonjs.mjs/particles/emitter.js +3 -3
  72. package/dist/melonjs.mjs/particles/particle.js +1 -1
  73. package/dist/melonjs.mjs/particles/settings.js +1 -1
  74. package/dist/melonjs.mjs/physics/body.js +18 -14
  75. package/dist/melonjs.mjs/physics/bounds.js +18 -70
  76. package/dist/melonjs.mjs/physics/collision.js +1 -1
  77. package/dist/melonjs.mjs/physics/detector.js +1 -1
  78. package/dist/melonjs.mjs/physics/quadtree.js +1 -1
  79. package/dist/melonjs.mjs/physics/response.js +1 -1
  80. package/dist/melonjs.mjs/physics/sat.js +1 -1
  81. package/dist/melonjs.mjs/physics/world.js +1 -1
  82. package/dist/melonjs.mjs/plugin/plugin.js +3 -3
  83. package/dist/melonjs.mjs/renderable/collectable.js +1 -1
  84. package/dist/melonjs.mjs/renderable/colorlayer.js +1 -1
  85. package/dist/melonjs.mjs/renderable/container.js +25 -19
  86. package/dist/melonjs.mjs/renderable/dragndrop.js +1 -1
  87. package/dist/melonjs.mjs/renderable/imagelayer.js +7 -1
  88. package/dist/melonjs.mjs/renderable/light2d.js +1 -1
  89. package/dist/melonjs.mjs/renderable/nineslicesprite.js +1 -1
  90. package/dist/melonjs.mjs/renderable/renderable.js +126 -105
  91. package/dist/melonjs.mjs/renderable/sprite.js +33 -54
  92. package/dist/melonjs.mjs/renderable/trigger.js +1 -1
  93. package/dist/melonjs.mjs/renderable/ui/uibaseelement.js +1 -1
  94. package/dist/melonjs.mjs/renderable/ui/uispriteelement.js +1 -1
  95. package/dist/melonjs.mjs/renderable/ui/uitextbutton.js +1 -1
  96. package/dist/melonjs.mjs/state/stage.js +1 -1
  97. package/dist/melonjs.mjs/state/state.js +2 -2
  98. package/dist/melonjs.mjs/system/device.js +1 -1
  99. package/dist/melonjs.mjs/system/dom.js +1 -1
  100. package/dist/melonjs.mjs/system/event.js +1 -1
  101. package/dist/melonjs.mjs/system/platform.js +1 -1
  102. package/dist/melonjs.mjs/system/pooling.js +8 -18
  103. package/dist/melonjs.mjs/system/save.js +1 -1
  104. package/dist/melonjs.mjs/system/timer.js +1 -1
  105. package/dist/melonjs.mjs/text/bitmaptext.js +66 -8
  106. package/dist/melonjs.mjs/text/bitmaptextdata.js +1 -1
  107. package/dist/melonjs.mjs/text/glyph.js +1 -1
  108. package/dist/melonjs.mjs/text/text.js +1 -1
  109. package/dist/melonjs.mjs/text/textmetrics.js +1 -1
  110. package/dist/melonjs.mjs/text/textstyle.js +1 -1
  111. package/dist/melonjs.mjs/tweens/easing.js +1 -1
  112. package/dist/melonjs.mjs/tweens/interpolation.js +1 -1
  113. package/dist/melonjs.mjs/tweens/tween.js +1 -1
  114. package/dist/melonjs.mjs/utils/agent.js +1 -1
  115. package/dist/melonjs.mjs/utils/array.js +1 -1
  116. package/dist/melonjs.mjs/utils/file.js +1 -1
  117. package/dist/melonjs.mjs/utils/function.js +1 -1
  118. package/dist/melonjs.mjs/utils/string.js +2 -2
  119. package/dist/melonjs.mjs/utils/utils.js +2 -4
  120. package/dist/melonjs.mjs/video/canvas/canvas_renderer.js +1 -1
  121. package/dist/melonjs.mjs/video/renderer.js +1 -1
  122. package/dist/melonjs.mjs/video/texture/atlas.js +10 -9
  123. package/dist/melonjs.mjs/video/texture/cache.js +3 -3
  124. package/dist/melonjs.mjs/video/texture/canvas_texture.js +1 -1
  125. package/dist/melonjs.mjs/video/utils/autodetect.js +1 -1
  126. package/dist/melonjs.mjs/video/video.js +2 -2
  127. package/dist/melonjs.mjs/video/webgl/buffer/vertex.js +1 -1
  128. package/dist/melonjs.mjs/video/webgl/compositors/compositor.js +235 -0
  129. package/{src/video/webgl → dist/melonjs.mjs/video/webgl/compositors}/webgl_compositor.js +28 -205
  130. package/dist/melonjs.mjs/video/webgl/glshader.js +1 -1
  131. package/dist/melonjs.mjs/video/webgl/shaders/primitive.frag.js +1 -1
  132. package/dist/melonjs.mjs/video/webgl/shaders/primitive.vert.js +1 -1
  133. package/dist/melonjs.mjs/video/webgl/shaders/quad.frag.js +1 -1
  134. package/dist/melonjs.mjs/video/webgl/shaders/quad.vert.js +1 -1
  135. package/dist/melonjs.mjs/video/webgl/utils/attributes.js +1 -1
  136. package/dist/melonjs.mjs/video/webgl/utils/precision.js +1 -1
  137. package/dist/melonjs.mjs/video/webgl/utils/program.js +1 -1
  138. package/dist/melonjs.mjs/video/webgl/utils/string.js +1 -1
  139. package/dist/melonjs.mjs/video/webgl/utils/uniforms.js +1 -1
  140. package/dist/melonjs.mjs/video/webgl/webgl_compositor.js +2 -2
  141. package/dist/melonjs.mjs/video/webgl/webgl_renderer.js +2 -2
  142. package/dist/melonjs.module.js +17844 -17809
  143. package/dist/types/entity/entity.d.ts +2 -2
  144. package/dist/types/geometries/path2d.d.ts +5 -31
  145. package/dist/types/geometries/point.d.ts +2 -7
  146. package/dist/types/geometries/poly.d.ts +0 -1
  147. package/dist/types/index.d.ts +2 -2
  148. package/dist/types/loader/cache.d.ts +7 -0
  149. package/dist/types/loader/loader.d.ts +166 -181
  150. package/dist/types/loader/parser.d.ts +41 -0
  151. package/dist/types/loader/settings.d.ts +57 -0
  152. package/dist/types/particles/emitter.d.ts +4 -4
  153. package/dist/types/physics/bounds.d.ts +29 -84
  154. package/dist/types/renderable/container.d.ts +0 -11
  155. package/dist/types/renderable/renderable.d.ts +37 -31
  156. package/dist/types/renderable/sprite.d.ts +3 -3
  157. package/dist/types/state/state.d.ts +1 -1
  158. package/dist/types/system/pooling.d.ts +2 -2
  159. package/dist/types/video/renderer.d.ts +1 -1
  160. package/dist/types/video/webgl/compositors/compositor.d.ts +101 -0
  161. package/dist/types/video/webgl/compositors/webgl_compositor.d.ts +86 -0
  162. package/dist/types/video/webgl/webgl_compositor.d.ts +2 -3
  163. package/dist/types/video/webgl/webgl_renderer.d.ts +1 -1
  164. package/package.json +16 -15
  165. package/src/audio/audio.js +3 -3
  166. package/src/entity/entity.js +42 -8
  167. package/src/geometries/ellipse.js +1 -2
  168. package/src/geometries/path2d.js +17 -41
  169. package/src/geometries/point.js +0 -5
  170. package/src/geometries/poly.js +1 -4
  171. package/src/geometries/rectangle.js +12 -8
  172. package/src/index.js +2 -2
  173. package/src/input/gamepad.js +9 -15
  174. package/src/input/pointerevent.js +1 -15
  175. package/src/level/level.js +2 -2
  176. package/src/level/tiled/TMXLayer.js +0 -7
  177. package/src/level/tiled/TMXTileMap.js +7 -3
  178. package/src/level/tiled/TMXTileset.js +4 -4
  179. package/src/loader/cache.js +16 -0
  180. package/src/loader/loader.js +339 -711
  181. package/src/loader/loadingscreen.js +3 -3
  182. package/src/loader/parser.js +279 -0
  183. package/src/loader/settings.js +85 -0
  184. package/src/math/matrix2.js +6 -8
  185. package/src/math/matrix3.js +17 -20
  186. package/src/math/observable_vector2.js +2 -2
  187. package/src/math/observable_vector3.js +2 -3
  188. package/src/math/vector2.js +2 -2
  189. package/src/math/vector3.js +2 -3
  190. package/src/particles/emitter.js +2 -2
  191. package/src/physics/body.js +17 -13
  192. package/src/physics/bounds.js +17 -69
  193. package/src/renderable/container.js +24 -18
  194. package/src/renderable/imagelayer.js +6 -0
  195. package/src/renderable/renderable.js +125 -104
  196. package/src/renderable/sprite.js +32 -53
  197. package/src/state/state.js +1 -1
  198. package/src/system/pooling.js +7 -17
  199. package/src/text/bitmaptext.js +65 -7
  200. package/src/utils/string.js +1 -1
  201. package/src/utils/utils.js +1 -3
  202. package/src/video/texture/atlas.js +9 -8
  203. package/src/video/texture/cache.js +2 -2
  204. package/src/video/video.js +1 -1
  205. package/src/video/webgl/compositors/compositor.js +227 -0
  206. package/src/video/webgl/compositors/webgl_compositor.js +300 -0
  207. package/src/video/webgl/webgl_renderer.js +1 -1
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * melonJS Game Engine - v14.4.0
2
+ * melonJS Game Engine - v14.5.0
3
3
  * http://www.melonjs.org
4
4
  * melonjs is licensed under the MIT License.
5
5
  * http://www.opensource.org/licenses/mit-license
@@ -30,18 +30,42 @@ import { releaseAllPointerEvents } from '../input/pointerevent.js';
30
30
  // parent constructor
31
31
  super(x, y, width, height);
32
32
 
33
- /**
34
- * to identify the object as a renderable object
35
- * @ignore
36
- */
37
- this.isRenderable = true;
33
+ if (this.pos instanceof ObservableVector3d) {
34
+ this.pos.setMuted(x, y, 0).setCallback(this.updateBoundsPos, this);
35
+ } else {
36
+ /**
37
+ * Position of the Renderable relative to its parent container
38
+ * @public
39
+ * @type {ObservableVector3d}
40
+ */
41
+ this.pos = pool.pull("ObservableVector3d", x, y, 0, { onUpdate: this.updateBoundsPos, scope: this});
42
+ }
38
43
 
39
- /**
40
- * If true then physic collision and input events will not impact this renderable
41
- * @type {boolean}
42
- * @default true
43
- */
44
- this.isKinematic = true;
44
+ if (this.anchorPoint instanceof ObservableVector2d) {
45
+ this.anchorPoint.setMuted(0.5, 0.5).setCallback(this.onAnchorUpdate, this);
46
+ } else {
47
+ /**
48
+ * The anchor point is used for attachment behavior, and/or when applying transformations.<br>
49
+ * The coordinate system places the origin at the top left corner of the frame (0, 0) and (1, 1) means the bottom-right corner<br>
50
+ * <img src="images/anchor_point.png"/><br>
51
+ * a Renderable's anchor point defaults to (0.5,0.5), which corresponds to the center position.<br>
52
+ * <br>
53
+ * <i><b>Note:</b> Object created through Tiled will have their anchorPoint set to (0, 0) to match Tiled Level editor implementation.
54
+ * To specify a value through Tiled, use a json expression like `json:{"x":0.5,"y":0.5}`. </i>
55
+ * @type {ObservableVector2d}
56
+ * @default <0.5,0.5>
57
+ */
58
+ this.anchorPoint = pool.pull("ObservableVector2d", 0.5, 0.5, { onUpdate: this.onAnchorUpdate, scope: this });
59
+ }
60
+
61
+ if (typeof this.currentTransform === "undefined") {
62
+ /**
63
+ * the renderable default transformation matrix
64
+ * @type {Matrix2d}
65
+ */
66
+ this.currentTransform = pool.pull("Matrix2d");
67
+ }
68
+ this.currentTransform.identity();
45
69
 
46
70
  /**
47
71
  * the renderable physic body
@@ -80,15 +104,6 @@ import { releaseAllPointerEvents } from '../input/pointerevent.js';
80
104
  */
81
105
  this.body = undefined;
82
106
 
83
- if (typeof this.currentTransform === "undefined") {
84
- /**
85
- * the renderable default transformation matrix
86
- * @type {Matrix2d}
87
- */
88
- this.currentTransform = pool.pull("Matrix2d");
89
- }
90
- this.currentTransform.identity();
91
-
92
107
  /**
93
108
  * (G)ame (U)nique (Id)entifier" <br>
94
109
  * a GUID will be allocated for any renderable object added <br>
@@ -139,23 +154,6 @@ import { releaseAllPointerEvents } from '../input/pointerevent.js';
139
154
  */
140
155
  this.floating = false;
141
156
 
142
- if (this.anchorPoint instanceof ObservableVector2d) {
143
- this.anchorPoint.setMuted(0.5, 0.5).setCallback(this.onAnchorUpdate, this);
144
- } else {
145
- /**
146
- * The anchor point is used for attachment behavior, and/or when applying transformations.<br>
147
- * The coordinate system places the origin at the top left corner of the frame (0, 0) and (1, 1) means the bottom-right corner<br>
148
- * <img src="images/anchor_point.png"/><br>
149
- * a Renderable's anchor point defaults to (0.5,0.5), which corresponds to the center position.<br>
150
- * <br>
151
- * <i><b>Note:</b> Object created through Tiled will have their anchorPoint set to (0, 0) to match Tiled Level editor implementation.
152
- * To specify a value through Tiled, use a json expression like `json:{"x":0.5,"y":0.5}`. </i>
153
- * @type {ObservableVector2d}
154
- * @default <0.5,0.5>
155
- */
156
- this.anchorPoint = pool.pull("ObservableVector2d", 0.5, 0.5, { onUpdate: this.onAnchorUpdate, scope: this });
157
- }
158
-
159
157
  /**
160
158
  * When enabled, an object container will automatically apply
161
159
  * any defined transformation before calling the child draw method.
@@ -231,23 +229,25 @@ import { releaseAllPointerEvents } from '../input/pointerevent.js';
231
229
  */
232
230
  this.name = "";
233
231
 
234
- if (this.pos instanceof ObservableVector3d) {
235
- this.pos.setMuted(x, y, 0).setCallback(this.updateBoundsPos, this);
236
- } else {
237
- /**
238
- * Position of the Renderable relative to its parent container
239
- * @public
240
- * @type {ObservableVector3d}
241
- */
242
- this.pos = pool.pull("ObservableVector3d", x, y, 0, { onUpdate: this.updateBoundsPos, scope: this});
243
- }
232
+ /**
233
+ * to identify the object as a renderable object
234
+ * @ignore
235
+ */
236
+ this.isRenderable = true;
237
+
238
+ /**
239
+ * If true then physic collision and input events will not impact this renderable
240
+ * @type {boolean}
241
+ * @default true
242
+ */
243
+ this.isKinematic = true;
244
244
 
245
245
  /**
246
246
  * when true the renderable will be redrawn during the next update cycle
247
247
  * @type {boolean}
248
- * @default false
248
+ * @default true
249
249
  */
250
- this.isDirty = false;
250
+ this.isDirty = true;
251
251
 
252
252
  // keep track of when we flip
253
253
  this._flip = {
@@ -344,7 +344,7 @@ import { releaseAllPointerEvents } from '../input/pointerevent.js';
344
344
  if (typeof this._bounds === "undefined") {
345
345
  super.getBounds();
346
346
  if (this.isFinite()) {
347
- this._bounds.setMinMax(this.pos.x, this.pos.y, this.pos.x + this.width, this.pos.y + this.height);
347
+ this.updateBounds();
348
348
  } else {
349
349
  // e.g. containers or game world can have infinite size
350
350
  this._bounds.setMinMax(this.pos.x, this.pos.y, this.width, this.height);
@@ -384,8 +384,11 @@ import { releaseAllPointerEvents } from '../input/pointerevent.js';
384
384
  * @returns {Renderable} Reference to this object for method chaining
385
385
  */
386
386
  flipX(flip = true) {
387
- this._flip.x = !!flip;
388
- this.isDirty = true;
387
+ if (this.isFlippedX !== flip) {
388
+ this._flip.x = !!flip;
389
+ this.scale(-1, 1);
390
+ this.isDirty = true;
391
+ }
389
392
  return this;
390
393
  }
391
394
 
@@ -396,8 +399,11 @@ import { releaseAllPointerEvents } from '../input/pointerevent.js';
396
399
  * @returns {Renderable} Reference to this object for method chaining
397
400
  */
398
401
  flipY(flip = true) {
399
- this._flip.y = !!flip;
400
- this.isDirty = true;
402
+ if (this.isFlippedY !== flip) {
403
+ this._flip.y = !!flip;
404
+ this.scale(1, -1);
405
+ this.isDirty = true;
406
+ }
401
407
  return this;
402
408
  }
403
409
 
@@ -409,8 +415,7 @@ import { releaseAllPointerEvents } from '../input/pointerevent.js';
409
415
  */
410
416
  transform(m) {
411
417
  this.currentTransform.multiply(m);
412
- //super.transform(m);
413
- this.updateBoundsPos(this.pos.x, this.pos.y);
418
+ this.updateBounds();
414
419
  this.isDirty = true;
415
420
  return this;
416
421
  }
@@ -485,9 +490,9 @@ import { releaseAllPointerEvents } from '../input/pointerevent.js';
485
490
  * @returns {Renderable} Reference to this object for method chaining
486
491
  */
487
492
  rotate(angle, v) {
488
- if (!isNaN(angle)) {
493
+ if (angle !== 0) {
489
494
  this.currentTransform.rotate(angle, v);
490
- //this.updateBoundsPos(this.pos.x, this.pos.y);
495
+ this.updateBounds();
491
496
  this.isDirty = true;
492
497
  }
493
498
  return this;
@@ -503,9 +508,9 @@ import { releaseAllPointerEvents } from '../input/pointerevent.js';
503
508
  * @param {number} [y=x] - a number representing the ordinate of the scaling vector.
504
509
  * @returns {Renderable} Reference to this object for method chaining
505
510
  */
506
- scale(x, y) {
511
+ scale(x, y = x) {
507
512
  this.currentTransform.scale(x, y);
508
- super.scale(x, y);
513
+ this.updateBounds();
509
514
  this.isDirty = true;
510
515
  return this;
511
516
  }
@@ -531,44 +536,68 @@ import { releaseAllPointerEvents } from '../input/pointerevent.js';
531
536
 
532
537
  /**
533
538
  * update the bounding box for this shape.
534
- * @ignore
539
+ * @param {boolean} [absolute=true] - update the bounds size and position in (world) absolute coordinates
535
540
  * @returns {Bounds} this shape bounding box Rectangle object
536
541
  */
537
- updateBounds() {
538
- super.updateBounds();
539
- this.updateBoundsPos(this.pos.x, this.pos.y);
540
- return this.getBounds();
542
+ updateBounds(absolute = true) {
543
+ if (this.isRenderable) {
544
+ var bounds = this.getBounds();
545
+
546
+ bounds.clear();
547
+
548
+ if ((this.autoTransform === true) && (!this.currentTransform.isIdentity())) {
549
+ // temporarly translate the matrix based on the anchor point
550
+ this.currentTransform.translate(
551
+ -this.width * this.anchorPoint.x,
552
+ -this.height * this.anchorPoint.y
553
+ );
554
+ bounds.addFrame(
555
+ 0,
556
+ 0,
557
+ this.width,
558
+ this.height,
559
+ this.currentTransform
560
+ );
561
+ this.currentTransform.translate(
562
+ this.width * this.anchorPoint.x,
563
+ this.height * this.anchorPoint.y
564
+ );
565
+ } else {
566
+ bounds.addFrame(
567
+ 0,
568
+ 0,
569
+ this.width,
570
+ this.height
571
+ );
572
+ // translate the bounds based on the anchor point
573
+ bounds.translate(
574
+ -this.width * this.anchorPoint.x,
575
+ -this.height * this.anchorPoint.y
576
+ );
577
+ }
578
+
579
+ if (absolute === true) {
580
+ bounds.centerOn(this.pos.x + bounds.x + bounds.width / 2, this.pos.y + bounds.y + bounds.height / 2);
581
+ if (typeof this.ancestor !== "undefined" && typeof this.ancestor.addChild === "function" && this.floating !== true) {
582
+ bounds.translate(this.ancestor.getAbsolutePosition());
583
+ }
584
+
585
+ }
586
+ return bounds;
587
+
588
+ } else {
589
+ // manage the case where updateBounds is called
590
+ // before the object being yet properly initialized
591
+ return super.updateBounds(absolute);
592
+ }
541
593
  }
542
594
 
543
595
  /**
544
596
  * update the renderable's bounding rect (private)
545
597
  * @ignore
546
598
  */
547
- updateBoundsPos(newX, newY) {
548
- var bounds = this.getBounds();
549
-
550
- bounds.shift(newX, newY);
551
-
552
- if (typeof this.anchorPoint !== "undefined" && bounds.isFinite()) {
553
- bounds.translate(
554
- -(this.anchorPoint.x * bounds.width),
555
- -(this.anchorPoint.y * bounds.height)
556
- );
557
- }
558
-
559
- /*
560
- if (typeof this.body !== "undefined") {
561
- var bodyBounds = this.body.getBounds();
562
- bounds.translate(bodyBounds.x, bodyBounds.y);
563
- }
564
- */
565
-
566
- // XXX: This is called from the constructor, before it gets an ancestor
567
- if (typeof this.ancestor !== "undefined" && typeof this.ancestor.addChild === "function" && this.floating !== true) {
568
- bounds.translate(this.ancestor.getAbsolutePosition());
569
- }
570
-
571
- this.isDirty = true;
599
+ updateBoundsPos(newX = this.pos.x, newY = this.pos.y) {
600
+ this.getBounds().translate(newX - this.pos.x, newY - this.pos.y);
572
601
  }
573
602
 
574
603
  /**
@@ -598,7 +627,10 @@ import { releaseAllPointerEvents } from '../input/pointerevent.js';
598
627
  // manually update the anchor point (required for updateBoundsPos)
599
628
  this.anchorPoint.setMuted(x, y);
600
629
  // then call updateBounds
601
- this.updateBoundsPos(this.pos.x, this.pos.y);
630
+ //this.updateBoundsPos(this.pos.x, this.pos.y);
631
+ this.updateBounds();
632
+ //console.log("hello");
633
+ this.isDirty = true;
602
634
  }
603
635
 
604
636
  /**
@@ -609,9 +641,8 @@ import { releaseAllPointerEvents } from '../input/pointerevent.js';
609
641
  * @param {CanvasRenderer|WebGLRenderer} renderer - a renderer object
610
642
  */
611
643
  preDraw(renderer) {
612
- var bounds = this.getBounds();
613
- var ax = bounds.width * this.anchorPoint.x,
614
- ay = bounds.height * this.anchorPoint.y;
644
+ var ax = this.width * this.anchorPoint.x,
645
+ ay = this.height * this.anchorPoint.y;
615
646
 
616
647
  // save renderer context
617
648
  renderer.save();
@@ -619,16 +650,6 @@ import { releaseAllPointerEvents } from '../input/pointerevent.js';
619
650
  // apply the defined alpha value
620
651
  renderer.setGlobalAlpha(renderer.globalAlpha() * this.getOpacity());
621
652
 
622
- // apply flip
623
- if (this._flip.x || this._flip.y) {
624
- var dx = this._flip.x ? this.centerX - ax : 0,
625
- dy = this._flip.y ? this.centerY - ay : 0;
626
-
627
- renderer.translate(dx, dy);
628
- renderer.scale(this._flip.x ? -1 : 1, this._flip.y ? -1 : 1);
629
- renderer.translate(-dx, -dy);
630
- }
631
-
632
653
  // apply stencil mask if defined
633
654
  if (typeof this.mask !== "undefined") {
634
655
  renderer.translate(this.pos.x, this.pos.y);
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * melonJS Game Engine - v14.4.0
2
+ * melonJS Game Engine - v14.5.0
3
3
  * http://www.melonjs.org
4
4
  * melonjs is licensed under the MIT License.
5
5
  * http://www.opensource.org/licenses/mit-license
@@ -7,7 +7,7 @@
7
7
  */
8
8
  import { renderer } from '../video/video.js';
9
9
  import pool from '../system/pooling.js';
10
- import loader from '../loader/loader.js';
10
+ import { getImage } from '../loader/loader.js';
11
11
  import { TextureAtlas } from '../video/texture/atlas.js';
12
12
  import Renderable from './renderable.js';
13
13
  import Color from '../math/color.js';
@@ -102,7 +102,7 @@ import Color from '../math/color.js';
102
102
  // (reusing current, any better/cleaner place?)
103
103
  this.current = {
104
104
  // the current animation name
105
- name : "default",
105
+ name : undefined,
106
106
  // length of the current animation name
107
107
  length : 0,
108
108
  //current frame texture offset
@@ -139,9 +139,6 @@ import Color from '../math/color.js';
139
139
  if (region) {
140
140
  // set the sprite region within the texture
141
141
  this.setRegion(region);
142
- // update the default "current" frame size
143
- this.current.width = settings.framewidth || region.width;
144
- this.current.height = settings.frameheight || region.height;
145
142
  } else {
146
143
  // throw an error
147
144
  throw new Error("Texture - region for " + settings.region + " not found");
@@ -149,14 +146,14 @@ import Color from '../math/color.js';
149
146
  }
150
147
  } else {
151
148
  // HTMLImageElement/Canvas or {string}
152
- this.image = (typeof settings.image === "object") ? settings.image : loader.getImage(settings.image);
149
+ this.image = (typeof settings.image === "object") ? settings.image : getImage(settings.image);
153
150
  // throw an error if image ends up being null/undefined
154
151
  if (!this.image) {
155
152
  throw new Error("me.Sprite: '" + settings.image + "' image/texture not found!");
156
153
  }
157
154
  // update the default "current" frame size
158
- this.current.width = settings.framewidth = settings.framewidth || this.image.width;
159
- this.current.height = settings.frameheight = settings.frameheight || this.image.height;
155
+ this.width = this.current.width = settings.framewidth = settings.framewidth || this.image.width;
156
+ this.height = this.current.height = settings.frameheight = settings.frameheight || this.image.height;
160
157
  this.source = renderer.cache.get(this.image, settings);
161
158
  this.textureAtlas = this.source.getAtlas();
162
159
  }
@@ -167,10 +164,6 @@ import Color from '../math/color.js';
167
164
  this.atlasIndices = settings.atlasIndices;
168
165
  }
169
166
 
170
- // resize based on the active frame
171
- this.width = this.current.width;
172
- this.height = this.current.height;
173
-
174
167
  // apply flip flags if specified
175
168
  if (typeof (settings.flipX) !== "undefined") {
176
169
  this.flipX(!!settings.flipX);
@@ -209,14 +202,11 @@ import Color from '../math/color.js';
209
202
  this.pos.z = settings.z;
210
203
  }
211
204
 
212
- // for sprite, addAnimation will return !=0
205
+ // addAnimation will return 0 if no texture atlas is defined
213
206
  if (this.addAnimation("default", null) !== 0) {
214
207
  // set as default
215
208
  this.setCurrentAnimation("default");
216
209
  }
217
-
218
- // enable currentTransform for me.Sprite based objects
219
- this.autoTransform = true;
220
210
  }
221
211
 
222
212
  /**
@@ -396,22 +386,24 @@ import Color from '../math/color.js';
396
386
  * return false; // do not reset to first frame
397
387
  * }).bind(this));
398
388
  */
399
- setCurrentAnimation(name, resetAnim, preserve_dt) {
400
- if (this.anim[name]) {
401
- this.current.name = name;
402
- this.current.length = this.anim[this.current.name].length;
403
- if (typeof resetAnim === "string") {
404
- this.resetAnim = this.setCurrentAnimation.bind(this, resetAnim, null, true);
405
- } else if (typeof resetAnim === "function") {
406
- this.resetAnim = resetAnim;
407
- } else {
408
- this.resetAnim = undefined;
409
- }
410
- this.setAnimationFrame(this.current.idx);
411
- if (!preserve_dt) {
412
- this.dt = 0;
389
+ setCurrentAnimation(name, resetAnim, preserve_dt = false) {
390
+ if (typeof this.anim[name] !== "undefined") {
391
+ if (!this.isCurrentAnimation(name)) {
392
+ this.current.name = name;
393
+ this.current.length = this.anim[this.current.name].length;
394
+ if (typeof resetAnim === "string") {
395
+ this.resetAnim = this.setCurrentAnimation.bind(this, resetAnim, null, true);
396
+ } else if (typeof resetAnim === "function") {
397
+ this.resetAnim = resetAnim;
398
+ } else {
399
+ this.resetAnim = undefined;
400
+ }
401
+ this.setAnimationFrame(0);
402
+ if (!preserve_dt) {
403
+ this.dt = 0;
404
+ }
405
+ this.isDirty = true;
413
406
  }
414
- this.isDirty = true;
415
407
  } else {
416
408
  throw new Error("animation id '" + name + "' not defined");
417
409
  }
@@ -468,17 +460,19 @@ import Color from '../math/color.js';
468
460
  // set the sprite offset within the texture
469
461
  this.current.offset.setV(region.offset);
470
462
  // set angle if defined
471
- this.current.angle = region.angle;
463
+ this.current.angle = typeof region.angle === "number" ? region.angle : 0;
472
464
  // update the default "current" size
473
465
  this.width = this.current.width = region.width;
474
466
  this.height = this.current.height = region.height;
475
467
  // set global anchortPoint if defined
476
468
  if (region.anchorPoint) {
477
- this.anchorPoint.set(
469
+ this.anchorPoint.setMuted(
478
470
  this._flip.x && region.trimmed === true ? 1 - region.anchorPoint.x : region.anchorPoint.x,
479
471
  this._flip.y && region.trimmed === true ? 1 - region.anchorPoint.y : region.anchorPoint.y
480
472
  );
481
473
  }
474
+ // update the sprite bounding box
475
+ this.updateBounds();
482
476
  this.isDirty = true;
483
477
  return this;
484
478
  }
@@ -487,14 +481,14 @@ import Color from '../math/color.js';
487
481
  * force the current animation frame index.
488
482
  * @name setAnimationFrame
489
483
  * @memberof Sprite
490
- * @param {number} [idx=0] - animation frame index
484
+ * @param {number} [index=0] - animation frame index
491
485
  * @returns {Sprite} Reference to this object for method chaining
492
486
  * @example
493
487
  * // reset the current animation to the first frame
494
488
  * this.setAnimationFrame();
495
489
  */
496
- setAnimationFrame(idx) {
497
- this.current.idx = (idx || 0) % this.current.length;
490
+ setAnimationFrame(index = 0) {
491
+ this.current.idx = index % this.current.length;
498
492
  return this.setRegion(this.getAnimationFrameObjectByIndex(this.current.idx));
499
493
  }
500
494
 
@@ -531,14 +525,14 @@ import Color from '../math/color.js';
531
525
  */
532
526
  update(dt) {
533
527
  // Update animation if necessary
534
- if (!this.animationpause && this.current && this.current.length > 0) {
528
+ if (!this.animationpause && this.current.length > 1) {
535
529
  var duration = this.getAnimationFrameObjectByIndex(this.current.idx).delay;
536
530
  this.dt += dt;
537
531
  while (this.dt >= duration) {
538
532
  this.isDirty = true;
539
533
  this.dt -= duration;
540
534
 
541
- var nextFrame = (this.current.length > 1? this.current.idx+1: this.current.idx);
535
+ var nextFrame = (this.current.length > 1 ? this.current.idx + 1 : this.current.idx);
542
536
  this.setAnimationFrame(nextFrame);
543
537
 
544
538
  // Switch animation if we reach the end of the strip and a callback is defined
@@ -558,21 +552,6 @@ import Color from '../math/color.js';
558
552
  }
559
553
  }
560
554
 
561
- // update the sprite bounding box
562
- /*
563
- if (this.isDirty === true && !this.currentTransform.isIdentity()) {
564
- this.getBounds().clear();
565
- this.getBounds().addFrame(
566
- 0,
567
- 0,
568
- this.current.width,
569
- this.current.height,
570
- this.currentTransform
571
- );
572
- this.updateBoundsPos(this.pos.x, this.pos.y);
573
- }
574
- */
575
-
576
555
  //update the "flickering" state if necessary
577
556
  if (this._flicker.isFlickering) {
578
557
  this._flicker.duration -= dt;
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * melonJS Game Engine - v14.4.0
2
+ * melonJS Game Engine - v14.5.0
3
3
  * http://www.melonjs.org
4
4
  * melonjs is licensed under the MIT License.
5
5
  * http://www.opensource.org/licenses/mit-license
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * melonJS Game Engine - v14.4.0
2
+ * melonJS Game Engine - v14.5.0
3
3
  * http://www.melonjs.org
4
4
  * melonjs is licensed under the MIT License.
5
5
  * http://www.opensource.org/licenses/mit-license
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * melonJS Game Engine - v14.4.0
2
+ * melonJS Game Engine - v14.5.0
3
3
  * http://www.melonjs.org
4
4
  * melonjs is licensed under the MIT License.
5
5
  * http://www.opensource.org/licenses/mit-license
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * melonJS Game Engine - v14.4.0
2
+ * melonJS Game Engine - v14.5.0
3
3
  * http://www.melonjs.org
4
4
  * melonjs is licensed under the MIT License.
5
5
  * http://www.opensource.org/licenses/mit-license
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * melonJS Game Engine - v14.4.0
2
+ * melonJS Game Engine - v14.5.0
3
3
  * http://www.melonjs.org
4
4
  * melonjs is licensed under the MIT License.
5
5
  * http://www.opensource.org/licenses/mit-license
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * melonJS Game Engine - v14.4.0
2
+ * melonJS Game Engine - v14.5.0
3
3
  * http://www.melonjs.org
4
4
  * melonjs is licensed under the MIT License.
5
5
  * http://www.opensource.org/licenses/mit-license
@@ -514,7 +514,7 @@ var state = {
514
514
  },
515
515
 
516
516
  /**
517
- * enable/disable transition for a specific state (by default enabled for all)
517
+ * enable/disable the transition to a particular state (by default enabled for all)
518
518
  * @name setTransition
519
519
  * @memberof state
520
520
  * @public
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * melonJS Game Engine - v14.4.0
2
+ * melonJS Game Engine - v14.5.0
3
3
  * http://www.melonjs.org
4
4
  * melonjs is licensed under the MIT License.
5
5
  * http://www.opensource.org/licenses/mit-license
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * melonJS Game Engine - v14.4.0
2
+ * melonJS Game Engine - v14.5.0
3
3
  * http://www.melonjs.org
4
4
  * melonjs is licensed under the MIT License.
5
5
  * http://www.opensource.org/licenses/mit-license
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * melonJS Game Engine - v14.4.0
2
+ * melonJS Game Engine - v14.5.0
3
3
  * http://www.melonjs.org
4
4
  * melonjs is licensed under the MIT License.
5
5
  * http://www.opensource.org/licenses/mit-license
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * melonJS Game Engine - v14.4.0
2
+ * melonJS Game Engine - v14.5.0
3
3
  * http://www.melonjs.org
4
4
  * melonjs is licensed under the MIT License.
5
5
  * http://www.opensource.org/licenses/mit-license