melonjs 15.0.0 → 15.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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 +77 -59
  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 +1747 -1809
  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 +76 -58
  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
@@ -229,7 +229,7 @@ let globalFloatingCounter = 0;
229
229
 
230
230
  // if a physic body is defined, add it to the game world
231
231
  if (child.body instanceof Body) {
232
- game.world.addBody(child.body);
232
+ this.getRootAncestor().addBody(child.body);
233
233
  }
234
234
 
235
235
  // triggered callback if defined
@@ -268,7 +268,7 @@ let globalFloatingCounter = 0;
268
268
 
269
269
  // force repaint in case this is a static non-animated object
270
270
  if (this.isAttachedToRoot() === true) {
271
- game.repaint();
271
+ this.isDirty = true;
272
272
  }
273
273
 
274
274
  // force bounds update if required
@@ -278,7 +278,7 @@ let globalFloatingCounter = 0;
278
278
 
279
279
  // if a physic body is defined, add it to the game world
280
280
  if (child.body instanceof Body) {
281
- game.world.addBody(child.body);
281
+ this.getRootAncestor().addBody(child.body);
282
282
  }
283
283
 
284
284
  // triggered callback if defined
@@ -300,20 +300,20 @@ let globalFloatingCounter = 0;
300
300
  * @param {Function} callback - fnction to execute on each element
301
301
  * @param {object} [thisArg] - value to use as this(i.e reference Object) when executing callback.
302
302
  * @example
