melonjs 15.2.1 → 15.4.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 (291) hide show
  1. package/README.md +1 -1
  2. package/dist/melonjs.mjs/_virtual/_commonjsHelpers.js +1 -1
  3. package/dist/melonjs.mjs/_virtual/earcut.js +1 -1
  4. package/dist/melonjs.mjs/_virtual/howler.js +1 -1
  5. package/dist/melonjs.mjs/_virtual/index.js +1 -1
  6. package/dist/melonjs.mjs/application/application.js +75 -23
  7. package/dist/melonjs.mjs/application/header.js +2 -2
  8. package/dist/melonjs.mjs/application/resize.js +13 -11
  9. package/dist/melonjs.mjs/application/settings.js +37 -1
  10. package/dist/melonjs.mjs/audio/audio.js +4 -6
  11. package/dist/melonjs.mjs/camera/camera2d.js +12 -14
  12. package/dist/melonjs.mjs/const.js +1 -1
  13. package/dist/melonjs.mjs/entity/entity.js +3 -4
  14. package/dist/melonjs.mjs/geometries/ellipse.js +26 -59
  15. package/dist/melonjs.mjs/geometries/line.js +18 -25
  16. package/dist/melonjs.mjs/geometries/path2d.js +16 -13
  17. package/dist/melonjs.mjs/geometries/point.js +8 -16
  18. package/dist/melonjs.mjs/geometries/poly.js +40 -97
  19. package/dist/melonjs.mjs/geometries/rectangle.js +37 -91
  20. package/dist/melonjs.mjs/geometries/roundrect.js +26 -35
  21. package/dist/melonjs.mjs/index.js +6 -6
  22. package/dist/melonjs.mjs/input/gamepad.js +1 -1
  23. package/dist/melonjs.mjs/input/input.js +1 -1
  24. package/dist/melonjs.mjs/input/keyboard.js +3 -3
  25. package/dist/melonjs.mjs/input/pointer.js +4 -4
  26. package/dist/melonjs.mjs/input/pointerevent.js +6 -7
  27. package/dist/melonjs.mjs/lang/console.js +1 -1
  28. package/dist/melonjs.mjs/lang/deprecated.js +2 -2
  29. package/dist/melonjs.mjs/level/level.js +1 -1
  30. package/dist/melonjs.mjs/level/tiled/TMXGroup.js +1 -1
  31. package/dist/melonjs.mjs/level/tiled/TMXLayer.js +16 -33
  32. package/dist/melonjs.mjs/level/tiled/TMXObject.js +3 -4
  33. package/dist/melonjs.mjs/level/tiled/TMXTile.js +4 -4
  34. package/dist/melonjs.mjs/level/tiled/TMXTileMap.js +3 -3
  35. package/dist/melonjs.mjs/level/tiled/TMXTileset.js +4 -7
  36. package/dist/melonjs.mjs/level/tiled/TMXTilesetGroup.js +2 -2
  37. package/dist/melonjs.mjs/level/tiled/TMXUtils.js +37 -47
  38. package/dist/melonjs.mjs/level/tiled/constants.js +1 -1
  39. package/dist/melonjs.mjs/level/tiled/renderer/TMXHexagonalRenderer.js +3 -3
  40. package/dist/melonjs.mjs/level/tiled/renderer/TMXIsometricRenderer.js +2 -2
  41. package/dist/melonjs.mjs/level/tiled/renderer/TMXOrthogonalRenderer.js +2 -2
  42. package/dist/melonjs.mjs/level/tiled/renderer/TMXRenderer.js +2 -2
  43. package/dist/melonjs.mjs/level/tiled/renderer/TMXStaggeredRenderer.js +2 -2
  44. package/dist/melonjs.mjs/level/tiled/renderer/autodetect.js +1 -1
  45. package/dist/melonjs.mjs/loader/cache.js +1 -1
  46. package/dist/melonjs.mjs/loader/loader.js +1 -1
  47. package/dist/melonjs.mjs/loader/loadingscreen.js +1 -1
  48. package/dist/melonjs.mjs/loader/melonjs_logo.png.js +1 -1
  49. package/dist/melonjs.mjs/loader/parser.js +4 -5
  50. package/dist/melonjs.mjs/loader/settings.js +1 -1
  51. package/dist/melonjs.mjs/math/color.js +5 -5
  52. package/dist/melonjs.mjs/math/math.js +1 -1
  53. package/dist/melonjs.mjs/math/matrix2.js +5 -59
  54. package/dist/melonjs.mjs/math/matrix3.js +82 -141
  55. package/dist/melonjs.mjs/math/observable_vector2.js +7 -7
  56. package/dist/melonjs.mjs/math/observable_vector3.js +5 -5
  57. package/dist/melonjs.mjs/math/vector2.js +7 -91
  58. package/dist/melonjs.mjs/math/vector3.js +6 -90
  59. package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/esm/arraymultimap.js +1 -1
  60. package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/esm/multimap.js +1 -1
  61. package/dist/melonjs.mjs/node_modules/earcut/src/earcut.js +1 -1
  62. package/dist/melonjs.mjs/node_modules/eventemitter3/index.js +1 -1
  63. package/dist/melonjs.mjs/node_modules/eventemitter3/index2.js +1 -1
  64. package/dist/melonjs.mjs/node_modules/howler/dist/howler.js +1 -1
  65. package/dist/melonjs.mjs/particles/emitter.js +2 -2
  66. package/dist/melonjs.mjs/particles/particle.js +2 -2
  67. package/dist/melonjs.mjs/particles/settings.js +1 -1
  68. package/dist/melonjs.mjs/physics/body.js +22 -20
  69. package/dist/melonjs.mjs/physics/bounds.js +27 -33
  70. package/dist/melonjs.mjs/physics/collision.js +5 -5
  71. package/dist/melonjs.mjs/physics/detector.js +10 -10
  72. package/dist/melonjs.mjs/physics/quadtree.js +5 -5
  73. package/dist/melonjs.mjs/physics/response.js +1 -1
  74. package/dist/melonjs.mjs/physics/sat.js +3 -4
  75. package/dist/melonjs.mjs/physics/world.js +6 -9
  76. package/dist/melonjs.mjs/plugin/plugin.js +3 -3
  77. package/dist/melonjs.mjs/renderable/collectable.js +2 -2
  78. package/dist/melonjs.mjs/renderable/colorlayer.js +4 -4
  79. package/dist/melonjs.mjs/renderable/container.js +25 -25
  80. package/dist/melonjs.mjs/renderable/draggable.js +1 -1
  81. package/dist/melonjs.mjs/renderable/dragndrop.js +1 -1
  82. package/dist/melonjs.mjs/renderable/imagelayer.js +4 -4
  83. package/dist/melonjs.mjs/renderable/light2d.js +3 -3
  84. package/dist/melonjs.mjs/renderable/nineslicesprite.js +2 -2
  85. package/dist/melonjs.mjs/renderable/renderable.js +31 -39
  86. package/dist/melonjs.mjs/renderable/sprite.js +3 -3
  87. package/dist/melonjs.mjs/renderable/text/bitmaptext.js +421 -0
  88. package/dist/melonjs.mjs/renderable/text/bitmaptextdata.js +195 -0
  89. package/dist/melonjs.mjs/renderable/text/glyph.js +65 -0
  90. package/dist/melonjs.mjs/renderable/text/text.js +422 -0
  91. package/dist/melonjs.mjs/renderable/text/textmetrics.js +175 -0
  92. package/dist/melonjs.mjs/renderable/text/textstyle.js +21 -0
  93. package/dist/melonjs.mjs/renderable/trigger.js +10 -10
  94. package/dist/melonjs.mjs/renderable/ui/uibaseelement.js +7 -7
  95. package/dist/melonjs.mjs/renderable/ui/uispriteelement.js +7 -7
  96. package/dist/melonjs.mjs/renderable/ui/uitextbutton.js +3 -3
  97. package/dist/melonjs.mjs/state/stage.js +13 -14
  98. package/dist/melonjs.mjs/state/state.js +4 -51
  99. package/dist/melonjs.mjs/system/device.js +51 -10
  100. package/dist/melonjs.mjs/system/dom.js +1 -1
  101. package/dist/melonjs.mjs/system/event.js +46 -2
  102. package/dist/melonjs.mjs/system/platform.js +18 -18
  103. package/dist/melonjs.mjs/system/pooling.js +10 -10
  104. package/dist/melonjs.mjs/system/save.js +1 -1
  105. package/dist/melonjs.mjs/system/timer.js +1 -1
  106. package/dist/melonjs.mjs/text/bitmaptext.js +1 -1
  107. package/dist/melonjs.mjs/text/bitmaptextdata.js +3 -6
  108. package/dist/melonjs.mjs/text/glyph.js +1 -1
  109. package/dist/melonjs.mjs/text/text.js +1 -1
  110. package/dist/melonjs.mjs/text/textmetrics.js +1 -1
  111. package/dist/melonjs.mjs/text/textstyle.js +1 -1
  112. package/dist/melonjs.mjs/tweens/easing.js +1 -1
  113. package/dist/melonjs.mjs/tweens/interpolation.js +1 -1
  114. package/dist/melonjs.mjs/tweens/tween.js +2 -2
  115. package/dist/melonjs.mjs/utils/agent.js +1 -1
  116. package/dist/melonjs.mjs/utils/array.js +1 -1
  117. package/dist/melonjs.mjs/utils/file.js +1 -1
  118. package/dist/melonjs.mjs/utils/function.js +2 -3
  119. package/dist/melonjs.mjs/utils/string.js +1 -1
  120. package/dist/melonjs.mjs/utils/utils.js +1 -1
  121. package/dist/melonjs.mjs/video/canvas/canvas_renderer.js +5 -18
  122. package/dist/melonjs.mjs/video/renderer.js +17 -30
  123. package/dist/melonjs.mjs/video/texture/atlas.js +13 -13
  124. package/dist/melonjs.mjs/video/texture/cache.js +1 -1
  125. package/dist/melonjs.mjs/video/texture/canvas_texture.js +15 -15
  126. package/dist/melonjs.mjs/video/utils/autodetect.js +1 -1
  127. package/dist/melonjs.mjs/video/video.js +5 -29
  128. package/dist/melonjs.mjs/video/webgl/buffer/vertex.js +3 -3
  129. package/dist/melonjs.mjs/video/webgl/compositors/compositor.js +13 -14
  130. package/dist/melonjs.mjs/video/webgl/compositors/primitive_compositor.js +5 -5
  131. package/dist/melonjs.mjs/video/webgl/compositors/quad_compositor.js +2 -3
  132. package/dist/melonjs.mjs/video/webgl/glshader.js +2 -2
  133. package/dist/melonjs.mjs/video/webgl/shaders/primitive.frag.js +1 -1
  134. package/dist/melonjs.mjs/video/webgl/shaders/primitive.vert.js +1 -1
  135. package/dist/melonjs.mjs/video/webgl/shaders/quad.frag.js +1 -1
  136. package/dist/melonjs.mjs/video/webgl/shaders/quad.vert.js +1 -1
  137. package/dist/melonjs.mjs/video/webgl/utils/attributes.js +1 -1
  138. package/dist/melonjs.mjs/video/webgl/utils/precision.js +4 -4
  139. package/dist/melonjs.mjs/video/webgl/utils/program.js +1 -1
  140. package/dist/melonjs.mjs/video/webgl/utils/string.js +1 -1
  141. package/dist/melonjs.mjs/video/webgl/utils/uniforms.js +1 -1
  142. package/dist/melonjs.mjs/video/webgl/webgl_renderer.js +62 -67
  143. package/dist/melonjs.module.js +1272 -1713
  144. package/dist/types/application/application.d.ts +32 -31
  145. package/dist/types/application/header.d.ts +2 -2
  146. package/dist/types/application/settings.d.ts +80 -16
  147. package/dist/types/audio/audio.d.ts +4 -6
  148. package/dist/types/camera/camera2d.d.ts +13 -16
  149. package/dist/types/entity/entity.d.ts +0 -1
  150. package/dist/types/geometries/ellipse.d.ts +18 -50
  151. package/dist/types/geometries/path2d.d.ts +1 -1
  152. package/dist/types/geometries/point.d.ts +5 -13
  153. package/dist/types/geometries/poly.d.ts +26 -75
  154. package/dist/types/geometries/rectangle.d.ts +12 -58
  155. package/dist/types/geometries/roundrect.d.ts +2 -11
  156. package/dist/types/index.d.ts +3 -3
  157. package/dist/types/input/gamepad.d.ts +31 -31
  158. package/dist/types/input/keyboard.d.ts +105 -105
  159. package/dist/types/input/pointer.d.ts +21 -21
  160. package/dist/types/input/pointerevent.d.ts +6 -6
  161. package/dist/types/level/tiled/TMXLayer.d.ts +1 -1
  162. package/dist/types/level/tiled/TMXUtils.d.ts +4 -6
  163. package/dist/types/math/matrix2.d.ts +9 -63
  164. package/dist/types/math/matrix3.d.ts +9 -68
  165. package/dist/types/math/observable_vector2.d.ts +2 -2
  166. package/dist/types/math/observable_vector3.d.ts +2 -2
  167. package/dist/types/math/vector2.d.ts +8 -92
  168. package/dist/types/math/vector3.d.ts +8 -92
  169. package/dist/types/particles/settings.d.ts +29 -29
  170. package/dist/types/physics/body.d.ts +10 -8
  171. package/dist/types/physics/bounds.d.ts +24 -30
  172. package/dist/types/physics/collision.d.ts +12 -12
  173. package/dist/types/physics/detector.d.ts +1 -1
  174. package/dist/types/physics/world.d.ts +4 -7
  175. package/dist/types/renderable/container.d.ts +19 -19
  176. package/dist/types/renderable/imagelayer.d.ts +6 -6
  177. package/dist/types/renderable/light2d.d.ts +7 -7
  178. package/dist/types/renderable/renderable.d.ts +10 -18
  179. package/dist/types/renderable/text/bitmaptext.d.ts +151 -0
  180. package/dist/types/renderable/text/bitmaptextdata.d.ts +35 -0
  181. package/dist/types/renderable/text/glyph.d.ts +28 -0
  182. package/dist/types/renderable/text/text.d.ts +159 -0
  183. package/dist/types/renderable/text/textmetrics.d.ts +47 -0
  184. package/dist/types/renderable/text/textstyle.d.ts +5 -0
  185. package/dist/types/renderable/ui/uibaseelement.d.ts +0 -1
  186. package/dist/types/renderable/ui/uispriteelement.d.ts +0 -1
  187. package/dist/types/renderable/ui/uitextbutton.d.ts +2 -7
  188. package/dist/types/state/stage.d.ts +3 -2
  189. package/dist/types/state/state.d.ts +11 -11
  190. package/dist/types/system/device.d.ts +16 -9
  191. package/dist/types/system/event.d.ts +40 -0
  192. package/dist/types/system/platform.d.ts +17 -17
  193. package/dist/types/utils/function.d.ts +1 -2
  194. package/dist/types/video/canvas/canvas_renderer.d.ts +0 -23
  195. package/dist/types/video/renderer.d.ts +16 -43
  196. package/dist/types/video/texture/canvas_texture.d.ts +14 -14
  197. package/dist/types/video/video.d.ts +4 -38
  198. package/dist/types/video/webgl/buffer/vertex.d.ts +2 -2
  199. package/dist/types/video/webgl/compositors/compositor.d.ts +24 -13
  200. package/dist/types/video/webgl/compositors/primitive_compositor.d.ts +0 -1
  201. package/dist/types/video/webgl/compositors/quad_compositor.d.ts +0 -1
  202. package/dist/types/video/webgl/utils/precision.d.ts +1 -1
  203. package/dist/types/video/webgl/webgl_renderer.d.ts +48 -84
  204. package/package.json +15 -15
  205. package/src/application/application.js +73 -21
  206. package/src/application/header.js +1 -1
  207. package/src/application/resize.js +11 -9
  208. package/src/application/settings.js +36 -0
  209. package/src/audio/audio.js +3 -5
  210. package/src/camera/camera2d.js +11 -13
  211. package/src/entity/entity.js +2 -3
  212. package/src/geometries/ellipse.js +25 -58
  213. package/src/geometries/line.js +17 -24
  214. package/src/geometries/path2d.js +15 -12
  215. package/src/geometries/point.js +7 -15
  216. package/src/geometries/poly.js +39 -96
  217. package/src/geometries/rectangle.js +36 -90
  218. package/src/geometries/roundrect.js +25 -34
  219. package/src/index.js +4 -4
  220. package/src/input/keyboard.js +2 -2
  221. package/src/input/pointer.js +3 -3
  222. package/src/input/pointerevent.js +5 -6
  223. package/src/lang/deprecated.js +1 -1
  224. package/src/level/tiled/TMXLayer.js +15 -32
  225. package/src/level/tiled/TMXObject.js +2 -3
  226. package/src/level/tiled/TMXTile.js +3 -3
  227. package/src/level/tiled/TMXTileMap.js +2 -2
  228. package/src/level/tiled/TMXTileset.js +3 -6
  229. package/src/level/tiled/TMXTilesetGroup.js +1 -1
  230. package/src/level/tiled/TMXUtils.js +36 -46
  231. package/src/level/tiled/renderer/TMXHexagonalRenderer.js +2 -2
  232. package/src/level/tiled/renderer/TMXIsometricRenderer.js +1 -1
  233. package/src/level/tiled/renderer/TMXOrthogonalRenderer.js +1 -1
  234. package/src/level/tiled/renderer/TMXRenderer.js +1 -1
  235. package/src/level/tiled/renderer/TMXStaggeredRenderer.js +1 -1
  236. package/src/loader/parser.js +3 -4
  237. package/src/math/color.js +4 -4
  238. package/src/math/matrix2.js +4 -58
  239. package/src/math/matrix3.js +81 -140
  240. package/src/math/observable_vector2.js +6 -6
  241. package/src/math/observable_vector3.js +4 -4
  242. package/src/math/vector2.js +6 -90
  243. package/src/math/vector3.js +5 -89
  244. package/src/particles/emitter.js +1 -1
  245. package/src/particles/particle.js +1 -1
  246. package/src/physics/body.js +21 -19
  247. package/src/physics/bounds.js +26 -32
  248. package/src/physics/collision.js +4 -4
  249. package/src/physics/detector.js +9 -9
  250. package/src/physics/quadtree.js +4 -4
  251. package/src/physics/sat.js +2 -3
  252. package/src/physics/world.js +5 -8
  253. package/src/polyfill/roundrect.js +163 -163
  254. package/src/renderable/collectable.js +1 -1
  255. package/src/renderable/colorlayer.js +3 -3
  256. package/src/renderable/container.js +24 -24
  257. package/src/renderable/imagelayer.js +3 -3
  258. package/src/renderable/light2d.js +2 -2
  259. package/src/renderable/nineslicesprite.js +1 -1
  260. package/src/renderable/renderable.js +30 -38
  261. package/src/renderable/sprite.js +2 -2
  262. package/src/{text → renderable/text}/bitmaptext.js +8 -8
  263. package/src/{text → renderable/text}/bitmaptextdata.js +4 -7
  264. package/src/{text → renderable/text}/glyph.js +1 -1
  265. package/src/{text → renderable/text}/text.js +16 -17
  266. package/src/{text → renderable/text}/textmetrics.js +2 -2
  267. package/src/renderable/trigger.js +9 -9
  268. package/src/renderable/ui/uibaseelement.js +6 -6
  269. package/src/renderable/ui/uispriteelement.js +6 -6
  270. package/src/renderable/ui/uitextbutton.js +2 -2
  271. package/src/state/stage.js +12 -13
  272. package/src/state/state.js +2 -61
  273. package/src/system/device.js +50 -9
  274. package/src/system/event.js +44 -0
  275. package/src/system/platform.js +18 -18
  276. package/src/system/pooling.js +9 -9
  277. package/src/tweens/tween.js +1 -1
  278. package/src/utils/function.js +1 -2
  279. package/src/video/canvas/canvas_renderer.js +4 -17
  280. package/src/video/renderer.js +16 -29
  281. package/src/video/texture/atlas.js +12 -12
  282. package/src/video/texture/canvas_texture.js +14 -14
  283. package/src/video/video.js +7 -28
  284. package/src/video/webgl/buffer/vertex.js +2 -2
  285. package/src/video/webgl/compositors/compositor.js +12 -13
  286. package/src/video/webgl/compositors/primitive_compositor.js +4 -4
  287. package/src/video/webgl/compositors/quad_compositor.js +1 -2
  288. package/src/video/webgl/glshader.js +1 -1
  289. package/src/video/webgl/utils/precision.js +3 -3
  290. package/src/video/webgl/webgl_renderer.js +61 -66
  291. /package/src/{text → renderable/text}/textstyle.js +0 -0
