melonjs 15.0.0 → 15.1.1

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 (285) hide show
  1. package/README.md +4 -4
  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 +7 -3
  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 +27 -17
  11. package/dist/melonjs.mjs/application/header.js +6 -5
  12. package/dist/melonjs.mjs/application/resize.js +20 -20
  13. package/dist/melonjs.mjs/application/settings.js +1 -1
  14. package/dist/melonjs.mjs/audio/audio.js +17 -17
  15. package/dist/melonjs.mjs/camera/camera2d.js +10 -10
  16. package/dist/melonjs.mjs/const.js +1 -1
  17. package/dist/melonjs.mjs/entity/entity.js +4 -4
  18. package/dist/melonjs.mjs/geometries/ellipse.js +6 -6
  19. package/dist/melonjs.mjs/geometries/line.js +9 -9
  20. package/dist/melonjs.mjs/geometries/path2d.js +53 -53
  21. package/dist/melonjs.mjs/geometries/point.js +2 -2
  22. package/dist/melonjs.mjs/geometries/poly.js +29 -29
  23. package/dist/melonjs.mjs/geometries/rectangle.js +8 -8
  24. package/dist/melonjs.mjs/geometries/roundrect.js +6 -6
  25. package/dist/melonjs.mjs/index.js +5 -5
  26. package/dist/melonjs.mjs/input/gamepad.js +30 -30
  27. package/dist/melonjs.mjs/input/input.js +2 -2
  28. package/dist/melonjs.mjs/input/keyboard.js +15 -15
  29. package/dist/melonjs.mjs/input/pointer.js +2 -2
  30. package/dist/melonjs.mjs/input/pointerevent.js +58 -58
  31. package/dist/melonjs.mjs/lang/console.js +3 -3
  32. package/dist/melonjs.mjs/lang/deprecated.js +2 -2
  33. package/dist/melonjs.mjs/level/level.js +9 -9
  34. package/dist/melonjs.mjs/level/tiled/TMXGroup.js +3 -3
  35. package/dist/melonjs.mjs/level/tiled/TMXLayer.js +31 -31
  36. package/dist/melonjs.mjs/level/tiled/TMXObject.js +8 -8
  37. package/dist/melonjs.mjs/level/tiled/TMXTile.js +8 -8
  38. package/dist/melonjs.mjs/level/tiled/TMXTileMap.js +19 -19
  39. package/dist/melonjs.mjs/level/tiled/TMXTileset.js +15 -15
  40. package/dist/melonjs.mjs/level/tiled/TMXTilesetGroup.js +3 -3
  41. package/dist/melonjs.mjs/level/tiled/TMXUtils.js +46 -41
  42. package/dist/melonjs.mjs/level/tiled/constants.js +1 -1
  43. package/dist/melonjs.mjs/level/tiled/renderer/TMXHexagonalRenderer.js +30 -30
  44. package/dist/melonjs.mjs/level/tiled/renderer/TMXIsometricRenderer.js +21 -21
  45. package/dist/melonjs.mjs/level/tiled/renderer/TMXOrthogonalRenderer.js +10 -10
  46. package/dist/melonjs.mjs/level/tiled/renderer/TMXRenderer.js +2 -2
  47. package/dist/melonjs.mjs/level/tiled/renderer/TMXStaggeredRenderer.js +6 -6
  48. package/dist/melonjs.mjs/level/tiled/renderer/autodetect.js +1 -1
  49. package/dist/melonjs.mjs/loader/cache.js +1 -1
  50. package/dist/melonjs.mjs/loader/loader.js +7 -7
  51. package/dist/melonjs.mjs/loader/loadingscreen.js +2 -2
  52. package/dist/melonjs.mjs/loader/melonjs_logo.png.js +1 -1
  53. package/dist/melonjs.mjs/loader/parser.js +13 -13
  54. package/dist/melonjs.mjs/loader/settings.js +3 -3
  55. package/dist/melonjs.mjs/math/color.js +21 -21
  56. package/dist/melonjs.mjs/math/math.js +2 -2
  57. package/dist/melonjs.mjs/math/matrix2.js +22 -22
  58. package/dist/melonjs.mjs/math/matrix3.js +52 -52
  59. package/dist/melonjs.mjs/math/observable_vector2.js +12 -12
  60. package/dist/melonjs.mjs/math/observable_vector3.js +22 -22
  61. package/dist/melonjs.mjs/math/vector2.js +11 -11
  62. package/dist/melonjs.mjs/math/vector3.js +21 -21
  63. package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/esm/arraymultimap.js +45 -0
  64. package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/esm/multimap.js +130 -0
  65. package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/arraymultimap.js +1 -1
  66. package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/index.js +1 -1
  67. package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/multimap.js +1 -1
  68. package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/setmultimap.js +1 -1
  69. package/dist/melonjs.mjs/node_modules/earcut/src/earcut.js +1 -1
  70. package/dist/melonjs.mjs/node_modules/eventemitter3/index.js +2 -2
  71. package/dist/melonjs.mjs/node_modules/eventemitter3/index2.js +1 -1
  72. package/dist/melonjs.mjs/node_modules/howler/dist/howler.js +1 -1
  73. package/dist/melonjs.mjs/particles/emitter.js +5 -5
  74. package/dist/melonjs.mjs/particles/particle.js +8 -8
  75. package/dist/melonjs.mjs/particles/settings.js +3 -3
  76. package/dist/melonjs.mjs/physics/body.js +17 -17
  77. package/dist/melonjs.mjs/physics/bounds.js +12 -12
  78. package/dist/melonjs.mjs/physics/collision.js +3 -3
  79. package/dist/melonjs.mjs/physics/detector.js +14 -14
  80. package/dist/melonjs.mjs/physics/quadtree.js +19 -19
  81. package/dist/melonjs.mjs/physics/response.js +1 -1
  82. package/dist/melonjs.mjs/physics/sat.js +60 -60
  83. package/dist/melonjs.mjs/physics/world.js +4 -4
  84. package/dist/melonjs.mjs/plugin/plugin.js +11 -11
  85. package/dist/melonjs.mjs/renderable/collectable.js +2 -2
  86. package/dist/melonjs.mjs/renderable/colorlayer.js +1 -1
  87. package/dist/melonjs.mjs/renderable/container.js +107 -63
  88. package/dist/melonjs.mjs/renderable/dragndrop.js +5 -5
  89. package/dist/melonjs.mjs/renderable/imagelayer.js +7 -6
  90. package/dist/melonjs.mjs/renderable/light2d.js +6 -6
  91. package/dist/melonjs.mjs/renderable/nineslicesprite.js +12 -12
  92. package/dist/melonjs.mjs/renderable/renderable.js +11 -11
  93. package/dist/melonjs.mjs/renderable/sprite.js +25 -25
  94. package/dist/melonjs.mjs/renderable/trigger.js +11 -9
  95. package/dist/melonjs.mjs/renderable/ui/uibaseelement.js +97 -27
  96. package/dist/melonjs.mjs/renderable/ui/uispriteelement.js +25 -25
  97. package/dist/melonjs.mjs/renderable/ui/uitextbutton.js +83 -63
  98. package/dist/melonjs.mjs/state/stage.js +7 -7
  99. package/dist/melonjs.mjs/state/state.js +15 -15
  100. package/dist/melonjs.mjs/system/device.js +2 -2
  101. package/dist/melonjs.mjs/system/dom.js +1 -1
  102. package/dist/melonjs.mjs/system/event.js +2 -2
  103. package/dist/melonjs.mjs/system/platform.js +1 -1
  104. package/dist/melonjs.mjs/system/pooling.js +9 -9
  105. package/dist/melonjs.mjs/system/save.js +6 -6
  106. package/dist/melonjs.mjs/system/timer.js +16 -12
  107. package/dist/melonjs.mjs/text/bitmaptext.js +20 -20
  108. package/dist/melonjs.mjs/text/bitmaptextdata.js +22 -22
  109. package/dist/melonjs.mjs/text/glyph.js +3 -3
  110. package/dist/melonjs.mjs/text/text.js +10 -9
  111. package/dist/melonjs.mjs/text/textmetrics.js +15 -15
  112. package/dist/melonjs.mjs/text/textstyle.js +1 -1
  113. package/dist/melonjs.mjs/tweens/easing.js +4 -4
  114. package/dist/melonjs.mjs/tweens/interpolation.js +8 -8
  115. package/dist/melonjs.mjs/tweens/tween.js +11 -11
  116. package/dist/melonjs.mjs/utils/agent.js +6 -6
  117. package/dist/melonjs.mjs/utils/array.js +4 -4
  118. package/dist/melonjs.mjs/utils/file.js +1 -1
  119. package/dist/melonjs.mjs/utils/function.js +5 -5
  120. package/dist/melonjs.mjs/utils/string.js +3 -3
  121. package/dist/melonjs.mjs/utils/utils.js +16 -16
  122. package/dist/melonjs.mjs/video/canvas/canvas_renderer.js +35 -109
  123. package/dist/melonjs.mjs/video/renderer.js +74 -7
  124. package/dist/melonjs.mjs/video/texture/atlas.js +37 -37
  125. package/dist/melonjs.mjs/video/texture/cache.js +9 -10
  126. package/dist/melonjs.mjs/video/texture/canvas_texture.js +63 -3
  127. package/dist/melonjs.mjs/video/utils/autodetect.js +1 -1
  128. package/dist/melonjs.mjs/video/video.js +2 -2
  129. package/dist/melonjs.mjs/video/webgl/buffer/vertex.js +3 -3
  130. package/dist/melonjs.mjs/video/webgl/compositors/compositor.js +5 -5
  131. package/dist/melonjs.mjs/video/webgl/compositors/primitive_compositor.js +5 -5
  132. package/dist/melonjs.mjs/video/webgl/compositors/quad_compositor.js +18 -15
  133. package/dist/melonjs.mjs/video/webgl/glshader.js +7 -7
  134. package/dist/melonjs.mjs/video/webgl/shaders/primitive.frag.js +1 -1
  135. package/dist/melonjs.mjs/video/webgl/shaders/primitive.vert.js +1 -1
  136. package/dist/melonjs.mjs/video/webgl/shaders/quad.frag.js +1 -1
  137. package/dist/melonjs.mjs/video/webgl/shaders/quad.vert.js +1 -1
  138. package/dist/melonjs.mjs/video/webgl/utils/attributes.js +2 -2
  139. package/dist/melonjs.mjs/video/webgl/utils/precision.js +1 -1
  140. package/dist/melonjs.mjs/video/webgl/utils/program.js +7 -7
  141. package/dist/melonjs.mjs/video/webgl/utils/string.js +1 -1
  142. package/dist/melonjs.mjs/video/webgl/utils/uniforms.js +4 -4
  143. package/dist/melonjs.mjs/video/webgl/webgl_renderer.js +55 -38
  144. package/dist/melonjs.module.js +1777 -1813
  145. package/dist/types/application/application.d.ts +11 -8
  146. package/dist/types/audio/audio.d.ts +3 -3
  147. package/dist/types/index.d.ts +4 -3
  148. package/dist/types/input/input.d.ts +1 -1
  149. package/dist/types/input/keyboard.d.ts +1 -1
  150. package/dist/types/input/pointerevent.d.ts +6 -6
  151. package/dist/types/level/level.d.ts +2 -2
  152. package/dist/types/level/tiled/TMXLayer.d.ts +4 -4
  153. package/dist/types/level/tiled/TMXTileMap.d.ts +2 -2
  154. package/dist/types/level/tiled/TMXUtils.d.ts +5 -4
  155. package/dist/types/loader/loader.d.ts +2 -2
  156. package/dist/types/loader/settings.d.ts +2 -2
  157. package/dist/types/particles/emitter.d.ts +1 -1
  158. package/dist/types/physics/collision.d.ts +1 -1
  159. package/dist/types/physics/detector.d.ts +1 -1
  160. package/dist/types/plugin/plugin.d.ts +2 -2
  161. package/dist/types/renderable/container.d.ts +21 -17
  162. package/dist/types/renderable/sprite.d.ts +11 -11
  163. package/dist/types/renderable/trigger.d.ts +1 -1
  164. package/dist/types/renderable/ui/uibaseelement.d.ts +28 -6
  165. package/dist/types/renderable/ui/uispriteelement.d.ts +12 -14
  166. package/dist/types/renderable/ui/uitextbutton.d.ts +52 -11
  167. package/dist/types/state/stage.d.ts +1 -1
  168. package/dist/types/system/device.d.ts +1 -1
  169. package/dist/types/system/pooling.d.ts +3 -3
  170. package/dist/types/system/timer.d.ts +5 -5
  171. package/dist/types/text/bitmaptext.d.ts +1 -1
  172. package/dist/types/text/text.d.ts +1 -1
  173. package/dist/types/utils/array.d.ts +2 -2
  174. package/dist/types/video/canvas/canvas_renderer.d.ts +8 -76
  175. package/dist/types/video/renderer.d.ts +48 -0
  176. package/dist/types/video/texture/atlas.d.ts +3 -3
  177. package/dist/types/video/texture/canvas_texture.d.ts +40 -0
  178. package/dist/types/video/webgl/glshader.d.ts +1 -1
  179. package/dist/types/video/webgl/webgl_renderer.d.ts +13 -9
  180. package/package.json +14 -14
  181. package/src/application/application.js +26 -16
  182. package/src/application/header.js +5 -4
  183. package/src/application/resize.js +19 -19
  184. package/src/audio/audio.js +16 -16
  185. package/src/camera/camera2d.js +9 -9
  186. package/src/entity/entity.js +3 -3
  187. package/src/geometries/ellipse.js +5 -5
  188. package/src/geometries/line.js +8 -8
  189. package/src/geometries/path2d.js +52 -52
  190. package/src/geometries/point.js +1 -1
  191. package/src/geometries/poly.js +28 -28
  192. package/src/geometries/rectangle.js +7 -7
  193. package/src/geometries/roundrect.js +5 -5
  194. package/src/index.js +3 -2
  195. package/src/input/gamepad.js +29 -29
  196. package/src/input/input.js +1 -1
  197. package/src/input/keyboard.js +14 -14
  198. package/src/input/pointer.js +1 -1
  199. package/src/input/pointerevent.js +52 -52
  200. package/src/lang/console.js +2 -2
  201. package/src/lang/deprecated.js +1 -1
  202. package/src/level/level.js +8 -8
  203. package/src/level/tiled/TMXGroup.js +2 -2
  204. package/src/level/tiled/TMXLayer.js +30 -30
  205. package/src/level/tiled/TMXObject.js +7 -7
  206. package/src/level/tiled/TMXTile.js +7 -7
  207. package/src/level/tiled/TMXTileMap.js +18 -18
  208. package/src/level/tiled/TMXTileset.js +14 -14
  209. package/src/level/tiled/TMXTilesetGroup.js +2 -2
  210. package/src/level/tiled/TMXUtils.js +45 -40
  211. package/src/level/tiled/renderer/TMXHexagonalRenderer.js +29 -29
  212. package/src/level/tiled/renderer/TMXIsometricRenderer.js +20 -20
  213. package/src/level/tiled/renderer/TMXOrthogonalRenderer.js +9 -9
  214. package/src/level/tiled/renderer/TMXRenderer.js +1 -1
  215. package/src/level/tiled/renderer/TMXStaggeredRenderer.js +5 -5
  216. package/src/loader/loader.js +6 -6
  217. package/src/loader/loadingscreen.js +1 -1
  218. package/src/loader/parser.js +12 -12
  219. package/src/loader/settings.js +2 -2
  220. package/src/math/color.js +20 -20
  221. package/src/math/math.js +1 -1
  222. package/src/math/matrix2.js +21 -21
  223. package/src/math/matrix3.js +51 -51
  224. package/src/math/observable_vector2.js +11 -11
  225. package/src/math/observable_vector3.js +21 -21
  226. package/src/math/vector2.js +10 -10
  227. package/src/math/vector3.js +20 -20
  228. package/src/particles/emitter.js +4 -4
  229. package/src/particles/particle.js +7 -7
  230. package/src/particles/settings.js +2 -2
  231. package/src/physics/body.js +16 -16
  232. package/src/physics/bounds.js +11 -11
  233. package/src/physics/collision.js +2 -2
  234. package/src/physics/detector.js +13 -13
  235. package/src/physics/quadtree.js +18 -18
  236. package/src/physics/sat.js +59 -59
  237. package/src/physics/world.js +3 -3
  238. package/src/plugin/plugin.js +8 -8
  239. package/src/renderable/collectable.js +1 -1
  240. package/src/renderable/container.js +106 -62
  241. package/src/renderable/dragndrop.js +4 -4
  242. package/src/renderable/imagelayer.js +6 -5
  243. package/src/renderable/light2d.js +5 -5
  244. package/src/renderable/nineslicesprite.js +11 -11
  245. package/src/renderable/renderable.js +10 -10
  246. package/src/renderable/sprite.js +24 -24
  247. package/src/renderable/trigger.js +10 -8
  248. package/src/renderable/ui/uibaseelement.js +96 -26
  249. package/src/renderable/ui/uispriteelement.js +24 -24
  250. package/src/renderable/ui/uitextbutton.js +85 -65
  251. package/src/state/stage.js +6 -6
  252. package/src/state/state.js +14 -14
  253. package/src/system/device.js +1 -1
  254. package/src/system/event.js +1 -1
  255. package/src/system/pooling.js +8 -8
  256. package/src/system/save.js +5 -5
  257. package/src/system/timer.js +15 -11
  258. package/src/text/bitmaptext.js +19 -19
  259. package/src/text/bitmaptextdata.js +21 -21
  260. package/src/text/glyph.js +2 -2
  261. package/src/text/text.js +9 -8
  262. package/src/text/textmetrics.js +14 -14
  263. package/src/tweens/easing.js +3 -3
  264. package/src/tweens/interpolation.js +7 -7
  265. package/src/tweens/tween.js +10 -10
  266. package/src/utils/agent.js +5 -5
  267. package/src/utils/array.js +3 -3
  268. package/src/utils/function.js +4 -4
  269. package/src/utils/string.js +2 -2
  270. package/src/utils/utils.js +15 -15
  271. package/src/video/canvas/canvas_renderer.js +34 -108
  272. package/src/video/renderer.js +72 -5
  273. package/src/video/texture/atlas.js +36 -36
  274. package/src/video/texture/cache.js +6 -6
  275. package/src/video/texture/canvas_texture.js +62 -2
  276. package/src/video/video.js +1 -1
  277. package/src/video/webgl/buffer/vertex.js +2 -2
  278. package/src/video/webgl/compositors/compositor.js +4 -4
  279. package/src/video/webgl/compositors/primitive_compositor.js +4 -4
  280. package/src/video/webgl/compositors/quad_compositor.js +17 -14
  281. package/src/video/webgl/glshader.js +6 -6
  282. package/src/video/webgl/utils/attributes.js +1 -1
  283. package/src/video/webgl/utils/program.js +6 -6
  284. package/src/video/webgl/utils/uniforms.js +3 -3
  285. package/src/video/webgl/webgl_renderer.js +54 -37
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * melonJS Game Engine - v15.0.0
2
+ * melonJS Game Engine - v15.1.1
3
3
  * http://www.melonjs.org
