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
@@ -57,12 +57,12 @@ let globalFloatingCounter = 0;
57
57
  this.children = undefined;
58
58
 
59
59
  /**
60
- * The property of the child object that should be used to sort on <br>
60
+ * The property of the child object that should be used to sort on this container
61
61
  * value : "x", "y", "z"
62
62
  * @type {string}
63
- * @default me.game.sortOn
63
+ * @default "z"
64
64
  */
65
- this.sortOn = game.sortOn;
65
+ this.sortOn = "z";
66
66
 
67
67
  /**
68
68
  * Specify if the children list should be automatically sorted when adding a new child
@@ -150,8 +150,8 @@ let globalFloatingCounter = 0;
150
150
  }
151
151
 
152
152
  // delete all children
153
- var children = this.getChildren();
154
- for (var i = children.length, child; i >= 0; (child = children[--i])) {
153
+ let children = this.getChildren();
154
+ for (let i = children.length, child; i >= 0; (child = children[--i])) {
155
155
  // don't remove it if a persistent object
156
156
  if (child && child.isPersistent !== true) {
157
157
  this.removeChildNow(child);
@@ -170,9 +170,9 @@ let globalFloatingCounter = 0;
170
170
  * Add a child to the container <br>
171
171
  * if auto-sort is disable, the object will be appended at the bottom of the list.
172
172
  * Adding a child to the container will automatically remove it from its other container.
173
- * Meaning a child can only have one parent. This is important if you add a renderable
174
- * to a container then add it to the me.game.world container it will move it out of the
175
- * orginal container. Then when the me.game.world.reset() is called the renderable
173
+ * Meaning a child can only have one parent. This is important if you add a renderable
174
+ * to a container then add it to the World container it will move it out of the
175
+ * orginal container. Then when the World container reset() method is called the renderable
176
176
  * will not be in any container. <br>
177
177
  * if the given child implements a onActivateEvent method, that method will be called
178
178
  * once the child is added to this container.
@@ -219,7 +219,7 @@ let globalFloatingCounter = 0;
219
219
 
220
220
  // force repaint in case this is a static non-animated object
221
221
  if (this.isAttachedToRoot() === true) {
222
- game.repaint();
222
+ this.isDirty = true;
223
223
  }
224
224
 
225
225
  // force bounds update if required
@@ -227,9 +227,22 @@ let globalFloatingCounter = 0;
227
227
  this.updateBounds();
228
228
  }
229
229
 
230
- // if a physic body is defined, add it to the game world
231
- if (child.body instanceof Body) {
232
- game.world.addBody(child.body);
230
+ // if a physic body(ies) to the game world
231
+ if (this.isAttachedToRoot()) {
232
+ var worldContainer = this.getRootAncestor();
233
+ if (child.body instanceof Body) {
234
+ worldContainer.addBody(child.body);
235
+ }
236
+ // if the child is a container
237
+ if (child instanceof Container) {
238
+ // add all container child bodies
239
+ // TODO: make it recursive ?
240
+ child.forEach((cchild) => {
241
+ if (cchild.body instanceof Body) {
242
+ worldContainer.addBody(cchild.body);
243
+ }
244
+ });
245
+ }
233
246
  }
234
247
 
235
248
  // triggered callback if defined
@@ -268,7 +281,7 @@ let globalFloatingCounter = 0;
268
281
 
269
282
  // force repaint in case this is a static non-animated object
270
283
  if (this.isAttachedToRoot() === true) {
271
- game.repaint();
284
+ this.isDirty = true;
272
285
  }
273
286
 
274
287
  // force bounds update if required
@@ -276,9 +289,22 @@ let globalFloatingCounter = 0;
276
289
  this.updateBounds();
277
290
  }
278
291
 
279
- // if a physic body is defined, add it to the game world
280
- if (child.body instanceof Body) {
281
- game.world.addBody(child.body);
292
+ // if a physic body(ies) to the game world
293
+ if (this.isAttachedToRoot()) {
294
+ var worldContainer = this.getRootAncestor();
295
+ if (child.body instanceof Body) {
296
+ worldContainer.addBody(child.body);
297
+ }
298
+ // if the child is a container
299
+ if (child instanceof Container) {
300
+ // add all container child bodies
301
+ // TODO: make it recursive ?
302
+ child.forEach((cchild) => {
303
+ if (cchild.body instanceof Body) {
304
+ worldContainer.addBody(cchild.body);
305
+ }
306
+ });
307
+ }
282
308
  }
283
309
 
284
310
  // triggered callback if defined
@@ -300,20 +326,20 @@ let globalFloatingCounter = 0;
300
326
  * @param {Function} callback - fnction to execute on each element
301
327
  * @param {object} [thisArg] - value to use as this(i.e reference Object) when executing callback.
302
328
  * @example
303
- * // iterate through all children of the root container
304
- * me.game.world.forEach((child) => {
329
+ * // iterate through all children of this container
330
+ * container.forEach((child) => {
305
331
  * // do something with the child
306
332
  * child.doSomething();
307
333
  * });
308
- * me.game.world.forEach((child, index) => { ... });
309
- * me.game.world.forEach((child, index, array) => { ... });
310
- * me.game.world.forEach((child, index, array) => { ... }, thisArg);
334
+ * container.forEach((child, index) => { ... });
335
+ * container.forEach((child, index, array) => { ... });
336
+ * container.forEach((child, index, array) => { ... }, thisArg);
311
337
  */
