melonjs 14.5.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 (315) hide show
  1. package/LICENSE.md +1 -1
  2. package/README.md +6 -6
  3. package/dist/melonjs.mjs/_virtual/_commonjsHelpers.js +1 -1
  4. package/dist/melonjs.mjs/_virtual/arraymultimap.js +1 -1
  5. package/dist/melonjs.mjs/_virtual/earcut.js +1 -1
  6. package/dist/melonjs.mjs/_virtual/howler.js +1 -1
  7. package/dist/melonjs.mjs/_virtual/index.js +7 -3
  8. package/dist/melonjs.mjs/_virtual/index2.js +1 -1
  9. package/dist/melonjs.mjs/_virtual/multimap.js +1 -1
  10. package/dist/melonjs.mjs/_virtual/setmultimap.js +1 -1
  11. package/dist/melonjs.mjs/application/application.js +27 -17
  12. package/dist/melonjs.mjs/application/header.js +6 -5
  13. package/dist/melonjs.mjs/application/resize.js +20 -20
  14. package/dist/melonjs.mjs/application/settings.js +1 -1
  15. package/dist/melonjs.mjs/audio/audio.js +18 -20
  16. package/dist/melonjs.mjs/camera/camera2d.js +10 -10
  17. package/dist/melonjs.mjs/const.js +1 -1
  18. package/dist/melonjs.mjs/entity/entity.js +4 -4
  19. package/dist/melonjs.mjs/geometries/ellipse.js +6 -6
  20. package/dist/melonjs.mjs/geometries/line.js +9 -9
  21. package/dist/melonjs.mjs/geometries/path2d.js +56 -56
  22. package/dist/melonjs.mjs/geometries/point.js +2 -2
  23. package/dist/melonjs.mjs/geometries/poly.js +29 -29
  24. package/dist/melonjs.mjs/geometries/rectangle.js +8 -8
  25. package/dist/melonjs.mjs/geometries/roundrect.js +6 -6
  26. package/dist/melonjs.mjs/index.js +8 -6
  27. package/dist/melonjs.mjs/input/gamepad.js +30 -30
  28. package/dist/melonjs.mjs/input/input.js +2 -2
  29. package/dist/melonjs.mjs/input/keyboard.js +15 -15
  30. package/dist/melonjs.mjs/input/pointer.js +2 -2
  31. package/dist/melonjs.mjs/input/pointerevent.js +59 -59
  32. package/dist/melonjs.mjs/lang/console.js +3 -3
  33. package/dist/melonjs.mjs/lang/deprecated.js +2 -2
  34. package/dist/melonjs.mjs/level/level.js +9 -9
  35. package/dist/melonjs.mjs/level/tiled/TMXGroup.js +3 -3
  36. package/dist/melonjs.mjs/level/tiled/TMXLayer.js +31 -31
  37. package/dist/melonjs.mjs/level/tiled/TMXObject.js +8 -8
  38. package/dist/melonjs.mjs/level/tiled/TMXTile.js +8 -8
  39. package/dist/melonjs.mjs/level/tiled/TMXTileMap.js +19 -19
  40. package/dist/melonjs.mjs/level/tiled/TMXTileset.js +15 -15
  41. package/dist/melonjs.mjs/level/tiled/TMXTilesetGroup.js +3 -3
  42. package/dist/melonjs.mjs/level/tiled/TMXUtils.js +46 -41
  43. package/dist/melonjs.mjs/level/tiled/constants.js +1 -1
  44. package/dist/melonjs.mjs/level/tiled/renderer/TMXHexagonalRenderer.js +30 -30
  45. package/dist/melonjs.mjs/level/tiled/renderer/TMXIsometricRenderer.js +21 -21
  46. package/dist/melonjs.mjs/level/tiled/renderer/TMXOrthogonalRenderer.js +10 -10
  47. package/dist/melonjs.mjs/level/tiled/renderer/TMXRenderer.js +2 -2
  48. package/dist/melonjs.mjs/level/tiled/renderer/TMXStaggeredRenderer.js +6 -6
  49. package/dist/melonjs.mjs/level/tiled/renderer/autodetect.js +1 -1
  50. package/dist/melonjs.mjs/loader/cache.js +1 -1
  51. package/dist/melonjs.mjs/loader/loader.js +7 -7
  52. package/dist/melonjs.mjs/loader/loadingscreen.js +2 -2
  53. package/dist/melonjs.mjs/loader/melonjs_logo.png.js +1 -1
  54. package/dist/melonjs.mjs/loader/parser.js +13 -13
  55. package/dist/melonjs.mjs/loader/settings.js +3 -3
  56. package/dist/melonjs.mjs/math/color.js +25 -24
  57. package/dist/melonjs.mjs/math/math.js +2 -2
  58. package/dist/melonjs.mjs/math/matrix2.js +22 -22
  59. package/dist/melonjs.mjs/math/matrix3.js +52 -52
  60. package/dist/melonjs.mjs/math/observable_vector2.js +12 -12
  61. package/dist/melonjs.mjs/math/observable_vector3.js +22 -22
  62. package/dist/melonjs.mjs/math/vector2.js +11 -11
  63. package/dist/melonjs.mjs/math/vector3.js +21 -21
  64. package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/esm/arraymultimap.js +45 -0
  65. package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/esm/multimap.js +130 -0
  66. package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/arraymultimap.js +1 -1
  67. package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/index.js +1 -1
  68. package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/multimap.js +1 -1
  69. package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/setmultimap.js +1 -1
  70. package/dist/melonjs.mjs/node_modules/earcut/src/earcut.js +1 -1
  71. package/dist/melonjs.mjs/node_modules/eventemitter3/index.js +2 -2
  72. package/dist/melonjs.mjs/node_modules/eventemitter3/index2.js +1 -1
  73. package/dist/melonjs.mjs/node_modules/howler/dist/howler.js +1 -1
  74. package/dist/melonjs.mjs/particles/emitter.js +5 -5
  75. package/dist/melonjs.mjs/particles/particle.js +8 -8
  76. package/dist/melonjs.mjs/particles/settings.js +3 -3
  77. package/dist/melonjs.mjs/physics/body.js +17 -17
  78. package/dist/melonjs.mjs/physics/bounds.js +12 -12
  79. package/dist/melonjs.mjs/physics/collision.js +3 -3
  80. package/dist/melonjs.mjs/physics/detector.js +14 -14
  81. package/dist/melonjs.mjs/physics/quadtree.js +19 -19
  82. package/dist/melonjs.mjs/physics/response.js +1 -1
  83. package/dist/melonjs.mjs/physics/sat.js +60 -60
  84. package/dist/melonjs.mjs/physics/world.js +4 -4
  85. package/dist/melonjs.mjs/plugin/plugin.js +11 -11
  86. package/dist/melonjs.mjs/renderable/collectable.js +2 -2
  87. package/dist/melonjs.mjs/renderable/colorlayer.js +1 -1
  88. package/dist/melonjs.mjs/renderable/container.js +77 -59
  89. package/dist/melonjs.mjs/renderable/dragndrop.js +5 -5
  90. package/dist/melonjs.mjs/renderable/imagelayer.js +7 -6
  91. package/dist/melonjs.mjs/renderable/light2d.js +6 -6
  92. package/dist/melonjs.mjs/renderable/nineslicesprite.js +12 -12
  93. package/dist/melonjs.mjs/renderable/renderable.js +35 -13
  94. package/dist/melonjs.mjs/renderable/sprite.js +25 -25
  95. package/dist/melonjs.mjs/renderable/trigger.js +11 -9
  96. package/dist/melonjs.mjs/renderable/ui/uibaseelement.js +97 -27
  97. package/dist/melonjs.mjs/renderable/ui/uispriteelement.js +25 -25
  98. package/dist/melonjs.mjs/renderable/ui/uitextbutton.js +83 -65
  99. package/dist/melonjs.mjs/state/stage.js +7 -7
  100. package/dist/melonjs.mjs/state/state.js +15 -15
  101. package/dist/melonjs.mjs/system/device.js +3 -3
  102. package/dist/melonjs.mjs/system/dom.js +1 -1
  103. package/dist/melonjs.mjs/system/event.js +2 -2
  104. package/dist/melonjs.mjs/system/platform.js +1 -1
  105. package/dist/melonjs.mjs/system/pooling.js +9 -9
  106. package/dist/melonjs.mjs/system/save.js +6 -6
  107. package/dist/melonjs.mjs/system/timer.js +16 -12
  108. package/dist/melonjs.mjs/text/bitmaptext.js +20 -20
  109. package/dist/melonjs.mjs/text/bitmaptextdata.js +22 -22
  110. package/dist/melonjs.mjs/text/glyph.js +3 -3
  111. package/dist/melonjs.mjs/text/text.js +63 -92
  112. package/dist/melonjs.mjs/text/textmetrics.js +15 -15
  113. package/dist/melonjs.mjs/text/textstyle.js +4 -6
  114. package/dist/melonjs.mjs/tweens/easing.js +4 -4
  115. package/dist/melonjs.mjs/tweens/interpolation.js +8 -8
  116. package/dist/melonjs.mjs/tweens/tween.js +11 -11
  117. package/dist/melonjs.mjs/utils/agent.js +6 -6
  118. package/dist/melonjs.mjs/utils/array.js +4 -4
  119. package/dist/melonjs.mjs/utils/file.js +1 -1
  120. package/dist/melonjs.mjs/utils/function.js +5 -5
  121. package/dist/melonjs.mjs/utils/string.js +3 -3
  122. package/dist/melonjs.mjs/utils/utils.js +16 -16
  123. package/dist/melonjs.mjs/video/canvas/canvas_renderer.js +41 -119
  124. package/dist/melonjs.mjs/video/renderer.js +70 -14
  125. package/dist/melonjs.mjs/video/texture/atlas.js +39 -45
  126. package/dist/melonjs.mjs/video/texture/cache.js +9 -10
  127. package/dist/melonjs.mjs/video/texture/canvas_texture.js +63 -3
  128. package/dist/melonjs.mjs/video/utils/autodetect.js +1 -1
  129. package/dist/melonjs.mjs/video/video.js +2 -2
  130. package/dist/melonjs.mjs/video/webgl/buffer/vertex.js +23 -19
  131. package/dist/melonjs.mjs/video/webgl/compositors/compositor.js +80 -80
  132. package/dist/melonjs.mjs/video/webgl/compositors/primitive_compositor.js +77 -0
  133. package/dist/melonjs.mjs/video/webgl/compositors/quad_compositor.js +252 -0
  134. package/dist/melonjs.mjs/video/webgl/compositors/webgl_compositor.js +1 -1
  135. package/dist/melonjs.mjs/video/webgl/glshader.js +7 -7
  136. package/dist/melonjs.mjs/video/webgl/shaders/primitive.frag.js +1 -1
  137. package/dist/melonjs.mjs/video/webgl/shaders/primitive.vert.js +2 -2
  138. package/dist/melonjs.mjs/video/webgl/shaders/quad.frag.js +1 -1
  139. package/dist/melonjs.mjs/video/webgl/shaders/quad.vert.js +2 -2
  140. package/dist/melonjs.mjs/video/webgl/utils/attributes.js +2 -2
  141. package/dist/melonjs.mjs/video/webgl/utils/precision.js +1 -1
  142. package/dist/melonjs.mjs/video/webgl/utils/program.js +7 -7
  143. package/dist/melonjs.mjs/video/webgl/utils/string.js +1 -1
  144. package/dist/melonjs.mjs/video/webgl/utils/uniforms.js +4 -4
  145. package/dist/melonjs.mjs/video/webgl/webgl_renderer.js +188 -181
  146. package/dist/melonjs.module.js +25040 -25193
  147. package/dist/types/application/application.d.ts +11 -8
  148. package/dist/types/audio/audio.d.ts +3 -3
  149. package/dist/types/entity/entity.d.ts +1 -1
  150. package/dist/types/index.d.ts +7 -4
  151. package/dist/types/input/input.d.ts +1 -1
  152. package/dist/types/input/keyboard.d.ts +1 -1
  153. package/dist/types/input/pointerevent.d.ts +6 -6
  154. package/dist/types/level/level.d.ts +2 -2
  155. package/dist/types/level/tiled/TMXLayer.d.ts +4 -4
  156. package/dist/types/level/tiled/TMXTileMap.d.ts +2 -2
  157. package/dist/types/level/tiled/TMXUtils.d.ts +5 -4
  158. package/dist/types/loader/loader.d.ts +2 -2
  159. package/dist/types/loader/settings.d.ts +2 -2
  160. package/dist/types/particles/emitter.d.ts +1 -1
  161. package/dist/types/physics/collision.d.ts +1 -1
  162. package/dist/types/physics/detector.d.ts +1 -1
  163. package/dist/types/plugin/plugin.d.ts +2 -2
  164. package/dist/types/renderable/container.d.ts +21 -17
  165. package/dist/types/renderable/renderable.d.ts +6 -0
  166. package/dist/types/renderable/sprite.d.ts +11 -11
  167. package/dist/types/renderable/trigger.d.ts +1 -1
  168. package/dist/types/renderable/ui/uibaseelement.d.ts +28 -6
  169. package/dist/types/renderable/ui/uispriteelement.d.ts +12 -14
  170. package/dist/types/renderable/ui/uitextbutton.d.ts +52 -12
  171. package/dist/types/state/stage.d.ts +1 -1
  172. package/dist/types/system/device.d.ts +1 -1
  173. package/dist/types/system/pooling.d.ts +3 -3
  174. package/dist/types/system/timer.d.ts +5 -5
  175. package/dist/types/text/bitmaptext.d.ts +1 -1
  176. package/dist/types/text/text.d.ts +7 -21
  177. package/dist/types/text/textstyle.d.ts +1 -1
  178. package/dist/types/utils/array.d.ts +2 -2
  179. package/dist/types/video/canvas/canvas_renderer.d.ts +8 -81
  180. package/dist/types/video/renderer.d.ts +48 -4
  181. package/dist/types/video/texture/atlas.d.ts +3 -3
  182. package/dist/types/video/texture/canvas_texture.d.ts +40 -0
  183. package/dist/types/video/webgl/buffer/vertex.d.ts +3 -3
  184. package/dist/types/video/webgl/compositors/compositor.d.ts +38 -32
  185. package/dist/types/video/webgl/compositors/primitive_compositor.d.ts +22 -0
  186. package/dist/types/video/webgl/compositors/quad_compositor.d.ts +72 -0
  187. package/dist/types/video/webgl/glshader.d.ts +1 -1
  188. package/dist/types/video/webgl/webgl_renderer.d.ts +47 -37
  189. package/package.json +16 -17
  190. package/src/application/application.js +26 -16
  191. package/src/application/header.js +5 -4
  192. package/src/application/resize.js +19 -19
  193. package/src/audio/audio.js +17 -19
  194. package/src/camera/camera2d.js +9 -9
  195. package/src/entity/entity.js +3 -3
  196. package/src/geometries/ellipse.js +5 -5
  197. package/src/geometries/line.js +8 -8
  198. package/src/geometries/path2d.js +55 -55
  199. package/src/geometries/point.js +1 -1
  200. package/src/geometries/poly.js +28 -28
  201. package/src/geometries/rectangle.js +7 -7
  202. package/src/geometries/roundrect.js +5 -5
  203. package/src/index.js +9 -4
  204. package/src/input/gamepad.js +29 -29
  205. package/src/input/input.js +1 -1
  206. package/src/input/keyboard.js +14 -14
  207. package/src/input/pointer.js +1 -1
  208. package/src/input/pointerevent.js +52 -52
  209. package/src/lang/console.js +2 -2
  210. package/src/lang/deprecated.js +1 -1
  211. package/src/level/level.js +8 -8
  212. package/src/level/tiled/TMXGroup.js +2 -2
  213. package/src/level/tiled/TMXLayer.js +30 -30
  214. package/src/level/tiled/TMXObject.js +7 -7
  215. package/src/level/tiled/TMXTile.js +7 -7
  216. package/src/level/tiled/TMXTileMap.js +18 -18
  217. package/src/level/tiled/TMXTileset.js +14 -14
  218. package/src/level/tiled/TMXTilesetGroup.js +2 -2
  219. package/src/level/tiled/TMXUtils.js +45 -40
  220. package/src/level/tiled/renderer/TMXHexagonalRenderer.js +29 -29
  221. package/src/level/tiled/renderer/TMXIsometricRenderer.js +20 -20
  222. package/src/level/tiled/renderer/TMXOrthogonalRenderer.js +9 -9
  223. package/src/level/tiled/renderer/TMXRenderer.js +1 -1
  224. package/src/level/tiled/renderer/TMXStaggeredRenderer.js +5 -5
  225. package/src/loader/loader.js +6 -6
  226. package/src/loader/loadingscreen.js +1 -1
  227. package/src/loader/parser.js +12 -12
  228. package/src/loader/settings.js +2 -2
  229. package/src/math/color.js +24 -23
  230. package/src/math/math.js +1 -1
  231. package/src/math/matrix2.js +21 -21
  232. package/src/math/matrix3.js +51 -51
  233. package/src/math/observable_vector2.js +11 -11
  234. package/src/math/observable_vector3.js +21 -21
  235. package/src/math/vector2.js +10 -10
  236. package/src/math/vector3.js +20 -20
  237. package/src/particles/emitter.js +4 -4
  238. package/src/particles/particle.js +7 -7
  239. package/src/particles/settings.js +2 -2
  240. package/src/physics/body.js +16 -16
  241. package/src/physics/bounds.js +11 -11
  242. package/src/physics/collision.js +2 -2
  243. package/src/physics/detector.js +13 -13
  244. package/src/physics/quadtree.js +18 -18
  245. package/src/physics/sat.js +59 -59
  246. package/src/physics/world.js +3 -3
  247. package/src/plugin/plugin.js +8 -8
  248. package/src/polyfill/index.js +0 -2
  249. package/src/renderable/collectable.js +1 -1
  250. package/src/renderable/container.js +76 -58
  251. package/src/renderable/dragndrop.js +4 -4
  252. package/src/renderable/imagelayer.js +6 -5
  253. package/src/renderable/light2d.js +5 -5
  254. package/src/renderable/nineslicesprite.js +11 -11
  255. package/src/renderable/renderable.js +34 -12
  256. package/src/renderable/sprite.js +24 -24
  257. package/src/renderable/trigger.js +10 -8
  258. package/src/renderable/ui/uibaseelement.js +96 -26
  259. package/src/renderable/ui/uispriteelement.js +24 -24
  260. package/src/renderable/ui/uitextbutton.js +85 -67
  261. package/src/state/stage.js +6 -6
  262. package/src/state/state.js +14 -14
  263. package/src/system/device.js +2 -2
  264. package/src/system/event.js +1 -1
  265. package/src/system/pooling.js +8 -8
  266. package/src/system/save.js +5 -5
  267. package/src/system/timer.js +15 -11
  268. package/src/text/bitmaptext.js +19 -19
  269. package/src/text/bitmaptextdata.js +21 -21
  270. package/src/text/glyph.js +2 -2
  271. package/src/text/text.js +62 -91
  272. package/src/text/textmetrics.js +14 -14
  273. package/src/text/textstyle.js +3 -5
  274. package/src/tweens/easing.js +3 -3
  275. package/src/tweens/interpolation.js +7 -7
  276. package/src/tweens/tween.js +10 -10
  277. package/src/utils/agent.js +5 -5
  278. package/src/utils/array.js +3 -3
  279. package/src/utils/function.js +4 -4
  280. package/src/utils/string.js +2 -2
  281. package/src/utils/utils.js +15 -15
  282. package/src/video/canvas/canvas_renderer.js +39 -117
  283. package/src/video/renderer.js +68 -12
  284. package/src/video/texture/atlas.js +38 -44
  285. package/src/video/texture/cache.js +6 -6
  286. package/src/video/texture/canvas_texture.js +62 -2
  287. package/src/video/video.js +1 -1
  288. package/src/video/webgl/buffer/vertex.js +22 -18
  289. package/src/video/webgl/compositors/compositor.js +79 -80
  290. package/src/video/webgl/compositors/primitive_compositor.js +68 -0
  291. package/src/video/webgl/compositors/{webgl_compositor.js → quad_compositor.js} +52 -109
  292. package/src/video/webgl/glshader.js +6 -6
  293. package/src/video/webgl/shaders/primitive.vert +2 -5
  294. package/src/video/webgl/shaders/quad.vert +3 -1
  295. package/src/video/webgl/utils/attributes.js +1 -1
  296. package/src/video/webgl/utils/program.js +6 -6
  297. package/src/video/webgl/utils/uniforms.js +3 -3
  298. package/src/video/webgl/webgl_renderer.js +186 -179
  299. package/dist/melonjs.mjs/_virtual/make-built-in.js +0 -10
  300. package/dist/melonjs.mjs/_virtual/object-define-property.js +0 -10
  301. package/dist/melonjs.mjs/_virtual/object-get-own-property-descriptor.js +0 -10
  302. package/dist/melonjs.mjs/_virtual/object-get-own-property-names.js +0 -10
  303. package/dist/melonjs.mjs/_virtual/object-get-own-property-symbols.js +0 -10
  304. package/dist/melonjs.mjs/_virtual/object-property-is-enumerable.js +0 -10
  305. package/dist/melonjs.mjs/_virtual/shared.js +0 -10
  306. package/dist/melonjs.mjs/game.js +0 -29
  307. package/dist/melonjs.mjs/polyfill/console.js +0 -18
  308. package/dist/melonjs.mjs/polyfill/performance.js +0 -27
  309. package/dist/melonjs.mjs/polyfill/requestAnimationFrame.js +0 -46
  310. package/dist/melonjs.mjs/polyfill/roundrect.js +0 -242
  311. package/dist/melonjs.mjs/renderable/re_container.js +0 -1016
  312. package/dist/melonjs.mjs/video/utils/resize.js +0 -116
  313. package/dist/melonjs.mjs/video/webgl/webgl_compositor.js +0 -494
  314. package/src/polyfill/performance.js +0 -20
  315. package/src/polyfill/requestAnimationFrame.js +0 -39