4
4
  * melonjs is licensed under the MIT License.
5
5
  * http://www.opensource.org/licenses/mit-license
@@ -64,12 +64,12 @@ let globalFloatingCounter = 0;
64
64
  this.children = undefined;
65
65
 
66
66
  /**
67
- * The property of the child object that should be used to sort on <br>
67
+ * The property of the child object that should be used to sort on this container
68
68
  * value : "x", "y", "z"
69
69
  * @type {string}
70
- * @default me.game.sortOn
70
+ * @default "z"
71
71
  */
72
- this.sortOn = game.sortOn;
72
+ this.sortOn = "z";
73
73
 
74
74
  /**
75
75
  * Specify if the children list should be automatically sorted when adding a new child
@@ -157,8 +157,8 @@ let globalFloatingCounter = 0;
157
157
  }
158
158
 
159
159
  // delete all children
160
- var children = this.getChildren();
161
- for (var i = children.length, child; i >= 0; (child = children[--i])) {
160
+ let children = this.getChildren();
161
+ for (let i = children.length, child; i >= 0; (child = children[--i])) {
162
162
  // don't remove it if a persistent object
163
163
  if (child && child.isPersistent !== true) {
164
164
  this.removeChildNow(child);
@@ -177,9 +177,9 @@ let globalFloatingCounter = 0;
177
177
  * Add a child to the container <br>
178
178
  * if auto-sort is disable, the object will be appended at the bottom of the list.
179
179
  * Adding a child to the container will automatically remove it from its other container.
180
- * Meaning a child can only have one parent. This is important if you add a renderable
181
- * to a container then add it to the me.game.world container it will move it out of the
182
- * orginal container. Then when the me.game.world.reset() is called the renderable
180
+ * Meaning a child can only have one parent. This is important if you add a renderable
181
+ * to a container then add it to the World container it will move it out of the
182
+ * orginal container. Then when the World container reset() method is called the renderable
183
183
  * will not be in any container. <br>
184
184
  * if the given child implements a onActivateEvent method, that method will be called
185
185
  * once the child is added to this container.
@@ -226,7 +226,7 @@ let globalFloatingCounter = 0;
226
226
 
227
227
  // force repaint in case this is a static non-animated object
228
228
  if (this.isAttachedToRoot() === true) {
229
- game.repaint();
229
+ this.isDirty = true;
230
230
  }
231
231
 
232
232
  // force bounds update if required
@@ -234,9 +234,22 @@ let globalFloatingCounter = 0;
234
234
  this.updateBounds();
235
235
  }
236
236
 
237
- // if a physic body is defined, add it to the game world
238
- if (child.body instanceof Body) {
239
- game.world.addBody(child.body);
237
+ // if a physic body(ies) to the game world
238
+ if (this.isAttachedToRoot()) {
239
+ var worldContainer = this.getRootAncestor();
240
+ if (child.body instanceof Body) {
241
+ worldContainer.addBody(child.body);
242
+ }
243
+ // if the child is a container
244
+ if (child instanceof Container) {
245
+ // add all container child bodies
246
+ // TODO: make it recursive ?
247
+ child.forEach((cchild) => {
248
+ if (cchild.body instanceof Body) {
249
+ worldContainer.addBody(cchild.body);
250
+ }
251
+ });
252
+ }
240
253
  }
241
254
 
242
255
  // triggered callback if defined
@@ -275,7 +288,7 @@ let globalFloatingCounter = 0;
275
288
 
276
289
  // force repaint in case this is a static non-animated object
277
290
  if (this.isAttachedToRoot() === true) {
278
- game.repaint();
291
+ this.isDirty = true;
279
292
  }
280
293
 
281
294
  // force bounds update if required
@@ -283,9 +296,22 @@ let globalFloatingCounter = 0;
283
296
  this.updateBounds();
284
297
  }
285
298
 
286
- // if a physic body is defined, add it to the game world
287
- if (child.body instanceof Body) {
288
- game.world.addBody(child.body);
299
+ // if a physic body(ies) to the game world
300
+ if (this.isAttachedToRoot()) {
301
+ var worldContainer = this.getRootAncestor();
302
+ if (child.body instanceof Body) {
303
+ worldContainer.addBody(child.body);
304
+ }
305
+ // if the child is a container
306
+ if (child instanceof Container) {
307
+ // add all container child bodies
308
+ // TODO: make it recursive ?
309
+ child.forEach((cchild) => {
310
+ if (cchild.body instanceof Body) {
311
+ worldContainer.addBody(cchild.body);
312
+ }
313
+ });
314
+ }
289
315
  }
290
316
 
291
317
  // triggered callback if defined
@@ -307,20 +333,20 @@ let globalFloatingCounter = 0;
307
333
  * @param {Function} callback - fnction to execute on each element
308
334
  * @param {object} [thisArg] - value to use as this(i.e reference Object) when executing callback.
309
335
  * @example
310
- * // iterate through all children of the root container
311
- * me.game.world.forEach((child) => {
336
+ * // iterate through all children of this container
337
+ * container.forEach((child) => {
312
338
  * // do something with the child
313
339
  * child.doSomething();
314
340
  * });
315
- * me.game.world.forEach((child, index) => { ... });
316
- * me.game.world.forEach((child, index, array) => { ... });
317
- * me.game.world.forEach((child, index, array) => { ... }, thisArg);
341
+ * container.forEach((child, index) => { ... });
342
+ * container.forEach((child, index, array) => { ... });
343
+ * container.forEach((child, index, array) => { ... }, thisArg);
318
344
  */