312
338
  forEach(callback, thisArg) {
313
- var context = this, i = 0;
314
- var children = this.getChildren();
339
+ let context = this, i = 0;
340
+ let children = this.getChildren();
315
341
 
316
- var len = children.length;
342
+ let len = children.length;
317
343
 
318
344
  if (typeof callback !== "function") {
319
345
  throw new Error(callback + " is not a function");
@@ -335,12 +361,12 @@ let globalFloatingCounter = 0;
335
361
  * @param {Renderable} child2
336
362
  */
337
363
  swapChildren(child, child2) {
338
- var index = this.getChildIndex(child);
339
- var index2 = this.getChildIndex(child2);
364
+ let index = this.getChildIndex(child);
365
+ let index2 = this.getChildIndex(child2);
340
366
 
341
367
  if ((index !== -1) && (index2 !== -1)) {
342
368
  // swap z index
343
- var _z = child.pos.z;
369
+ let _z = child.pos.z;
344
370
  child.pos.z = child2.pos.z;
345
371
  child2.pos.z = _z;
346
372
  // swap the positions..
@@ -383,7 +409,7 @@ let globalFloatingCounter = 0;
383
409
  * @returns {Renderable} child
384
410
  */
385
411
  getNextChild(child) {
386
- var index = this.getChildren().indexOf(child) - 1;
412
+ let index = this.getChildren().indexOf(child) - 1;
387
413
  if (index >= 0 && index < this.getChildren().length) {
388
414
  return this.getChildAt(index);
389
415
  }
@@ -408,27 +434,27 @@ let globalFloatingCounter = 0;
408
434
  * @returns {Renderable[]} Array of childs
409
435
  * @example
410
436
  * // get the first child object called "mainPlayer" in a specific container :
411
- * var ent = myContainer.getChildByProp("name", "mainPlayer");
437
+ * let ent = myContainer.getChildByProp("name", "mainPlayer");
412
438
  *
413
439
  * // or query the whole world :
414
- * var ent = me.game.world.getChildByProp("name", "mainPlayer");
440
+ * let ent = container.getChildByProp("name", "mainPlayer");
415
441
  *
416
442
  * // partial property matches are also allowed by using a RegExp.
417
443
  * // the following matches "redCOIN", "bluecoin", "bagOfCoins", etc :
418
- * var allCoins = me.game.world.getChildByProp("name", /coin/i);
444
+ * let allCoins = container.getChildByProp("name", /coin/i);
419
445
  *
420
446
  * // searching for numbers or other data types :
421
- * var zIndex10 = me.game.world.getChildByProp("z", 10);
422
- * var inViewport = me.game.world.getChildByProp("inViewport", true);
447
+ * let zIndex10 = container.getChildByProp("z", 10);
448
+ * let inViewport = container.getChildByProp("inViewport", true);
423
449
  */
424
450
  getChildByProp(prop, value) {
425
- var objList = [];
451
+ let objList = [];
426
452
 
427
453
  /**
428
454
  * @ignore
429
455
  */
430
456
  function compare(obj, prop) {
431
- var v = obj[prop];
457
+ let v = obj[prop];
432
458
  if (value instanceof RegExp && typeof(v) === "string") {
433
459
  if (value.test(v)) {
434
460
  objList.push(obj);
@@ -455,7 +481,7 @@ let globalFloatingCounter = 0;
455
481
  * @returns {Renderable[]} Array of children
456
482
  */
457
483
  getChildByType(classType) {
458
- var objList = [];
484
+ let objList = [];
459
485
 
460
486
  this.forEach((child) => {
461
487
  if (child instanceof classType) {
@@ -489,7 +515,7 @@ let globalFloatingCounter = 0;
489
515
  * @returns {Renderable} corresponding child or null
490
516
  */
491
517
  getChildByGUID(guid) {
492
- var obj = this.getChildByProp("GUID", guid);
518
+ let obj = this.getChildByProp("GUID", guid);
493
519
  return (obj.length > 0) ? obj[0] : null;
494
520
  }
495
521
 
@@ -511,7 +537,7 @@ let globalFloatingCounter = 0;
511
537
  * @returns {Bounds} this shape bounding box Rectangle object
512
538
  */
513
539
  updateBounds(absolute = true) {
514
- var bounds = this.getBounds();
540
+ let bounds = this.getBounds();
515
541
 
516
542
  // call parent method
517
543
  super.updateBounds(absolute);
@@ -519,7 +545,7 @@ let globalFloatingCounter = 0;
519
545
  if (this.enableChildBoundsUpdate === true) {
520
546
  this.forEach((child) => {
521
547
  if (child.isRenderable) {
522
- var childBounds = child.getBounds();
548
+ let childBounds = child.getBounds();
523
549
  if (childBounds.isFinite()) {
524
550
  bounds.addBounds(childBounds);
525
551
  }
@@ -531,14 +557,13 @@ let globalFloatingCounter = 0;
531
557
 
532
558
  /**
533
559
  * Checks if this container is root or if it's attached to the root container.
534
- * @private
535
560
  * @returns {boolean}
536
561
  */
537
562
  isAttachedToRoot() {
538
563
  if (this.root === true) {
539
564
  return true;
540
565
  } else {
541
- var ancestor = this.ancestor;
566
+ let ancestor = this.ancestor;
542
567
  while (ancestor) {
543
568
  if (ancestor.root === true) {
544
569
  return true;
@@ -549,6 +574,25 @@ let globalFloatingCounter = 0;
549
574
  }
550
575
  }
551
576
 
577
+ /**
578
+ * Returns the instance of the root container (i.e. the current application World container).
579
+ * @returns {Container}
580
+ */
581
+ getRootAncestor() {
582
+ if (this.root === true) {
583
+ return this;
584
+ } else {
585
+ let ancestor = this.ancestor;
586
+ while (ancestor) {
587
+ if (ancestor.root === true) {
588
+ break;
589
+ }
590
+ ancestor = ancestor.ancestor;
591
+ }
592
+ return ancestor;
593
+ }
594
+ }
595
+
552
596
  /**
553
597
  * update the cointainer's bounding rect (private)
554
598
  * @ignore
@@ -610,7 +654,7 @@ let globalFloatingCounter = 0;
610
654
  // remove the body first to avoid a condition where a body can be detached
611
655
  // from its parent, before the body is removed from the game world
612
656
  if (child.body instanceof Body) {
613
- game.world.removeBody(child.body);
657
+ this.getRootAncestor().removeBody(child.body);
614
658
  }
615
659
 
616
660
  if (!keepalive) {
@@ -625,7 +669,7 @@ let globalFloatingCounter = 0;
625
669
 
626
670
  // Don't cache the child index; another element might have been removed
627
671
  // by the child's `onDeactivateEvent` or `destroy` methods
628
- var childIndex = this.getChildIndex(child);
672
+ let childIndex = this.getChildIndex(child);
629
673
  if (childIndex >= 0) {
630
674
  this.getChildren().splice(childIndex, 1);
631
675
  child.ancestor = undefined;
@@ -633,7 +677,7 @@ let globalFloatingCounter = 0;
633
677
 
634
678
  // force repaint in case this is a static non-animated object
635
679
  if (this.isAttachedToRoot() === true) {
636
- game.repaint();
680
+ this.isDirty = true;
637
681
  }
638
682
 
639
683
  // force bounds update if required
@@ -666,7 +710,7 @@ let globalFloatingCounter = 0;
666
710
  * @param {Renderable} child
667
711
  */
668
712
  moveUp(child) {
669
- var childIndex = this.getChildIndex(child);
713
+ let childIndex = this.getChildIndex(child);
670
714
  if (childIndex - 1 >= 0) {
671
715
  // note : we use an inverted loop
672
716
  this.swapChildren(child, this.getChildAt(childIndex - 1));
@@ -680,7 +724,7 @@ let globalFloatingCounter = 0;
680
724
  * @param {Renderable} child
681
725
  */
682
726
  moveDown(child) {
683
- var childIndex = this.getChildIndex(child);
727
+ let childIndex = this.getChildIndex(child);
684
728
  if (childIndex >= 0 && (childIndex + 1) < this.getChildren().length) {
685
729
  // note : we use an inverted loop
686
730
  this.swapChildren(child, this.getChildAt(childIndex + 1));
@@ -694,9 +738,9 @@ let globalFloatingCounter = 0;
694
738
  * @param {Renderable} child
695
739
  */
696
740
  moveToTop(child) {
697
- var childIndex = this.getChildIndex(child);
741
+ let childIndex = this.getChildIndex(child);
698
742
  if (childIndex > 0) {
699
- var children = this.getChildren();
743
+ let children = this.getChildren();
700
744
  // note : we use an inverted loop
701
745
  children.splice(0, 0, children.splice(childIndex, 1)[0]);
702
746
  // increment our child z value based on the previous child depth
@@ -711,8 +755,8 @@ let globalFloatingCounter = 0;
711
755
  * @param {Renderable} child
712
756
  */
713
757
  moveToBottom(child) {
714
- var childIndex = this.getChildIndex(child);
715
- var children = this.getChildren();
758
+ let childIndex = this.getChildIndex(child);
759
+ let children = this.getChildren();
716
760
  if (childIndex >= 0 && childIndex < (children.length - 1)) {
717
761
  // note : we use an inverted loop
718
762
  children.splice((children.length - 1), 0, children.splice(childIndex, 1)[0]);
@@ -746,7 +790,7 @@ let globalFloatingCounter = 0;
746
790
  // clear the defer id
747
791
  this.pendingSort = null;
748
792
  // make sure we redraw everything
749
- game.repaint();
793
+ this.isDirty = true;
750
794
  }, this);
751
795
  }
752
796
  }
@@ -786,7 +830,7 @@ let globalFloatingCounter = 0;
786
830
  if (!b.pos || !a.pos) {
787
831
  return (a.pos ? -Infinity : Infinity);
788
832
  }
789
- var result = b.pos.z - a.pos.z;
833
+ let result = b.pos.z - a.pos.z;
790
834
  return (result ? result : (b.pos.x - a.pos.x));
791
835
  }
792
836
 
@@ -798,7 +842,7 @@ let globalFloatingCounter = 0;
798
842
  if (!b.pos || !a.pos) {
799
843
  return (a.pos ? -Infinity : Infinity);
800
844
  }
801
- var result = b.pos.z - a.pos.z;
845
+ let result = b.pos.z - a.pos.z;
802
846
  return (result ? result : (b.pos.y - a.pos.y));
803
847
  }
804
848
 
@@ -815,17 +859,17 @@ let globalFloatingCounter = 0;
815
859
 
816
860
  /**
817
861
  * container update function. <br>
818
- * automatically called by the game manager {@link game}
862
+ * automatically called by the application update loop {@link Application}
819
863
  * @protected
820
864
  * @param {number} dt - time since the last update in milliseconds.
821
865
  * @returns {boolean} true if the Container is dirty
822
866
  */
823
867
  update(dt) {
824
- var isFloating = false;
825
- var isPaused = state.isPaused();
826
- var children = this.getChildren();
868
+ let isFloating = false;
869
+ let isPaused = state.isPaused();
870
+ let children = this.getChildren();
827
871
 
828
- for (var i = children.length, obj; i--, (obj = children[i]);) {
872
+ for (let i = children.length, obj; i--, (obj = children[i]);) {
829
873
  if (isPaused && (!obj.updateWhenPaused)) {
830
874
  // skip this object
831
875
  continue;
@@ -870,8 +914,8 @@ let globalFloatingCounter = 0;
870
914
  * @param {Camera2d} [viewport] - the viewport to (re)draw
871
915
  */
872
916
  draw(renderer, viewport) {
873
- var isFloating = false;
874
- var bounds = this.getBounds();
917
+ let isFloating = false;
918
+ let bounds = this.getBounds();
875
919
 
876
920
  this.drawCount = 0;
877
921
 
@@ -893,8 +937,8 @@ let globalFloatingCounter = 0;
893
937
  renderer.clearColor(this.backgroundColor);
894
938
  }
895
939
 
896
- var children = this.getChildren();
897
- for (var i = children.length, obj; i--, (obj = children[i]);) {
940
+ let children = this.getChildren();
941
+ for (let i = children.length, obj; i--, (obj = children[i]);) {
898
942
  if (obj.isRenderable) {
899
943
 
900
944
  isFloating = obj.floating === true;
@@ -36,10 +36,10 @@ export class Draggable extends Renderable {
36
36
  * @private
37
37
  */
38
38
  initEvents() {
39
- input.registerPointerEvent("pointerdown", this, (e) => { event.emit(event.DRAGSTART, e, this); });
40
- input.registerPointerEvent("pointerup", this, (e) => { event.emit(event.DRAGEND, e, this); });
41
- input.registerPointerEvent("pointercancel", this, (e) => { event.emit(event.DRAGEND, e, this); });
42
- event.on(event.POINTERMOVE, this.dragMove.bind(this));
39
+ input.registerPointerEvent("pointerdown", this, (e) => event.emit(event.DRAGSTART, e, this));
40
+ input.registerPointerEvent("pointerup", this, (e) => event.emit(event.DRAGEND, e, this));
41
+ input.registerPointerEvent("pointercancel", this, (e) => event.emit(event.DRAGEND, e, this));
42
+ event.on(event.POINTERMOVE, (e) => this.dragMove(e));
43
43
  event.on(event.DRAGSTART, (e, draggable) => {
44
44
  if (draggable === this) {
45
45
  this.dragStart(e);
@@ -183,7 +183,7 @@ import * as stringUtil from "./../utils/string.js";
183
183
  * @ignore
184
184
  */
185
185
  updateLayer(vpos) {
186
- var rx = this.ratio.x,
186
+ const rx = this.ratio.x,
187
187
  ry = this.ratio.y;
188
188
 
189
189
  if (rx === 0 && ry === 0) {
@@ -191,7 +191,7 @@ import * as stringUtil from "./../utils/string.js";
191
191
  return;
192
192
  }
193
193
 
194
- var width = this.width,
194
+ const width = this.width,
195
195
  height = this.height,
196
196
  bw = game.viewport.bounds.width,
197
197
  bh = game.viewport.bounds.height,
@@ -257,13 +257,14 @@ import * as stringUtil from "./../utils/string.js";
257
257
  * @param {Camera2d} [viewport] - the viewport to (re)draw
258
258
  */
259
259
  draw(renderer, viewport) {
260
- var width = this.width,
260
+ const width = this.width,
261
261
  height = this.height,
262
262
  bw = viewport.bounds.width,
263
263
  bh = viewport.bounds.height,
264
264
  ax = this.anchorPoint.x,
265
- ay = this.anchorPoint.y,
266
- x = this.pos.x,
265
+ ay = this.anchorPoint.y;
266
+
267
+ let x = this.pos.x,
267
268
  y = this.pos.y;
268
269
 
269
270
  if (this.ratio.x === 0 && this.ratio.y === 0) {
@@ -3,16 +3,16 @@ import Renderable from "./renderable.js";
3
3
 
4
4
  /** @ignore */
5
5
  function createGradient(light) {
6
- var context = light.texture.context;
6
+ let context = light.texture.context;
7
7
 
8
- var x1 = light.texture.width / 2,
8
+ let x1 = light.texture.width / 2,
9
9
  y1 = light.texture.height / 2;
10
10
 
11
- var radiusX = light.radiusX,
11
+ let radiusX = light.radiusX,
12
12
  radiusY = light.radiusY;
13
13
 
14
- var scaleX, scaleY, invScaleX, invScaleY;
15
- var gradient;
14
+ let scaleX, scaleY, invScaleX, invScaleY;
15
+ let gradient;
16
16
 
17
17
 
18
18
  light.texture.clear();
@@ -86,18 +86,18 @@ import Sprite from "./sprite.js";
86
86
  */
87
87
  draw(renderer) {
88
88
  // the frame to draw
89
- var frame = this.current;
89
+ let frame = this.current;
90
90
 
91
91
  // cache the current position and size
92
- var dx = this.pos.x,
92
+ let dx = this.pos.x,
93
93
  dy = this.pos.y;
94
94
 
95
- var w = frame.width,
95
+ let w = frame.width,
96
96
  h = frame.height;
97
97
 
98
98
  // frame offset in the texture/atlas
99
- var frame_offset = frame.offset;
100
- var g_offset = this.offset;
99
+ let frame_offset = frame.offset;
100
+ let g_offset = this.offset;
101
101
 
102
102
 
103
103
  // remove image's TexturePacker/ShoeBox rotation
@@ -109,11 +109,11 @@ import Sprite from "./sprite.js";
109
109
  h = frame.width;
110
110
  }
111
111
 
112
- var sx = g_offset.x + frame_offset.x,
112
+ let sx = g_offset.x + frame_offset.x,
113
113
  sy = g_offset.y + frame_offset.y;
114
114
 
115
115
  // should this be configurable ?
116
- var corner_width = this.insetx || w / 4,
116
+ let corner_width = this.insetx || w / 4,
117
117
  corner_height = this.insety || h / 4;
118
118
 
119
119
  // OPTIMIZE ME !
@@ -163,11 +163,11 @@ import Sprite from "./sprite.js";
163
163
 
164
164
 
165
165
  // DRAW SIDES and CENTER
166
- var image_center_width = w - (corner_width << 1);
167
- var image_center_height = h - (corner_height << 1);
166
+ let image_center_width = w - (corner_width << 1);
167
+ let image_center_height = h - (corner_height << 1);
168
168
 
169
- var target_center_width = this.nss_width - (corner_width << 1);
170
- var target_center_height = this.nss_height - (corner_height << 1);
169
+ let target_center_width = this.nss_width - (corner_width << 1);
170
+ let target_center_height = this.nss_height - (corner_height << 1);
171
171
 
172
172
  //Top center
173
173
  renderer.drawImage(
@@ -426,11 +426,11 @@ import Color from "./../math/color.js";
426
426
  * @returns {number} angle in radians
427
427
  */
428
428
  angleTo(target) {
429
- var a = this.getBounds();
430
- var ax, ay;
429
+ let a = this.getBounds();
430
+ let ax, ay;
431
431
 
432
432
  if (target instanceof Renderable) {
433
- var b = target.getBounds();
433
+ let b = target.getBounds();
434
434
  ax = b.centerX - a.centerX;
435
435
  ay = b.centerY - a.centerY;
436
436
  } else { // vector object
@@ -447,11 +447,11 @@ import Color from "./../math/color.js";
447
447
  * @returns {number} distance
448
448
  */
449
449
  distanceTo(target) {
450
- var a = this.getBounds();
451
- var dx, dy;
450
+ let a = this.getBounds();
451
+ let dx, dy;
452
452
 
453
453
  if (target instanceof Renderable) {
454
- var b = target.getBounds();
454
+ let b = target.getBounds();
455
455
  dx = a.centerX - b.centerX;
456
456
  dy = a.centerY - b.centerY;
457
457
  } else { // vector object
@@ -468,7 +468,7 @@ import Color from "./../math/color.js";
468
468
  * @returns {Renderable} Reference to this object for method chaining
469
469
  */
470
470
  lookAt(target) {
471
- var position;
471
+ let position;
472
472
 
473
473
  if (target instanceof Renderable) {
474
474
  position = target.pos;
@@ -476,7 +476,7 @@ import Color from "./../math/color.js";
476
476
  position = target;
477
477
  }
478
478
 
479
- var angle = this.angleTo(position);
479
+ let angle = this.angleTo(position);
480
480
 
481
481
  this.rotate(angle);
482
482
 
@@ -541,7 +541,7 @@ import Color from "./../math/color.js";
541
541
  */
542
542
  updateBounds(absolute = true) {
543
543
  if (this.isRenderable) {
544
- var bounds = this.getBounds();
544
+ let bounds = this.getBounds();
545
545
 
546
546
  bounds.clear();
547
547
 
@@ -639,7 +639,7 @@ import Color from "./../math/color.js";
639
639
  * @param {CanvasRenderer|WebGLRenderer} renderer - a renderer object
640
640
  */
641
641
  preDraw(renderer) {
642
- var ax = this.width * this.anchorPoint.x,
642
+ let ax = this.width * this.anchorPoint.x,
643
643
  ay = this.height * this.anchorPoint.y;
644
644
 
645
645
  // save renderer context