303
- * // iterate through all children of the root container
304
- * me.game.world.forEach((child) => {
303
+ * // iterate through all children of this container
304
+ * container.forEach((child) => {
305
305
  * // do something with the child
306
306
  * child.doSomething();
307
307
  * });
308
- * me.game.world.forEach((child, index) => { ... });
309
- * me.game.world.forEach((child, index, array) => { ... });
310
- * me.game.world.forEach((child, index, array) => { ... }, thisArg);
308
+ * container.forEach((child, index) => { ... });
309
+ * container.forEach((child, index, array) => { ... });
310
+ * container.forEach((child, index, array) => { ... }, thisArg);
311
311
  */
312
312
  forEach(callback, thisArg) {
313
- var context = this, i = 0;
314
- var children = this.getChildren();
313
+ let context = this, i = 0;
314
+ let children = this.getChildren();
315
315
 
316
- var len = children.length;
316
+ let len = children.length;
317
317
 
318
318
  if (typeof callback !== "function") {
319
319
  throw new Error(callback + " is not a function");
@@ -335,12 +335,12 @@ let globalFloatingCounter = 0;
335
335
  * @param {Renderable} child2
336
336
  */
337
337
  swapChildren(child, child2) {
338
- var index = this.getChildIndex(child);
339
- var index2 = this.getChildIndex(child2);
338
+ let index = this.getChildIndex(child);
339
+ let index2 = this.getChildIndex(child2);
340
340
 
341
341
  if ((index !== -1) && (index2 !== -1)) {
342
342
  // swap z index
343
- var _z = child.pos.z;
343
+ let _z = child.pos.z;
344
344
  child.pos.z = child2.pos.z;
345
345
  child2.pos.z = _z;
346
346
  // swap the positions..
@@ -383,7 +383,7 @@ let globalFloatingCounter = 0;
383
383
  * @returns {Renderable} child
384
384
  */
385
385
  getNextChild(child) {
386
- var index = this.getChildren().indexOf(child) - 1;
386
+ let index = this.getChildren().indexOf(child) - 1;
387
387
  if (index >= 0 && index < this.getChildren().length) {
388
388
  return this.getChildAt(index);
389
389
  }
@@ -408,27 +408,27 @@ let globalFloatingCounter = 0;
408
408
  * @returns {Renderable[]} Array of childs
409
409
  * @example
410
410
  * // get the first child object called "mainPlayer" in a specific container :
411
- * var ent = myContainer.getChildByProp("name", "mainPlayer");
411
+ * let ent = myContainer.getChildByProp("name", "mainPlayer");
412
412
  *
413
413
  * // or query the whole world :
414
- * var ent = me.game.world.getChildByProp("name", "mainPlayer");
414
+ * let ent = container.getChildByProp("name", "mainPlayer");
415
415
  *
416
416
  * // partial property matches are also allowed by using a RegExp.
417
417
  * // the following matches "redCOIN", "bluecoin", "bagOfCoins", etc :
418
- * var allCoins = me.game.world.getChildByProp("name", /coin/i);
418
+ * let allCoins = container.getChildByProp("name", /coin/i);
419
419
  *
420
420
  * // 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);
421
+ * let zIndex10 = container.getChildByProp("z", 10);
422
+ * let inViewport = container.getChildByProp("inViewport", true);
423
423
  */
424
424
  getChildByProp(prop, value) {
425
- var objList = [];
425
+ let objList = [];
426
426
 
427
427
  /**
428
428
  * @ignore
429
429
  */
430
430
  function compare(obj, prop) {
431
- var v = obj[prop];
431
+ let v = obj[prop];
432
432
  if (value instanceof RegExp && typeof(v) === "string") {
433
433
  if (value.test(v)) {
434
434
  objList.push(obj);
@@ -455,7 +455,7 @@ let globalFloatingCounter = 0;
455
455
  * @returns {Renderable[]} Array of children
456
456
  */
457
457
  getChildByType(classType) {
458
- var objList = [];
458
+ let objList = [];
459
459
 
460
460
  this.forEach((child) => {
461
461
  if (child instanceof classType) {
@@ -489,7 +489,7 @@ let globalFloatingCounter = 0;
489
489
  * @returns {Renderable} corresponding child or null
490
490
  */
491
491
  getChildByGUID(guid) {
492
- var obj = this.getChildByProp("GUID", guid);
492
+ let obj = this.getChildByProp("GUID", guid);
493
493
  return (obj.length > 0) ? obj[0] : null;
494
494
  }
495
495
 
@@ -511,7 +511,7 @@ let globalFloatingCounter = 0;
511
511
  * @returns {Bounds} this shape bounding box Rectangle object
512
512
  */
513
513
  updateBounds(absolute = true) {
514
- var bounds = this.getBounds();
514
+ let bounds = this.getBounds();
515
515
 
516
516
  // call parent method
517
517
  super.updateBounds(absolute);
@@ -519,7 +519,7 @@ let globalFloatingCounter = 0;
519
519
  if (this.enableChildBoundsUpdate === true) {
520
520
  this.forEach((child) => {
521
521
  if (child.isRenderable) {
522
- var childBounds = child.getBounds();
522
+ let childBounds = child.getBounds();
523
523
  if (childBounds.isFinite()) {
524
524
  bounds.addBounds(childBounds);
525
525
  }
@@ -531,14 +531,13 @@ let globalFloatingCounter = 0;
531
531
 
532
532
  /**
533
533
  * Checks if this container is root or if it's attached to the root container.
534
- * @private
535
534
  * @returns {boolean}
536
535
  */
537
536
  isAttachedToRoot() {
538
537
  if (this.root === true) {
539
538
  return true;
540
539
  } else {
541
- var ancestor = this.ancestor;
540
+ let ancestor = this.ancestor;
542
541
  while (ancestor) {
543
542
  if (ancestor.root === true) {
544
543
  return true;
@@ -549,6 +548,25 @@ let globalFloatingCounter = 0;
549
548
  }
550
549
  }
551
550
 
551
+ /**
552
+ * Returns the instance of the root container (i.e. the current application World container).
553
+ * @returns {Container}
554
+ */
555
+ getRootAncestor() {
556
+ if (this.root === true) {
557
+ return this;
558
+ } else {
559
+ let ancestor = this.ancestor;
560
+ while (ancestor) {
561
+ if (ancestor.root === true) {
562
+ break;
563
+ }
564
+ ancestor = ancestor.ancestor;
565
+ }
566
+ return ancestor;
567
+ }
568
+ }
569
+
552
570
  /**
553
571
  * update the cointainer's bounding rect (private)
554
572
  * @ignore
@@ -610,7 +628,7 @@ let globalFloatingCounter = 0;
610
628
  // remove the body first to avoid a condition where a body can be detached
611
629
  // from its parent, before the body is removed from the game world
612
630
  if (child.body instanceof Body) {
613
- game.world.removeBody(child.body);
631
+ this.getRootAncestor().removeBody(child.body);
614
632
  }
615
633
 
616
634
  if (!keepalive) {
@@ -625,7 +643,7 @@ let globalFloatingCounter = 0;
625
643
 
626
644
  // Don't cache the child index; another element might have been removed
627
645
  // by the child's `onDeactivateEvent` or `destroy` methods
628
- var childIndex = this.getChildIndex(child);
646
+ let childIndex = this.getChildIndex(child);
629
647
  if (childIndex >= 0) {
630
648
  this.getChildren().splice(childIndex, 1);
631
649
  child.ancestor = undefined;
@@ -633,7 +651,7 @@ let globalFloatingCounter = 0;
633
651
 
634
652
  // force repaint in case this is a static non-animated object
635
653
  if (this.isAttachedToRoot() === true) {
636
- game.repaint();
654
+ this.isDirty = true;
637
655
  }
638
656
 
639
657
  // force bounds update if required
@@ -666,7 +684,7 @@ let globalFloatingCounter = 0;
666
684
  * @param {Renderable} child
667
685
  */
668
686
  moveUp(child) {
669
- var childIndex = this.getChildIndex(child);
687
+ let childIndex = this.getChildIndex(child);
670
688
  if (childIndex - 1 >= 0) {
671
689
  // note : we use an inverted loop
672
690
  this.swapChildren(child, this.getChildAt(childIndex - 1));
@@ -680,7 +698,7 @@ let globalFloatingCounter = 0;
680
698
  * @param {Renderable} child
681
699
  */
682
700
  moveDown(child) {
683
- var childIndex = this.getChildIndex(child);
701
+ let childIndex = this.getChildIndex(child);
684
702
  if (childIndex >= 0 && (childIndex + 1) < this.getChildren().length) {
685
703
  // note : we use an inverted loop
686
704
  this.swapChildren(child, this.getChildAt(childIndex + 1));
@@ -694,9 +712,9 @@ let globalFloatingCounter = 0;
694
712
  * @param {Renderable} child
695
713
  */
696
714
  moveToTop(child) {
697
- var childIndex = this.getChildIndex(child);
715
+ let childIndex = this.getChildIndex(child);
698
716
  if (childIndex > 0) {
699
- var children = this.getChildren();
717
+ let children = this.getChildren();
700
718
  // note : we use an inverted loop
701
719
  children.splice(0, 0, children.splice(childIndex, 1)[0]);
702
720
  // increment our child z value based on the previous child depth
@@ -711,8 +729,8 @@ let globalFloatingCounter = 0;
711
729
  * @param {Renderable} child
712
730
  */
713
731
  moveToBottom(child) {
714
- var childIndex = this.getChildIndex(child);
715
- var children = this.getChildren();
732
+ let childIndex = this.getChildIndex(child);
733
+ let children = this.getChildren();
716
734
  if (childIndex >= 0 && childIndex < (children.length - 1)) {
717
735
  // note : we use an inverted loop
718
736
  children.splice((children.length - 1), 0, children.splice(childIndex, 1)[0]);
@@ -746,7 +764,7 @@ let globalFloatingCounter = 0;
746
764
  // clear the defer id
747
765
  this.pendingSort = null;
748
766
  // make sure we redraw everything
749
- game.repaint();
767
+ this.isDirty = true;
750
768
  }, this);
751
769
  }
752
770
  }
@@ -786,7 +804,7 @@ let globalFloatingCounter = 0;
786
804
  if (!b.pos || !a.pos) {
787
805
  return (a.pos ? -Infinity : Infinity);
788
806
  }
789
- var result = b.pos.z - a.pos.z;
807
+ let result = b.pos.z - a.pos.z;
790
808
  return (result ? result : (b.pos.x - a.pos.x));
791
809
  }
792
810
 
@@ -798,7 +816,7 @@ let globalFloatingCounter = 0;
798
816
  if (!b.pos || !a.pos) {
799
817
  return (a.pos ? -Infinity : Infinity);
800
818
  }
801
- var result = b.pos.z - a.pos.z;
819
+ let result = b.pos.z - a.pos.z;
802
820
  return (result ? result : (b.pos.y - a.pos.y));
803
821
  }
804
822
 
@@ -815,17 +833,17 @@ let globalFloatingCounter = 0;
815
833
 
816
834
  /**
817
835
  * container update function. <br>
818
- * automatically called by the game manager {@link game}
836
+ * automatically called by the application update loop {@link Application}
819
837
  * @protected
820
838
  * @param {number} dt - time since the last update in milliseconds.
821
839
  * @returns {boolean} true if the Container is dirty
822
840
  */
823
841
  update(dt) {
824
- var isFloating = false;
825
- var isPaused = state.isPaused();
826
- var children = this.getChildren();
842
+ let isFloating = false;
843
+ let isPaused = state.isPaused();
844
+ let children = this.getChildren();
827
845
 
828
- for (var i = children.length, obj; i--, (obj = children[i]);) {
846
+ for (let i = children.length, obj; i--, (obj = children[i]);) {
829
847
  if (isPaused && (!obj.updateWhenPaused)) {
830
848
  // skip this object
831
849
  continue;
@@ -870,8 +888,8 @@ let globalFloatingCounter = 0;
870
888
  * @param {Camera2d} [viewport] - the viewport to (re)draw
871
889
  */
872
890
  draw(renderer, viewport) {
873
- var isFloating = false;
874
- var bounds = this.getBounds();
891
+ let isFloating = false;
892
+ let bounds = this.getBounds();
875
893
 
876
894
  this.drawCount = 0;
877
895
 
@@ -893,8 +911,8 @@ let globalFloatingCounter = 0;
893
911
  renderer.clearColor(this.backgroundColor);
894
912
  }
895
913
 
896
- var children = this.getChildren();
897
- for (var i = children.length, obj; i--, (obj = children[i]);) {
914
+ let children = this.getChildren();
915
+ for (let i = children.length, obj; i--, (obj = children[i]);) {
898
916
  if (obj.isRenderable) {
899
917
 
900
918
  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