319
345
  forEach(callback, thisArg) {
320
- var context = this, i = 0;
321
- var children = this.getChildren();
346
+ let context = this, i = 0;
347
+ let children = this.getChildren();
322
348
 
323
- var len = children.length;
349
+ let len = children.length;
324
350
 
325
351
  if (typeof callback !== "function") {
326
352
  throw new Error(callback + " is not a function");
@@ -342,12 +368,12 @@ let globalFloatingCounter = 0;
342
368
  * @param {Renderable} child2
343
369
  */
344
370
  swapChildren(child, child2) {
345
- var index = this.getChildIndex(child);
346
- var index2 = this.getChildIndex(child2);
371
+ let index = this.getChildIndex(child);
372
+ let index2 = this.getChildIndex(child2);
347
373
 
348
374
  if ((index !== -1) && (index2 !== -1)) {
349
375
  // swap z index
350
- var _z = child.pos.z;
376
+ let _z = child.pos.z;
351
377
  child.pos.z = child2.pos.z;
352
378
  child2.pos.z = _z;
353
379
  // swap the positions..
@@ -390,7 +416,7 @@ let globalFloatingCounter = 0;
390
416
  * @returns {Renderable} child
391
417
  */
392
418
  getNextChild(child) {
393
- var index = this.getChildren().indexOf(child) - 1;
419
+ let index = this.getChildren().indexOf(child) - 1;
394
420
  if (index >= 0 && index < this.getChildren().length) {
395
421
  return this.getChildAt(index);
396
422
  }
@@ -415,27 +441,27 @@ let globalFloatingCounter = 0;
415
441
  * @returns {Renderable[]} Array of childs
416
442
  * @example
417
443
  * // get the first child object called "mainPlayer" in a specific container :
418
- * var ent = myContainer.getChildByProp("name", "mainPlayer");
444
+ * let ent = myContainer.getChildByProp("name", "mainPlayer");
419
445
  *
420
446
  * // or query the whole world :
421
- * var ent = me.game.world.getChildByProp("name", "mainPlayer");
447
+ * let ent = container.getChildByProp("name", "mainPlayer");
422
448
  *
423
449
  * // partial property matches are also allowed by using a RegExp.
424
450
  * // the following matches "redCOIN", "bluecoin", "bagOfCoins", etc :
425
- * var allCoins = me.game.world.getChildByProp("name", /coin/i);
451
+ * let allCoins = container.getChildByProp("name", /coin/i);
426
452
  *
427
453
  * // searching for numbers or other data types :
428
- * var zIndex10 = me.game.world.getChildByProp("z", 10);
429
- * var inViewport = me.game.world.getChildByProp("inViewport", true);
454
+ * let zIndex10 = container.getChildByProp("z", 10);
455
+ * let inViewport = container.getChildByProp("inViewport", true);
430
456
  */
431
457
  getChildByProp(prop, value) {
432
- var objList = [];
458
+ let objList = [];
433
459
 
434
460
  /**
435
461
  * @ignore
436
462
  */
437
463
  function compare(obj, prop) {
438
- var v = obj[prop];
464
+ let v = obj[prop];
439
465
  if (value instanceof RegExp && typeof(v) === "string") {
440
466
  if (value.test(v)) {
441
467
  objList.push(obj);
@@ -462,7 +488,7 @@ let globalFloatingCounter = 0;
462
488
  * @returns {Renderable[]} Array of children
463
489
  */
464
490
  getChildByType(classType) {
465
- var objList = [];
491
+ let objList = [];
466
492
 
467
493
  this.forEach((child) => {
468
494
  if (child instanceof classType) {
@@ -496,7 +522,7 @@ let globalFloatingCounter = 0;
496
522
  * @returns {Renderable} corresponding child or null
497
523
  */
498
524
  getChildByGUID(guid) {
499
- var obj = this.getChildByProp("GUID", guid);
525
+ let obj = this.getChildByProp("GUID", guid);
500
526
  return (obj.length > 0) ? obj[0] : null;
501
527
  }
502
528
 
@@ -518,7 +544,7 @@ let globalFloatingCounter = 0;
518
544
  * @returns {Bounds} this shape bounding box Rectangle object
519
545
  */
520
546
  updateBounds(absolute = true) {
521
- var bounds = this.getBounds();
547
+ let bounds = this.getBounds();
522
548
 
523
549
  // call parent method
524
550
  super.updateBounds(absolute);
@@ -526,7 +552,7 @@ let globalFloatingCounter = 0;
526
552
  if (this.enableChildBoundsUpdate === true) {
527
553
  this.forEach((child) => {
528
554
  if (child.isRenderable) {
529
- var childBounds = child.getBounds();
555
+ let childBounds = child.getBounds();
530
556
  if (childBounds.isFinite()) {
531
557
  bounds.addBounds(childBounds);
532
558
  }
@@ -538,14 +564,13 @@ let globalFloatingCounter = 0;
538
564
 
539
565
  /**
540
566
  * Checks if this container is root or if it's attached to the root container.
541
- * @private
542
567
  * @returns {boolean}
543
568
  */
544
569
  isAttachedToRoot() {
545
570
  if (this.root === true) {
546
571
  return true;
547
572
  } else {
548
- var ancestor = this.ancestor;
573
+ let ancestor = this.ancestor;
549
574
  while (ancestor) {
550
575
  if (ancestor.root === true) {
551
576
  return true;
@@ -556,6 +581,25 @@ let globalFloatingCounter = 0;
556
581
  }
557
582
  }
558
583
 
584
+ /**
585
+ * Returns the instance of the root container (i.e. the current application World container).
586
+ * @returns {Container}
587
+ */
588
+ getRootAncestor() {
589
+ if (this.root === true) {
590
+ return this;
591
+ } else {
592
+ let ancestor = this.ancestor;
593
+ while (ancestor) {
594
+ if (ancestor.root === true) {
595
+ break;
596
+ }
597
+ ancestor = ancestor.ancestor;
598
+ }
599
+ return ancestor;
600
+ }
601
+ }
602
+
559
603
  /**
560
604
  * update the cointainer's bounding rect (private)
561
605
  * @ignore
@@ -617,7 +661,7 @@ let globalFloatingCounter = 0;
617
661
  // remove the body first to avoid a condition where a body can be detached
618
662
  // from its parent, before the body is removed from the game world
619
663
  if (child.body instanceof Body) {
620
- game.world.removeBody(child.body);
664
+ this.getRootAncestor().removeBody(child.body);
621
665
  }
622
666
 
623
667
  if (!keepalive) {
@@ -632,7 +676,7 @@ let globalFloatingCounter = 0;
632
676
 
633
677
  // Don't cache the child index; another element might have been removed
634
678
  // by the child's `onDeactivateEvent` or `destroy` methods
635
- var childIndex = this.getChildIndex(child);
679
+ let childIndex = this.getChildIndex(child);
636
680
  if (childIndex >= 0) {
637
681
  this.getChildren().splice(childIndex, 1);
638
682
  child.ancestor = undefined;
@@ -640,7 +684,7 @@ let globalFloatingCounter = 0;
640
684
 
641
685
  // force repaint in case this is a static non-animated object
642
686
  if (this.isAttachedToRoot() === true) {
643
- game.repaint();
687
+ this.isDirty = true;
644
688
  }
645
689
 
646
690
  // force bounds update if required
@@ -673,7 +717,7 @@ let globalFloatingCounter = 0;
673
717
  * @param {Renderable} child
674
718
  */
675
719
  moveUp(child) {
676
- var childIndex = this.getChildIndex(child);
720
+ let childIndex = this.getChildIndex(child);
677
721
  if (childIndex - 1 >= 0) {
678
722
  // note : we use an inverted loop
679
723
  this.swapChildren(child, this.getChildAt(childIndex - 1));
@@ -687,7 +731,7 @@ let globalFloatingCounter = 0;
687
731
  * @param {Renderable} child
688
732
  */
689
733
  moveDown(child) {
690
- var childIndex = this.getChildIndex(child);
734
+ let childIndex = this.getChildIndex(child);
691
735
  if (childIndex >= 0 && (childIndex + 1) < this.getChildren().length) {
692
736
  // note : we use an inverted loop
693
737
  this.swapChildren(child, this.getChildAt(childIndex + 1));
@@ -701,9 +745,9 @@ let globalFloatingCounter = 0;
701
745
  * @param {Renderable} child
702
746
  */
703
747
  moveToTop(child) {
704
- var childIndex = this.getChildIndex(child);
748
+ let childIndex = this.getChildIndex(child);
705
749
  if (childIndex > 0) {
706
- var children = this.getChildren();
750
+ let children = this.getChildren();
707
751
  // note : we use an inverted loop
708
752
  children.splice(0, 0, children.splice(childIndex, 1)[0]);
709
753
  // increment our child z value based on the previous child depth
@@ -718,8 +762,8 @@ let globalFloatingCounter = 0;
718
762
  * @param {Renderable} child
719
763
  */
720
764
  moveToBottom(child) {
721
- var childIndex = this.getChildIndex(child);
722
- var children = this.getChildren();
765
+ let childIndex = this.getChildIndex(child);
766
+ let children = this.getChildren();
723
767
  if (childIndex >= 0 && childIndex < (children.length - 1)) {
724
768
  // note : we use an inverted loop
725
769
  children.splice((children.length - 1), 0, children.splice(childIndex, 1)[0]);
@@ -753,7 +797,7 @@ let globalFloatingCounter = 0;
753
797
  // clear the defer id
754
798
  this.pendingSort = null;
755
799
  // make sure we redraw everything
756
- game.repaint();
800
+ this.isDirty = true;
757
801
  }, this);
758
802
  }
759
803
  }
@@ -793,7 +837,7 @@ let globalFloatingCounter = 0;
793
837
  if (!b.pos || !a.pos) {
794
838
  return (a.pos ? -Infinity : Infinity);
795
839
  }
796
- var result = b.pos.z - a.pos.z;
840
+ let result = b.pos.z - a.pos.z;
797
841
  return (result ? result : (b.pos.x - a.pos.x));
798
842
  }
799
843
 
@@ -805,7 +849,7 @@ let globalFloatingCounter = 0;
805
849
  if (!b.pos || !a.pos) {
806
850
  return (a.pos ? -Infinity : Infinity);
807
851
  }
808
- var result = b.pos.z - a.pos.z;
852
+ let result = b.pos.z - a.pos.z;
809
853
  return (result ? result : (b.pos.y - a.pos.y));
810
854
  }
811
855
 
@@ -822,17 +866,17 @@ let globalFloatingCounter = 0;
822
866
 
823
867
  /**
824
868
  * container update function. <br>
825
- * automatically called by the game manager {@link game}
869
+ * automatically called by the application update loop {@link Application}
826
870
  * @protected
827
871
  * @param {number} dt - time since the last update in milliseconds.
828
872
  * @returns {boolean} true if the Container is dirty
829
873
  */
830
874
  update(dt) {
831
- var isFloating = false;
832
- var isPaused = state.isPaused();
833
- var children = this.getChildren();
875
+ let isFloating = false;
876
+ let isPaused = state.isPaused();
877
+ let children = this.getChildren();
834
878
 
835
- for (var i = children.length, obj; i--, (obj = children[i]);) {
879
+ for (let i = children.length, obj; i--, (obj = children[i]);) {
836
880
  if (isPaused && (!obj.updateWhenPaused)) {
837
881
  // skip this object
838
882
  continue;
@@ -877,8 +921,8 @@ let globalFloatingCounter = 0;
877
921
  * @param {Camera2d} [viewport] - the viewport to (re)draw
878
922
  */
879
923
  draw(renderer, viewport) {
880
- var isFloating = false;
881
- var bounds = this.getBounds();
924
+ let isFloating = false;
925
+ let bounds = this.getBounds();
882
926
 
883
927
  this.drawCount = 0;
884
928
 
@@ -900,8 +944,8 @@ let globalFloatingCounter = 0;
900
944
  renderer.clearColor(this.backgroundColor);
901
945
  }
902
946
 
903
- var children = this.getChildren();
904
- for (var i = children.length, obj; i--, (obj = children[i]);) {
947
+ let children = this.getChildren();
948
+ for (let i = children.length, obj; i--, (obj = children[i]);) {
905
949
  if (obj.isRenderable) {
906
950
 
907
951
  isFloating = obj.floating === true;
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * melonJS Game Engine - v15.0.0
2
+ * melonJS Game Engine - v15.1.1
3
3
  * http://www.melonjs.org
4
4
  * melonjs is licensed under the MIT License.
5
5
  * http://www.opensource.org/licenses/mit-license
@@ -43,10 +43,10 @@ class Draggable extends Renderable {
43
43
  * @private
44
44
  */
45
45
  initEvents() {
46
- registerPointerEvent("pointerdown", this, (e) => { emit(DRAGSTART, e, this); });
47
- registerPointerEvent("pointerup", this, (e) => { emit(DRAGEND, e, this); });
48
- registerPointerEvent("pointercancel", this, (e) => { emit(DRAGEND, e, this); });
49
- on(POINTERMOVE, this.dragMove.bind(this));
46
+ registerPointerEvent("pointerdown", this, (e) => emit(DRAGSTART, e, this));
47
+ registerPointerEvent("pointerup", this, (e) => emit(DRAGEND, e, this));
48
+ registerPointerEvent("pointercancel", this, (e) => emit(DRAGEND, e, this));
49
+ on(POINTERMOVE, (e) => this.dragMove(e));
50
50
  on(DRAGSTART, (e, draggable) => {
51
51
  if (draggable === this) {
52
52
  this.dragStart(e);
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * melonJS Game Engine - v15.0.0
2
+ * melonJS Game Engine - v15.1.1
3
3
  * http://www.melonjs.org
4
4
  * melonjs is licensed under the MIT License.
5
5
  * http://www.opensource.org/licenses/mit-license
@@ -189,7 +189,7 @@ import { isNumeric } from '../utils/string.js';
189
189
  * @ignore
190
190
  */
191
191
  updateLayer(vpos) {
192
- var rx = this.ratio.x,
192
+ const rx = this.ratio.x,
193
193
  ry = this.ratio.y;
194
194
 
195
195
  if (rx === 0 && ry === 0) {
@@ -197,7 +197,7 @@ import { isNumeric } from '../utils/string.js';
197
197
  return;
198
198
  }
199
199
 
200
- var width = this.width,
200
+ const width = this.width,
201
201
  height = this.height,
202
202
  bw = game.viewport.bounds.width,
203
203
  bh = game.viewport.bounds.height,
@@ -263,13 +263,14 @@ import { isNumeric } from '../utils/string.js';
263
263
  * @param {Camera2d} [viewport] - the viewport to (re)draw
264
264
  */
265
265
  draw(renderer, viewport) {
266
- var width = this.width,
266
+ const width = this.width,
267
267
  height = this.height,
268
268
  bw = viewport.bounds.width,
269
269
  bh = viewport.bounds.height,
270
270
  ax = this.anchorPoint.x,
271
- ay = this.anchorPoint.y,
272
- x = this.pos.x,
271
+ ay = this.anchorPoint.y;
272
+
273
+ let x = this.pos.x,
273
274
  y = this.pos.y;
274
275
 
275
276
  if (this.ratio.x === 0 && this.ratio.y === 0) {
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * melonJS Game Engine - v15.0.0
2
+ * melonJS Game Engine - v15.1.1
3
3
  * http://www.melonjs.org
4
4
  * melonjs is licensed under the MIT License.
5
5
  * http://www.opensource.org/licenses/mit-license
@@ -10,16 +10,16 @@ import Renderable from './renderable.js';
10
10
 
11
11
  /** @ignore */
12
12
  function createGradient(light) {
13
- var context = light.texture.context;
13
+ let context = light.texture.context;
14
14
 
15
- var x1 = light.texture.width / 2,
15
+ let x1 = light.texture.width / 2,
16
16
  y1 = light.texture.height / 2;
17
17
 
18
- var radiusX = light.radiusX,
18
+ let radiusX = light.radiusX,
19
19
  radiusY = light.radiusY;
20
20
 
21
- var scaleX, scaleY, invScaleX, invScaleY;
22
- var gradient;
21
+ let scaleX, scaleY, invScaleX, invScaleY;
22
+ let gradient;
23
23
 
24
24
 
25
25
  light.texture.clear();
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * melonJS Game Engine - v15.0.0
2
+ * melonJS Game Engine - v15.1.1
3
3
  * http://www.melonjs.org
4
4
  * melonjs is licensed under the MIT License.
5
5
  * http://www.opensource.org/licenses/mit-license
@@ -93,18 +93,18 @@ import Sprite from './sprite.js';
93
93
  */
94
94
  draw(renderer) {
95
95
  // the frame to draw
96
- var frame = this.current;
96
+ let frame = this.current;
97
97
 
98
98
  // cache the current position and size
99
- var dx = this.pos.x,
99
+ let dx = this.pos.x,
100
100
  dy = this.pos.y;
101
101
 
102
- var w = frame.width,
102
+ let w = frame.width,
103
103
  h = frame.height;
104
104
 
105
105
  // frame offset in the texture/atlas
106
- var frame_offset = frame.offset;
107
- var g_offset = this.offset;
106
+ let frame_offset = frame.offset;
107
+ let g_offset = this.offset;
108
108
 
109
109
 
110
110
  // remove image's TexturePacker/ShoeBox rotation
@@ -116,11 +116,11 @@ import Sprite from './sprite.js';
116
116
  h = frame.width;
117
117
  }
118
118
 
119
- var sx = g_offset.x + frame_offset.x,
119
+ let sx = g_offset.x + frame_offset.x,
120
120
  sy = g_offset.y + frame_offset.y;
121
121
 
122
122
  // should this be configurable ?
123
- var corner_width = this.insetx || w / 4,
123
+ let corner_width = this.insetx || w / 4,
124
124
  corner_height = this.insety || h / 4;
125
125
 
126
126
  // OPTIMIZE ME !
@@ -170,11 +170,11 @@ import Sprite from './sprite.js';
170
170
 
171
171
 
172
172
  // DRAW SIDES and CENTER
173
- var image_center_width = w - (corner_width << 1);
174
- var image_center_height = h - (corner_height << 1);
173
+ let image_center_width = w - (corner_width << 1);
174
+ let image_center_height = h - (corner_height << 1);
175
175
 
176
- var target_center_width = this.nss_width - (corner_width << 1);
177
- var target_center_height = this.nss_height - (corner_height << 1);
176
+ let target_center_width = this.nss_width - (corner_width << 1);
177
+ let target_center_height = this.nss_height - (corner_height << 1);
178
178
 
179
179
  //Top center
180
180
  renderer.drawImage(
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * melonJS Game Engine - v15.0.0
2
+ * melonJS Game Engine - v15.1.1
3
3
  * http://www.melonjs.org
4
4
  * melonjs is licensed under the MIT License.
5
5
  * http://www.opensource.org/licenses/mit-license
@@ -433,11 +433,11 @@ import { releaseAllPointerEvents } from '../input/pointerevent.js';
433
433
  * @returns {number} angle in radians
434
434
  */
435
435
  angleTo(target) {
436
- var a = this.getBounds();
437
- var ax, ay;
436
+ let a = this.getBounds();
437
+ let ax, ay;
438
438
 
439
439
  if (target instanceof Renderable) {
440
- var b = target.getBounds();
440
+ let b = target.getBounds();
441
441
  ax = b.centerX - a.centerX;
442
442
  ay = b.centerY - a.centerY;
443
443
  } else { // vector object
@@ -454,11 +454,11 @@ import { releaseAllPointerEvents } from '../input/pointerevent.js';
454
454
  * @returns {number} distance
455
455
  */
456
456
  distanceTo(target) {
457
- var a = this.getBounds();
458
- var dx, dy;
457
+ let a = this.getBounds();
458
+ let dx, dy;
459
459
 
460
460
  if (target instanceof Renderable) {
461
- var b = target.getBounds();
461
+ let b = target.getBounds();
462
462
  dx = a.centerX - b.centerX;
463
463
  dy = a.centerY - b.centerY;
464
464
  } else { // vector object
@@ -475,7 +475,7 @@ import { releaseAllPointerEvents } from '../input/pointerevent.js';
475
475
  * @returns {Renderable} Reference to this object for method chaining
476
476
  */
477
477
  lookAt(target) {
478
- var position;
478
+ let position;
479
479
 
480
480
  if (target instanceof Renderable) {
481
481
  position = target.pos;
@@ -483,7 +483,7 @@ import { releaseAllPointerEvents } from '../input/pointerevent.js';
483
483
  position = target;
484
484
  }
485
485
 
486
- var angle = this.angleTo(position);
486
+ let angle = this.angleTo(position);
487
487
 
488
488
  this.rotate(angle);
489
489
 
@@ -548,7 +548,7 @@ import { releaseAllPointerEvents } from '../input/pointerevent.js';
548
548
  */
549
549
  updateBounds(absolute = true) {
550
550
  if (this.isRenderable) {
551
- var bounds = this.getBounds();
551
+ let bounds = this.getBounds();
552
552
 
553
553
  bounds.clear();
554
554
 
@@ -646,7 +646,7 @@ import { releaseAllPointerEvents } from '../input/pointerevent.js';
646
646
  * @param {CanvasRenderer|WebGLRenderer} renderer - a renderer object
647
647
  */
648
648
  preDraw(renderer) {
649
- var ax = this.width * this.anchorPoint.x,
649
+ let ax = this.width * this.anchorPoint.x,
650
650
  ay = this.height * this.anchorPoint.y;
651
651
 
652
652
  // save renderer context