@@ -21,7 +21,7 @@ function createDefaultParticleTexture(w = 8, h = 8) {
21
21
  * Particle Emitter Object.
22
22
  * @augments Container
23
23
  */
24
- export default class ParticleEmitter extends Container {
24
+ export default class ParticleEmitter extends Container {
25
25
  /**
26
26
  * @param {number} x - x position of the particle emitter
27
27
  * @param {number} y - y position of the particle emitter
@@ -8,7 +8,7 @@ import Renderable from "./../renderable/renderable.js";
8
8
  * Single Particle Object.
9
9
  * @augments Renderable
10
10
  */
11
- export default class Particle extends Renderable {
11
+ export default class Particle extends Renderable {
12
12
  /**
13
13
  * @param {ParticleEmitter} emitter - the particle emitter
14
14
  */
@@ -14,7 +14,7 @@ import Point from "../geometries/point.js";
14
14
  * a Generic Physic Body Object with some physic properties and behavior functionality, to as a member of a Renderable.
15
15
  * @see Renderable.body
16
16
  */
17
- export default class Body {
17
+ export default class Body {
18
18
  /**
19
19
  * @param {Renderable|Container|Entity|Sprite|NineSliceSprite} ancestor - the parent object this body is attached to
20
20
  * @param {Rect|Rect[]|Polygon|Polygon[]|Line|Line[]|Ellipse|Ellipse[]|Point|Point[]|Bounds|Bounds[]|object} [shapes] - a initial shape, list of shapes, or JSON object defining the body
@@ -516,32 +516,34 @@ import Point from "../geometries/point.js";
516
516
 
517
517
  /**
518
518
  * Returns true if the any of the shape composing the body contains the given point.
519
- * @method Body#contains
520
- * @param {Vector2d} point
521
- * @returns {boolean} true if contains
522
- */
523
- /**
524
- * Returns true if the any of the shape composing the body contains the given point.
525
- * @param {number} x - x coordinate
526
- * @param {number} y - y coordinate
519
+ * @param {number|Vector2d} x - x coordinate or a vector point to check
520
+ * @param {number} [y] - y coordinate
527
521
  * @returns {boolean} true if contains
522
+ * @example
523
+ * if (mySprite.body.contains(10, 10)) {
524
+ * // do something
525
+ * }
526
+ * // or
527
+ * if (mySprite.body.contains(myVector2d)) {
528
+ * // do something
529
+ * }
528
530
  */
529
531
  contains() {
530
532
  let _x, _y;
531
533
 
532
534
  if (arguments.length === 2) {
533
- // x, y
534
- _x = arguments[0];
535
- _y = arguments[1];
535
+ // x, y
536
+ _x = arguments[0];
537
+ _y = arguments[1];
536
538
  } else {
537
- // vector
538
- _x = arguments[0].x;
539
- _y = arguments[0].y;
539
+ // vector
540
+ _x = arguments[0].x;
541
+ _y = arguments[0].y;
540
542
  }
541
543
 
542
544
  if (this.getBounds().contains(_x, _y)) {
543
- // cannot use forEach here as cannot break out with a return
544
- for (let i = this.shapes.length, shape; i--, (shape = this.shapes[i]);) {
545
+ // cannot use forEach here as cannot break out with a return
546
+ for (let i = this.shapes.length, shape; i--, (shape = this.shapes[i]);) {
545
547
  if (shape.contains(_x, _y)) {
546
548
  return true;
547
549
  }
@@ -633,7 +635,7 @@ import Point from "../geometries/point.js";
633
635
 
634
636
  this.vel.x = (
635
637
  (nx < 0) ? nx :
636
- ( x > 0) ? x : 0
638
+ ( x > 0) ? x : 0
637
639
  );
638
640
  }
639
641
  if (this.friction.y > 0) {
@@ -643,7 +645,7 @@ import Point from "../geometries/point.js";
643
645
 
644
646
  this.vel.y = (
645
647
  (ny < 0) ? ny :
646
- ( y > 0) ? y : 0
648
+ ( y > 0) ? y : 0
647
649
  );
648
650
  }
649
651
 
@@ -5,7 +5,7 @@ import Vector2d from "./../math/vector2.js";
5
5
  * @classdesc
6
6
  * a bound object contains methods for creating and manipulating axis-aligned bounding boxes (AABB).
7
7
  */
8
- export default class Bounds {
8
+ export default class Bounds {
9
9
  /**
10
10
  * @param {Vector2d[]|Point[]} [vertices] - an array of Vector2d or Point
11
11
  */
@@ -254,17 +254,17 @@ import Vector2d from "./../math/vector2.js";
254
254
 
255
255
  /**
256
256
  * Returns true if the bounds contains the given point.
257
- * @name contains
258
- * @memberof Bounds
259
- * @method
260
- * @param {Vector2d} point
261
- * @returns {boolean} True if the bounds contain the point, otherwise false
262
- */
263
- /**
264
- * Returns true if the bounds contains the given point.
265
- * @param {number} x
266
- * @param {number} y
257
+ * @param {number|Vector2d} x - x coordinate or a vector point to check
258
+ * @param {number} [y] - y coordinate
267
259
  * @returns {boolean} True if the bounds contain the point, otherwise false
260
+ * @example
261
+ * if (bounds.contains(10, 10)) {
262
+ * // do something
263
+ * }
264
+ * // or
265
+ * if (bounds.contains(myVector2d)) {
266
+ * // do something
267
+ * }
268
268
  */
269
269
  contains() {
270
270
  let arg0 = arguments[0];
@@ -274,8 +274,8 @@ import Vector2d from "./../math/vector2.js";
274
274
  _x1 = _x2 = arg0;
275
275
  _y1 = _y2 = arguments[1];
276
276
  } else {
277
- if (arg0 instanceof Bounds) {
278
- // bounds
277
+ if (typeof arg0.max !== "undefined") {
278
+ // only bounds define min and max properties
279
279
  _x1 = arg0.min.x;
280
280
  _x2 = arg0.max.x;
281
281
  _y1 = arg0.min.y;
@@ -310,16 +310,13 @@ import Vector2d from "./../math/vector2.js";
310
310
  }
311
311
 
312
312
  /**
313
- * Translates the bounds by the given vector.
314
- * @name translate
315
- * @memberof Bounds
316
- * @method
317
- * @param {Vector2d} vector
318
- */
319
- /**
320
- * Translates the bounds by x on the x axis, and y on the y axis
321
- * @param {number} x
322
- * @param {number} y
313
+ * Translates the bounds by the given point
314
+ * @param {number|Vector2d} x - x coordinate or a vector point to translate by
315
+ * @param {number} [y]
316
+ * @example
317
+ * bounds.translate(10, 10);
318
+ * // or
319
+ * bounds.translate(myVector2d);
323
320
  */
324
321
  translate() {
325
322
  let _x, _y;
@@ -338,17 +335,14 @@ import Vector2d from "./../math/vector2.js";
338
335
  this.max.y += _y;
339
336
  }
340
337
 
341
- /**
342
- * Shifts the bounds to the given position vector.
343
- * @name shift
344
- * @memberof Bounds
345
- * @method
346
- * @param {Vector2d} position
347
- */
348
338
  /**
349
339
  * Shifts the bounds to the given x, y position.
350
- * @param {number} x
351
- * @param {number} y
340
+ * @param {number|Vector2d} x - x coordinate or a vector point to shift to
341
+ * @param {number} [y]
342
+ * @example
343
+ * bounds.shift(10, 10);
344
+ * // or
345
+ * bounds.shift(myVector2d);
352
346
  */
353
347
  shift() {
354
348
  let _x, _y;
@@ -8,7 +8,7 @@ import { game } from "../index.js";
8
8
 
9
9
  let collision = {
10
10
 
11
- /**
11
+ /**
12
12
  * The maximum number of children that a quadtree node can contain before it is split into sub-nodes.
13
13
  * @name maxChildren
14
14
  * @memberof collision
@@ -17,9 +17,9 @@ let collision = {
17
17
  * @default 8
18
18
  * @see game.world.broadphase
19
19
  */
20
- maxChildren : 8,
20
+ maxChildren : 8,
21
21
 
22
- /**
22
+ /**
23
23
  * The maximum number of levels that the quadtree will create.
24
24
  * @name maxDepth
25
25
  * @memberof collision
@@ -28,7 +28,7 @@ let collision = {
28
28
  * @default 4
29
29
  * @see game.world.broadphase
30
30
  */
31
- maxDepth : 4,
31
+ maxDepth : 4,
32
32
 
33
33
  /**
34
34
  * Enum for collision type values.
@@ -62,7 +62,7 @@ export default class Detector {
62
62
  * detect collision between two bodies.
63
63
  * @param {Body} bodyA - a reference to body A.
64
64
  * @param {Body} bodyB - a reference to body B.
65
- * @returns {Boolean} true if colliding
65
+ * @returns {boolean} true if colliding
66
66
  */
67
67
  collides(bodyA, bodyB, response = this.response) {
68
68
  // for each shape in body A
@@ -71,13 +71,13 @@ export default class Detector {
71
71
  for (let indexB = bodyB.shapes.length, shapeB; indexB--, (shapeB = bodyB.shapes[indexB]);) {
72
72
  // full SAT collision check
73
73
  if (SAT["test" + shapeA.shapeType + shapeB.shapeType].call(
74
- this,
75
- bodyA.ancestor, // a reference to the object A
76
- shapeA,
77
- bodyB.ancestor, // a reference to the object B
78
- shapeB,
79
- // clear response object before reusing
80
- response.clear()) === true
74
+ this,
75
+ bodyA.ancestor, // a reference to the object A
76
+ shapeA,
77
+ bodyB.ancestor, // a reference to the object B
78
+ shapeB,
79
+ // clear response object before reusing
80
+ response.clear()) === true
81
81
  ) {
82
82
 
83
83
  // set the shape index
@@ -190,7 +190,7 @@ export default class Detector {
190
190
  shapeA,
191
191
  objB, // a reference to the object B
192
192
  shapeB
193
- )) {
193
+ )) {
194
194
  // we touched something !
195
195
  result[collisionCounter] = objB;
196
196
  collisionCounter++;
@@ -51,7 +51,7 @@ let QT_VECTOR = new Vector2d();
51
51
  * a QuadTree implementation in JavaScript, a 2d spatial subdivision algorithm.
52
52
  * @see game.world.broadphase
53
53
  */
54
- export default class QuadTree {
54
+ export default class QuadTree {
55
55
  /**
56
56
  * @param {World} world - the physic world this QuadTree belongs to
57
57
  * @param {Bounds} bounds - bounds of the node
@@ -83,7 +83,7 @@ let QT_VECTOR = new Vector2d();
83
83
  left = this.bounds.left,
84
84
  top = this.bounds.top;
85
85
 
86
- //top right node
86
+ //top right node
87
87
  this.nodes[0] = QT_ARRAY_POP(
88
88
  this.world,
89
89
  {
@@ -279,7 +279,7 @@ let QT_VECTOR = new Vector2d();
279
279
  if (index !== -1) {
280
280
  returnObjects = returnObjects.concat(this.nodes[index].retrieve(item));
281
281
  } else {
282
- //if rect does not fit into a subnode, check it against all subnodes
282
+ //if rect does not fit into a subnode, check it against all subnodes
283
283
  for (let i = 0; i < this.nodes.length; i = i + 1) {
284
284
  returnObjects = returnObjects.concat(this.nodes[i].retrieve(item));
285
285
  }
@@ -301,7 +301,7 @@ let QT_VECTOR = new Vector2d();
301
301
  * @param {object} item - object to be removed
302
302
  * @returns {boolean} true if the item was found and removed.
303
303
  */
304
- remove(item) {
304
+ remove(item) {
305
305
  let found = false;
306
306
 
307
307
  if (typeof (item.getBounds) === "undefined") {
@@ -205,10 +205,9 @@ export function testPolygonPolygon(a, polyA, b, polyB, response) {
205
205
  // aboslute shape position
206
206
  let posA = T_VECTORS.pop().copy(a.pos).add(a.ancestor.getAbsolutePosition()).add(polyA.pos);
207
207
  let posB = T_VECTORS.pop().copy(b.pos).add(b.ancestor.getAbsolutePosition()).add(polyB.pos);
208
- let i;
209
208
 
210
209
  // If any of the edge normals of A is a separating axis, no intersection.
211
- for (i = 0; i < aLen; i++) {
210
+ for (let i = 0; i < aLen; i++) {
212
211
  if (isSeparatingAxis(posA, posB, aPoints, bPoints, aNormals[i], response)) {
213
212
  T_VECTORS.push(posA);
214
213
  T_VECTORS.push(posB);
@@ -217,7 +216,7 @@ export function testPolygonPolygon(a, polyA, b, polyB, response) {
217
216
  }
218
217
 
219
218
  // If any of the edge normals of B is a separating axis, no intersection.
220
- for (i = 0; i < bLen; i++) {
219
+ for (let i = 0; i < bLen; i++) {
221
220
  if (isSeparatingAxis(posA, posB, aPoints, bPoints, bNormals[i], response)) {
222
221
  T_VECTORS.push(posA);
223
222
  T_VECTORS.push(posB);
@@ -11,7 +11,7 @@ import state from "./../state/state.js";
11
11
  * an object representing the physic world, and responsible for managing and updating all childs and physics
12
12
  * @augments Container
13
13
  */
14
- export default class World extends Container {
14
+ export default class World extends Container {
15
15
  /**
16
16
  * @param {number} [x=0] - position of the container (accessible via the inherited pos.x property)
17
17
  * @param {number} [y=0] - position of the container (accessible via the inherited pos.y property)
@@ -50,13 +50,10 @@ import state from "./../state/state.js";
50
50
  this.gravity = new Vector2d(0, 0.98);
51
51
 
52
52
  /**
53
- * Specify the rendering method for tile layers. <br>
54
- * if false visible part of the layers are rendered dynamically,<br>
55
- * if true the entire layers are first rendered into an offscreen canvas.<br>
56
- * the "best" rendering method depends of your game
57
- * (amount of layer, layer size, amount of tiles per layer, etc.)<br>
58
- * note : rendering method is also configurable per layer by adding this
59
- * property to your layer (in Tiled).
53
+ * Enabled pre-rendering for all tile layers. <br>
54
+ * If false layers are rendered dynamically, if true layers are first fully rendered into an offscreen canvas.<br>
55
+ * the "best" rendering method depends of your game (amount of layer, layer size, amount of tiles per layer, etc.)<br>
56
+ * Note : rendering method is also configurable per layer by adding a boolean "preRender" property to your layer in Tiled ({@link https://doc.mapeditor.org/en/stable/manual/custom-properties/#adding-properties}).
60
57
  * @type {boolean}
61
58
  * @default false
62
59
  */