@@ -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(
@@ -206,6 +206,13 @@ import Color from "./../math/color.js";
206
206
  */
207
207
  this.mask = undefined;
208
208
 
209
+ /**
210
+ * (Experimental) an optional shader, to be used instead of the default built-in one, when drawing this renderable (WebGL only)
211
+ * @type {GLShader}
212
+ * @default undefined
213
+ */
214
+ this.shader = undefined;
215
+
209
216
  /**
210
217
  * the blend mode to be applied to this renderable (see renderer setBlendMode for available blend mode)
211
218
  * @type {string}
@@ -419,11 +426,11 @@ import Color from "./../math/color.js";
419
426
  * @returns {number} angle in radians
420
427
  */
421
428
  angleTo(target) {
422
- var a = this.getBounds();
423
- var ax, ay;
429
+ let a = this.getBounds();
430
+ let ax, ay;
424
431
 
425
432
  if (target instanceof Renderable) {
426
- var b = target.getBounds();
433
+ let b = target.getBounds();
427
434
  ax = b.centerX - a.centerX;
428
435
  ay = b.centerY - a.centerY;
429
436
  } else { // vector object
@@ -440,11 +447,11 @@ import Color from "./../math/color.js";
440
447
  * @returns {number} distance
441
448
  */
442
449
  distanceTo(target) {
443
- var a = this.getBounds();
444
- var dx, dy;
450
+ let a = this.getBounds();
451
+ let dx, dy;
445
452
 
446
453
  if (target instanceof Renderable) {
447
- var b = target.getBounds();
454
+ let b = target.getBounds();
448
455
  dx = a.centerX - b.centerX;
449
456
  dy = a.centerY - b.centerY;
450
457
  } else { // vector object
@@ -461,7 +468,7 @@ import Color from "./../math/color.js";
461
468
  * @returns {Renderable} Reference to this object for method chaining
462
469
  */
463
470
  lookAt(target) {
464
- var position;
471
+ let position;
465
472
 
466
473
  if (target instanceof Renderable) {
467
474
  position = target.pos;
@@ -469,7 +476,7 @@ import Color from "./../math/color.js";
469
476
  position = target;
470
477
  }
471
478
 
472
- var angle = this.angleTo(position);
479
+ let angle = this.angleTo(position);
473
480
 
474
481
  this.rotate(angle);
475
482
 
@@ -534,7 +541,7 @@ import Color from "./../math/color.js";
534
541
  */
535
542
  updateBounds(absolute = true) {
536
543
  if (this.isRenderable) {
537
- var bounds = this.getBounds();
544
+ let bounds = this.getBounds();
538
545
 
539
546
  bounds.clear();
540
547
 
@@ -620,9 +627,7 @@ import Color from "./../math/color.js";
620
627
  // manually update the anchor point (required for updateBoundsPos)
621
628
  this.anchorPoint.setMuted(x, y);
622
629
  // then call updateBounds
623
- //this.updateBoundsPos(this.pos.x, this.pos.y);
624
630
  this.updateBounds();
625
- //console.log("hello");
626
631
  this.isDirty = true;
627
632
  }
628
633
 
@@ -634,7 +639,7 @@ import Color from "./../math/color.js";
634
639
  * @param {CanvasRenderer|WebGLRenderer} renderer - a renderer object
635
640
  */
636
641
  preDraw(renderer) {
637
- var ax = this.width * this.anchorPoint.x,
642
+ let ax = this.width * this.anchorPoint.x,
638
643
  ay = this.height * this.anchorPoint.y;
639
644
 
640
645
  // save renderer context
@@ -650,6 +655,11 @@ import Color from "./../math/color.js";
650
655
  renderer.translate(-this.pos.x, -this.pos.y);
651
656
  }
652
657
 
658
+ // use this renderable shader if defined
659
+ if (typeof this.shader === "object" && typeof renderer.gl !== "undefined") {
660
+ renderer.customShader = this.shader;
661
+ }
662
+
653
663
  if ((this.autoTransform === true) && (!this.currentTransform.isIdentity())) {
654
664
  // apply the renderable transformation matrix
655
665
  renderer.translate(this.pos.x, this.pos.y);
@@ -701,6 +711,12 @@ import Color from "./../math/color.js";
701
711
  renderer.clearMask();
702
712
  }
703
713
 
714
+ // revert to the default shader if defined
715
+ if (typeof this.shader === "object" && typeof renderer.gl !== "undefined") {
716
+ renderer.customShader = undefined;
717
+ //renderer.setCompositor("quad");
718
+ }
719
+
704
720
  // restore the context
705
721
  renderer.restore();
706
722
 
@@ -780,6 +796,12 @@ import Color from "./../math/color.js";
780
796
 
781
797
  // call the user defined destroy method
782
798
  this.onDestroyEvent.apply(this, arguments);
799
+
800
+ // destroy any shader object if not done by the user through onDestroyEvent()
801
+ if (typeof this.shader === "object") {
802
+ this.shader.destroy();
803
+ this.shader = undefined;
804
+ }
783
805
  }
784
806
 
785
807
  /**