melonjs 14.4.0 → 15.0.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 (245) hide show
  1. package/LICENSE.md +1 -1
  2. package/README.md +13 -57
  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 +1 -1
  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 +1 -1
  12. package/dist/melonjs.mjs/application/header.js +1 -1
  13. package/dist/melonjs.mjs/application/resize.js +1 -1
  14. package/dist/melonjs.mjs/application/settings.js +1 -1
  15. package/dist/melonjs.mjs/audio/audio.js +5 -7
  16. package/dist/melonjs.mjs/camera/camera2d.js +1 -1
  17. package/dist/melonjs.mjs/const.js +1 -1
  18. package/dist/melonjs.mjs/entity/entity.js +43 -9
  19. package/dist/melonjs.mjs/geometries/ellipse.js +2 -3
  20. package/dist/melonjs.mjs/geometries/line.js +1 -1
  21. package/dist/melonjs.mjs/geometries/path2d.js +20 -44
  22. package/dist/melonjs.mjs/geometries/point.js +1 -6
  23. package/dist/melonjs.mjs/geometries/poly.js +2 -5
  24. package/dist/melonjs.mjs/geometries/rectangle.js +13 -9
  25. package/dist/melonjs.mjs/geometries/roundrect.js +1 -1
  26. package/dist/melonjs.mjs/index.js +10 -6
  27. package/dist/melonjs.mjs/input/gamepad.js +10 -16
  28. package/dist/melonjs.mjs/input/input.js +1 -1
  29. package/dist/melonjs.mjs/input/keyboard.js +1 -1
  30. package/dist/melonjs.mjs/input/pointer.js +1 -1
  31. package/dist/melonjs.mjs/input/pointerevent.js +3 -17
  32. package/dist/melonjs.mjs/lang/console.js +1 -1
  33. package/dist/melonjs.mjs/lang/deprecated.js +1 -1
  34. package/dist/melonjs.mjs/level/level.js +3 -3
  35. package/dist/melonjs.mjs/level/tiled/TMXGroup.js +1 -1
  36. package/dist/melonjs.mjs/level/tiled/TMXLayer.js +1 -8
  37. package/dist/melonjs.mjs/level/tiled/TMXObject.js +1 -1
  38. package/dist/melonjs.mjs/level/tiled/TMXTile.js +1 -1
  39. package/dist/melonjs.mjs/level/tiled/TMXTileMap.js +8 -4
  40. package/dist/melonjs.mjs/level/tiled/TMXTileset.js +5 -5
  41. package/dist/melonjs.mjs/level/tiled/TMXTilesetGroup.js +1 -1
  42. package/dist/melonjs.mjs/level/tiled/TMXUtils.js +1 -1
  43. package/dist/melonjs.mjs/level/tiled/constants.js +1 -1
  44. package/dist/melonjs.mjs/level/tiled/renderer/TMXHexagonalRenderer.js +1 -1
  45. package/dist/melonjs.mjs/level/tiled/renderer/TMXIsometricRenderer.js +1 -1
  46. package/dist/melonjs.mjs/level/tiled/renderer/TMXOrthogonalRenderer.js +1 -1
  47. package/dist/melonjs.mjs/level/tiled/renderer/TMXRenderer.js +1 -1
  48. package/dist/melonjs.mjs/level/tiled/renderer/TMXStaggeredRenderer.js +1 -1
  49. package/dist/melonjs.mjs/level/tiled/renderer/autodetect.js +1 -1
  50. package/dist/melonjs.mjs/loader/cache.js +24 -0
  51. package/dist/melonjs.mjs/loader/loader.js +331 -716
  52. package/dist/melonjs.mjs/loader/loadingscreen.js +4 -4
  53. package/dist/melonjs.mjs/loader/melonjs_logo.png.js +1 -1
  54. package/dist/melonjs.mjs/loader/parser.js +281 -0
  55. package/dist/melonjs.mjs/loader/settings.js +91 -0
  56. package/dist/melonjs.mjs/math/color.js +9 -8
  57. package/dist/melonjs.mjs/math/math.js +1 -1
  58. package/dist/melonjs.mjs/math/matrix2.js +7 -9
  59. package/dist/melonjs.mjs/math/matrix3.js +18 -21
  60. package/dist/melonjs.mjs/math/observable_vector2.js +3 -3
  61. package/dist/melonjs.mjs/math/observable_vector3.js +3 -4
  62. package/dist/melonjs.mjs/math/vector2.js +3 -3
  63. package/dist/melonjs.mjs/math/vector3.js +3 -4
  64. package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/arraymultimap.js +1 -1
  65. package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/index.js +1 -1
  66. package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/multimap.js +1 -1
  67. package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/setmultimap.js +1 -1
  68. package/dist/melonjs.mjs/node_modules/earcut/src/earcut.js +1 -1
  69. package/dist/melonjs.mjs/node_modules/eventemitter3/index.js +1 -1
  70. package/dist/melonjs.mjs/node_modules/eventemitter3/index2.js +1 -1
  71. package/dist/melonjs.mjs/node_modules/howler/dist/howler.js +1 -1
  72. package/dist/melonjs.mjs/particles/emitter.js +3 -3
  73. package/dist/melonjs.mjs/particles/particle.js +1 -1
  74. package/dist/melonjs.mjs/particles/settings.js +1 -1
  75. package/dist/melonjs.mjs/physics/body.js +18 -14
  76. package/dist/melonjs.mjs/physics/bounds.js +18 -70
  77. package/dist/melonjs.mjs/physics/collision.js +1 -1
  78. package/dist/melonjs.mjs/physics/detector.js +1 -1
  79. package/dist/melonjs.mjs/physics/quadtree.js +1 -1
  80. package/dist/melonjs.mjs/physics/response.js +1 -1
  81. package/dist/melonjs.mjs/physics/sat.js +1 -1
  82. package/dist/melonjs.mjs/physics/world.js +1 -1
  83. package/dist/melonjs.mjs/plugin/plugin.js +3 -3
  84. package/dist/melonjs.mjs/renderable/collectable.js +1 -1
  85. package/dist/melonjs.mjs/renderable/colorlayer.js +1 -1
  86. package/dist/melonjs.mjs/renderable/container.js +25 -19
  87. package/dist/melonjs.mjs/renderable/dragndrop.js +1 -1
  88. package/dist/melonjs.mjs/renderable/imagelayer.js +7 -1
  89. package/dist/melonjs.mjs/renderable/light2d.js +1 -1
  90. package/dist/melonjs.mjs/renderable/nineslicesprite.js +1 -1
  91. package/dist/melonjs.mjs/renderable/renderable.js +148 -105
  92. package/dist/melonjs.mjs/renderable/sprite.js +33 -54
  93. package/dist/melonjs.mjs/renderable/trigger.js +1 -1
  94. package/dist/melonjs.mjs/renderable/ui/uibaseelement.js +1 -1
  95. package/dist/melonjs.mjs/renderable/ui/uispriteelement.js +1 -1
  96. package/dist/melonjs.mjs/renderable/ui/uitextbutton.js +1 -3
  97. package/dist/melonjs.mjs/state/stage.js +1 -1
  98. package/dist/melonjs.mjs/state/state.js +2 -2
  99. package/dist/melonjs.mjs/system/device.js +2 -2
  100. package/dist/melonjs.mjs/system/dom.js +1 -1
  101. package/dist/melonjs.mjs/system/event.js +1 -1
  102. package/dist/melonjs.mjs/system/platform.js +1 -1
  103. package/dist/melonjs.mjs/system/pooling.js +8 -18
  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 +66 -8
  107. package/dist/melonjs.mjs/text/bitmaptextdata.js +1 -1
  108. package/dist/melonjs.mjs/text/glyph.js +1 -1
  109. package/dist/melonjs.mjs/text/text.js +56 -86
  110. package/dist/melonjs.mjs/text/textmetrics.js +1 -1
  111. package/dist/melonjs.mjs/text/textstyle.js +4 -6
  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 +1 -1
  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 +1 -1
  119. package/dist/melonjs.mjs/utils/string.js +2 -2
  120. package/dist/melonjs.mjs/utils/utils.js +2 -4
  121. package/dist/melonjs.mjs/video/canvas/canvas_renderer.js +7 -11
  122. package/dist/melonjs.mjs/video/renderer.js +2 -13
  123. package/dist/melonjs.mjs/video/texture/atlas.js +12 -17
  124. package/dist/melonjs.mjs/video/texture/cache.js +3 -3
  125. package/dist/melonjs.mjs/video/texture/canvas_texture.js +1 -1
  126. package/dist/melonjs.mjs/video/utils/autodetect.js +1 -1
  127. package/dist/melonjs.mjs/video/video.js +2 -2
  128. package/dist/melonjs.mjs/video/webgl/buffer/vertex.js +21 -17
  129. package/dist/melonjs.mjs/video/webgl/compositors/compositor.js +235 -0
  130. package/dist/melonjs.mjs/video/webgl/compositors/primitive_compositor.js +77 -0
  131. package/dist/melonjs.mjs/video/webgl/compositors/quad_compositor.js +249 -0
  132. package/dist/melonjs.mjs/video/webgl/{webgl_compositor.js → compositors/webgl_compositor.js} +20 -205
  133. package/dist/melonjs.mjs/video/webgl/glshader.js +1 -1
  134. package/dist/melonjs.mjs/video/webgl/shaders/primitive.frag.js +1 -1
  135. package/dist/melonjs.mjs/video/webgl/shaders/primitive.vert.js +2 -2
  136. package/dist/melonjs.mjs/video/webgl/shaders/quad.frag.js +1 -1
  137. package/dist/melonjs.mjs/video/webgl/shaders/quad.vert.js +2 -2
  138. package/dist/melonjs.mjs/video/webgl/utils/attributes.js +1 -1
  139. package/dist/melonjs.mjs/video/webgl/utils/precision.js +1 -1
  140. package/dist/melonjs.mjs/video/webgl/utils/program.js +1 -1
  141. package/dist/melonjs.mjs/video/webgl/utils/string.js +1 -1
  142. package/dist/melonjs.mjs/video/webgl/utils/uniforms.js +1 -1
  143. package/dist/melonjs.mjs/video/webgl/webgl_renderer.js +139 -149
  144. package/dist/melonjs.module.js +26320 -26376
  145. package/dist/types/entity/entity.d.ts +3 -3
  146. package/dist/types/geometries/path2d.d.ts +5 -31
  147. package/dist/types/geometries/point.d.ts +2 -7
  148. package/dist/types/geometries/poly.d.ts +0 -1
  149. package/dist/types/index.d.ts +5 -3
  150. package/dist/types/loader/cache.d.ts +7 -0
  151. package/dist/types/loader/loader.d.ts +166 -181
  152. package/dist/types/loader/parser.d.ts +41 -0
  153. package/dist/types/loader/settings.d.ts +57 -0
  154. package/dist/types/particles/emitter.d.ts +4 -4
  155. package/dist/types/physics/bounds.d.ts +29 -84
  156. package/dist/types/renderable/container.d.ts +0 -11
  157. package/dist/types/renderable/renderable.d.ts +43 -31
  158. package/dist/types/renderable/sprite.d.ts +3 -3
  159. package/dist/types/renderable/ui/uitextbutton.d.ts +0 -1
  160. package/dist/types/state/state.d.ts +1 -1
  161. package/dist/types/system/pooling.d.ts +2 -2
  162. package/dist/types/text/text.d.ts +6 -20
  163. package/dist/types/text/textstyle.d.ts +1 -1
  164. package/dist/types/video/canvas/canvas_renderer.d.ts +0 -5
  165. package/dist/types/video/renderer.d.ts +1 -5
  166. package/dist/types/video/webgl/buffer/vertex.d.ts +3 -3
  167. package/dist/types/video/webgl/compositors/compositor.d.ts +107 -0
  168. package/dist/types/video/webgl/compositors/primitive_compositor.d.ts +22 -0
  169. package/dist/types/video/webgl/compositors/quad_compositor.d.ts +72 -0
  170. package/dist/types/video/webgl/compositors/webgl_compositor.d.ts +86 -0
  171. package/dist/types/video/webgl/webgl_compositor.d.ts +2 -3
  172. package/dist/types/video/webgl/webgl_renderer.d.ts +34 -28
  173. package/package.json +18 -18
  174. package/src/audio/audio.js +4 -6
  175. package/src/entity/entity.js +42 -8
  176. package/src/geometries/ellipse.js +1 -2
  177. package/src/geometries/path2d.js +19 -43
  178. package/src/geometries/point.js +0 -5
  179. package/src/geometries/poly.js +1 -4
  180. package/src/geometries/rectangle.js +12 -8
  181. package/src/index.js +7 -3
  182. package/src/input/gamepad.js +9 -15
  183. package/src/input/pointerevent.js +1 -15
  184. package/src/level/level.js +2 -2
  185. package/src/level/tiled/TMXLayer.js +0 -7
  186. package/src/level/tiled/TMXTileMap.js +7 -3
  187. package/src/level/tiled/TMXTileset.js +4 -4
  188. package/src/loader/cache.js +16 -0
  189. package/src/loader/loader.js +339 -711
  190. package/src/loader/loadingscreen.js +3 -3
  191. package/src/loader/parser.js +279 -0
  192. package/src/loader/settings.js +85 -0
  193. package/src/math/color.js +8 -7
  194. package/src/math/matrix2.js +6 -8
  195. package/src/math/matrix3.js +17 -20
  196. package/src/math/observable_vector2.js +2 -2
  197. package/src/math/observable_vector3.js +2 -3
  198. package/src/math/vector2.js +2 -2
  199. package/src/math/vector3.js +2 -3
  200. package/src/particles/emitter.js +2 -2
  201. package/src/physics/body.js +17 -13
  202. package/src/physics/bounds.js +17 -69
  203. package/src/polyfill/index.js +0 -2
  204. package/src/renderable/container.js +24 -18
  205. package/src/renderable/imagelayer.js +6 -0
  206. package/src/renderable/renderable.js +147 -104
  207. package/src/renderable/sprite.js +32 -53
  208. package/src/renderable/ui/uitextbutton.js +0 -2
  209. package/src/state/state.js +1 -1
  210. package/src/system/device.js +1 -1
  211. package/src/system/pooling.js +7 -17
  212. package/src/text/bitmaptext.js +65 -7
  213. package/src/text/text.js +55 -85
  214. package/src/text/textstyle.js +3 -5
  215. package/src/utils/string.js +1 -1
  216. package/src/utils/utils.js +1 -3
  217. package/src/video/canvas/canvas_renderer.js +5 -9
  218. package/src/video/renderer.js +0 -11
  219. package/src/video/texture/atlas.js +11 -16
  220. package/src/video/texture/cache.js +2 -2
  221. package/src/video/video.js +1 -1
  222. package/src/video/webgl/buffer/vertex.js +20 -16
  223. package/src/video/webgl/compositors/compositor.js +226 -0
  224. package/src/video/webgl/compositors/primitive_compositor.js +68 -0
  225. package/src/video/webgl/compositors/quad_compositor.js +240 -0
  226. package/src/video/webgl/shaders/primitive.vert +2 -5
  227. package/src/video/webgl/shaders/quad.vert +3 -1
  228. package/src/video/webgl/webgl_renderer.js +137 -147
  229. package/dist/melonjs.mjs/_virtual/make-built-in.js +0 -10
  230. package/dist/melonjs.mjs/_virtual/object-define-property.js +0 -10
  231. package/dist/melonjs.mjs/_virtual/object-get-own-property-descriptor.js +0 -10
  232. package/dist/melonjs.mjs/_virtual/object-get-own-property-names.js +0 -10
  233. package/dist/melonjs.mjs/_virtual/object-get-own-property-symbols.js +0 -10
  234. package/dist/melonjs.mjs/_virtual/object-property-is-enumerable.js +0 -10
  235. package/dist/melonjs.mjs/_virtual/shared.js +0 -10
  236. package/dist/melonjs.mjs/game.js +0 -29
  237. package/dist/melonjs.mjs/polyfill/console.js +0 -18
  238. package/dist/melonjs.mjs/polyfill/performance.js +0 -27
  239. package/dist/melonjs.mjs/polyfill/requestAnimationFrame.js +0 -46
  240. package/dist/melonjs.mjs/polyfill/roundrect.js +0 -242
  241. package/dist/melonjs.mjs/renderable/re_container.js +0 -1016
  242. package/dist/melonjs.mjs/video/utils/resize.js +0 -116
  243. package/src/polyfill/performance.js +0 -20
  244. package/src/polyfill/requestAnimationFrame.js +0 -39
  245. package/src/video/webgl/webgl_compositor.js +0 -486
@@ -10,20 +10,14 @@ import earcut from "earcut";
10
10
  constructor() {
11
11
  /**
12
12
  * the points defining the current path
13
- * @public
14
- * @type {Vector2d[]}
15
- * @name points
16
- * @memberof Path2D#
13
+ * @type {Point[]}
17
14
  */
18
15
  this.points = [];
19
16
 
20
17
  /**
21
18
  * space between interpolated points for quadratic and bezier curve approx. in pixels.
22
- * @public
23
19
  * @type {number}
24
- * @name arcResolution
25
20
  * @default 5
26
- * @memberof Path2D#
27
21
  */
28
22
  this.arcResolution = 5;
29
23
 
@@ -33,8 +27,6 @@ import earcut from "earcut";
33
27
 
34
28
  /**
35
29
  * begin a new path
36
- * @name beginPath
37
- * @memberof Path2D
38
30
  */
39
31
  beginPath() {
40
32
  // empty the cache and recycle all vectors
@@ -48,21 +40,17 @@ import earcut from "earcut";
48
40
  * causes the point of the pen to move back to the start of the current path.
49
41
  * It tries to draw a straight line from the current point to the start.
50
42
  * If the shape has already been closed or has only one point, this function does nothing.
51
- * @name closePath
52
- * @memberof Path2D
53
43
  */
54
44
  closePath() {
55
45
  var points = this.points;
56
46
  if (points.length > 1 && !points[points.length-1].equals(points[0])) {
57
- points.push(pool.pull("Vector2d", points[0].x, points[0].y));
47
+ points.push(pool.pull("Point", points[0].x, points[0].y));
58
48
  }
59
49
  }
60
50
 
61
51
  /**
62
52
  * triangulate the shape defined by this path into an array of triangles
63
- * @name triangulatePath
64
- * @memberof Path2D
65
- * @returns {Vector2d[]}
53
+ * @returns {Point[]}
66
54
  */
67
55
  triangulatePath() {
68
56
  var i = 0;
@@ -70,13 +58,15 @@ import earcut from "earcut";
70
58
  var vertices = this.vertices;
71
59
  var indices = earcut(points.flatMap(p => [p.x, p.y]));
72
60
 
61
+ // pre-allocate vertices if necessary
62
+ while (vertices.length < indices.length) {
63
+ vertices.push(pool.pull("Point"));
64
+ }
65
+
73
66
  // calculate all vertices
74
67
  for (i = 0; i < indices.length; i++ ) {
75
- if (typeof vertices[i] === "undefined") {
76
- // increase cache buffer if necessary
77
- vertices[i] = pool.pull("Vector2d");
78
- }
79
- vertices[i].set(points[indices[i]].x, points[indices[i]].y);
68
+ var point = points[indices[i]];
69
+ vertices[i].set(point.x, point.y);
80
70
  }
81
71
 
82
72
  // recycle overhead from a previous triangulation
@@ -90,31 +80,25 @@ import earcut from "earcut";
90
80
 
91
81
  /**
92
82
  * moves the starting point of the current path to the (x, y) coordinates.
93
- * @name moveTo
94
- * @memberof Path2D
95
83
  * @param {number} x - the x-axis (horizontal) coordinate of the point.
96
84
  * @param {number} y - the y-axis (vertical) coordinate of the point.
97
85
  */
98
86
  moveTo(x, y) {
99
- this.points.push(pool.pull("Vector2d", x, y));
87
+ this.points.push(pool.pull("Point", x, y));
100
88
  }
101
89
 
102
90
  /**
103
91
  * connects the last point in the current patch to the (x, y) coordinates with a straight line.
104
- * @name lineTo
105
- * @memberof Path2D
106
92
  * @param {number} x - the x-axis coordinate of the line's end point.
107
93
  * @param {number} y - the y-axis coordinate of the line's end point.
108
94
  */
109
95
  lineTo(x, y) {
110
- this.points.push(pool.pull("Vector2d", x, y));
96
+ this.points.push(pool.pull("Point", x, y));
111
97
  }
112
98
 
113
99
  /**
114
100
  * adds an arc to the current path which is centered at (x, y) position with the given radius,
115
101
  * starting at startAngle and ending at endAngle going in the given direction by counterclockwise (defaulting to clockwise).
116
- * @name arc
117
- * @memberof Path2D
118
102
  * @param {number} x - the horizontal coordinate of the arc's center.
119
103
  * @param {number} y - the vertical coordinate of the arc's center.
120
104
  * @param {number} radius - the arc's radius. Must be positive.
@@ -154,16 +138,14 @@ import earcut from "earcut";
154
138
 
155
139
  var angle = startAngle;
156
140
  for (var j = 0; j < nr_of_interpolation_points; j++) {
157
- points.push(pool.pull("Vector2d", x + radius * Math.cos(angle), y + radius * Math.sin(angle)));
141
+ points.push(pool.pull("Point", x + radius * Math.cos(angle), y + radius * Math.sin(angle)));
158
142
  angle += direction * dangle;
159
143
  }
160
- points.push(pool.pull("Vector2d", x + radius * Math.cos(endAngle), y + radius * Math.sin(endAngle)));
144
+ points.push(pool.pull("Point", x + radius * Math.cos(endAngle), y + radius * Math.sin(endAngle)));
161
145
  }
162
146
 
163
147
  /**
164
148
  * adds a circular arc to the path with the given control points and radius, connected to the previous point by a straight line.
165
- * @name arcTo
166
- * @memberof Path2D
167
149
  * @param {number} x1 - the x-axis coordinate of the first control point.
168
150
  * @param {number} y1 - the y-axis coordinate of the first control point.
169
151
  * @param {number} x2 - the x-axis coordinate of the second control point.
@@ -192,7 +174,7 @@ import earcut from "earcut";
192
174
  var tangent_point1 = [x1 + a[0] * adj_l, y1 + a[1] * adj_l];
193
175
  var tangent_point2 = [x1 + b[0] * adj_l, y1 + b[1] * adj_l];
194
176
 
195
- points.push(pool.pull("Vector2d", tangent_point1[0], tangent_point1[1]));
177
+ points.push(pool.pull("Point", tangent_point1[0], tangent_point1[1]));
196
178
 
197
179
  var bisec = [(a[0] + b[0]) / 2.0, (a[1] + b[1]) / 2.0];
198
180
  var bisec_l = Math.sqrt(Math.pow(bisec[0], 2) + Math.pow(bisec[1], 2));
@@ -210,8 +192,6 @@ import earcut from "earcut";
210
192
  /**
211
193
  * adds an elliptical arc to the path which is centered at (x, y) position with the radii radiusX and radiusY
212
194
  * starting at startAngle and ending at endAngle going in the given direction by counterclockwise.
213
- * @name ellipse
214
- * @memberof Path2D
215
195
  * @param {number} x - the x-axis (horizontal) coordinate of the ellipse's center.
216
196
  * @param {number} y - the y-axis (vertical) coordinate of the ellipse's center.
217
197
  * @param {number} radiusX - the ellipse's major-axis radius. Must be non-negative.
@@ -259,18 +239,13 @@ import earcut from "earcut";
259
239
  var _y1 = radiusY * Math.sin(angle);
260
240
  var _x2 = x + _x1 * cos_rotation - _y1 * sin_rotation;
261
241
  var _y2 = y + _x1 * sin_rotation + _y1 * cos_rotation;
262
- points.push(pool.pull("Vector2d", _x2, _y2));
242
+ points.push(pool.pull("Point", _x2, _y2));
263
243
  angle += direction * dangle;
264
244
  }
265
- //var x1 = radiusX * Math.cos(endAngle);
266
- //var y1 = radiusY * Math.sin(endAngle);
267
- //points.push(pool.pull("Vector2d", x + x1 * cos_rotation - y1 * sin_rotation, y + x1 * sin_rotation + y1 * cos_rotation));
268
245
  }
269
246
 
270
247
  /**
271
248
  * creates a path for a rectangle at position (x, y) with a size that is determined by width and height.
272
- * @name rect
273
- * @memberof Path2D
274
249
  * @param {number} x - the x-axis coordinate of the rectangle's starting point.
275
250
  * @param {number} y - the y-axis coordinate of the rectangle's starting point.
276
251
  * @param {number} width - the rectangle's width. Positive values are to the right, and negative to the left.
@@ -279,15 +254,16 @@ import earcut from "earcut";
279
254
  rect(x, y, width, height) {
280
255
  this.moveTo(x, y);
281
256
  this.lineTo(x + width, y);
257
+ this.moveTo(x + width, y);
282
258
  this.lineTo(x + width, y + height);
259
+ this.moveTo(x + width, y + height);
283
260
  this.lineTo(x, y + height);
261
+ this.moveTo(x, y + height);
284
262
  this.lineTo(x, y);
285
263
  }
286
264
 
287
265
  /**
288
266
  * adds an rounded rectangle to the current path.
289
- * @name roundRect
290
- * @memberof Path2D
291
267
  * @param {number} x - the x-axis coordinate of the rectangle's starting point.
292
268
  * @param {number} y - the y-axis coordinate of the rectangle's starting point.
293
269
  * @param {number} width - the rectangle's width. Positive values are to the right, and negative to the left.
@@ -6,7 +6,6 @@
6
6
  constructor(x = 0, y = 0) {
7
7
  /**
8
8
  * the position of the point on the horizontal axis
9
- * @public
10
9
  * @type {Number}
11
10
  * @default 0
12
11
  */
@@ -14,7 +13,6 @@
14
13
 
15
14
  /**
16
15
  * the position of the point on the vertical axis
17
- * @public
18
16
  * @type {Number}
19
17
  * @default 0
20
18
  */
@@ -48,8 +46,6 @@
48
46
  */
49
47
  /**
50
48
  * return true if this point is equal to the given values
51
- * @name equals
52
- * @memberof Point
53
49
  * @param {number} x
54
50
  * @param {number} y
55
51
  * @returns {boolean}
@@ -70,7 +66,6 @@
70
66
 
71
67
  /**
72
68
  * clone this Point
73
- * @name clone
74
69
  * @returns {Point} new Point
75
70
  */
76
71
  clone() {
@@ -200,9 +200,7 @@ import pool from "./../system/pooling.js";
200
200
  * @param {number} [y=x]
201
201
  * @returns {Polygon} Reference to this object for method chaining
202
202
  */
203
- scale(x, y) {
204
- y = typeof (y) !== "undefined" ? y : x;
205
-
203
+ scale(x, y = x) {
206
204
  var points = this.points;
207
205
  var len = points.length;
208
206
  for (var i = 0; i < len; i++) {
@@ -458,7 +456,6 @@ import pool from "./../system/pooling.js";
458
456
 
459
457
  /**
460
458
  * update the bounding box for this shape.
461
- * @ignore
462
459
  * @name updateBounds
463
460
  * @memberof Polygon
464
461
  * @returns {Bounds} this shape bounding box Rectangle object
@@ -77,7 +77,7 @@ import Polygon from "./poly.js";
77
77
  */
78
78
  get right() {
79
79
  var w = this.width;
80
- return (this.pos.x + w) || w;
80
+ return (this.left + w) || w;
81
81
  }
82
82
 
83
83
  /**
@@ -100,7 +100,7 @@ import Polygon from "./poly.js";
100
100
  */
101
101
  get bottom() {
102
102
  var h = this.height;
103
- return (this.pos.y + h) || h;
103
+ return (this.top + h) || h;
104
104
  }
105
105
 
106
106
  /**
@@ -144,13 +144,15 @@ import Polygon from "./poly.js";
144
144
  */
145
145
  get centerX() {
146
146
  if (isFinite(this.width)) {
147
- return this.pos.x + (this.width / 2);
147
+ return this.left + (this.width / 2);
148
148
  } else {
149
149
  return this.width;
150
150
  }
151
151
  }
152
152
  set centerX (value) {
153
153
  this.pos.x = value - (this.width / 2);
154
+ this.recalc();
155
+ this.updateBounds();
154
156
  }
155
157
 
156
158
  /**
@@ -162,13 +164,15 @@ import Polygon from "./poly.js";
162
164
  */
163
165
  get centerY() {
164
166
  if (isFinite(this.height)) {
165
- return this.pos.y + (this.height / 2);
167
+ return this.top + (this.height / 2);
166
168
  } else {
167
169
  return this.height;
168
170
  }
169
171
  }
170
172
  set centerY(value) {
171
173
  this.pos.y = value - (this.height / 2);
174
+ this.recalc();
175
+ this.updateBounds();
172
176
  }
173
177
 
174
178
  /**
@@ -220,7 +224,7 @@ import Polygon from "./poly.js";
220
224
  * @returns {Rect} new rectangle
221
225
  */
222
226
  clone() {
223
- return new Rect(this.pos.x, this.pos.y, this.width, this.height);
227
+ return new Rect(this.left, this.top, this.width, this.height);
224
228
  }
225
229
 
226
230
  /**
@@ -231,7 +235,7 @@ import Polygon from "./poly.js";
231
235
  * @returns {Rect} new rectangle
232
236
  */
233
237
  copy(rect) {
234
- return this.setShape(rect.pos.x, rect.pos.y, rect.width, rect.height);
238
+ return this.setShape(rect.left, rect.top, rect.width, rect.height);
235
239
  }
236
240
 
237
241
  /**
@@ -348,7 +352,7 @@ import Polygon from "./poly.js";
348
352
  * @returns {boolean} false if all coordinates are positive or negative Infinity or NaN; otherwise, true.
349
353
  */
350
354
  isFinite() {
351
- return (isFinite(this.pos.x) && isFinite(this.pos.y) && isFinite(this.width) && isFinite(this.height));
355
+ return (isFinite(this.left) && isFinite(this.top) && isFinite(this.width) && isFinite(this.height));
352
356
  }
353
357
 
354
358
  /**
@@ -359,7 +363,7 @@ import Polygon from "./poly.js";
359
363
  */
360
364
  toPolygon() {
361
365
  return pool.pull("Polygon",
362
- this.pos.x, this.pos.y, this.points
366
+ this.left, this.top, this.points
363
367
  );
364
368
  }
365
369
  }
package/src/index.js CHANGED
@@ -20,7 +20,9 @@ import Body from "./physics/body.js";
20
20
  import Bounds from "./physics/bounds.js";
21
21
  import Tween from "./tweens/tween.js";
22
22
  import GLShader from "./video/webgl/glshader.js";
23
- import WebGLCompositor from "./video/webgl/webgl_compositor.js";
23
+ import Compositor from "./video/webgl/compositors/compositor.js";
24
+ import PrimitiveCompositor from "./video/webgl/compositors/primitive_compositor.js";
25
+ import QuadCompositor from "./video/webgl/compositors/quad_compositor.js";
24
26
  import Renderer from "./video/renderer.js";
25
27
  import WebGLRenderer from "./video/webgl/webgl_renderer.js";
26
28
  import CanvasRenderer from "./video/canvas/canvas_renderer.js";
@@ -67,7 +69,7 @@ import * as audio from "./audio/audio.js";
67
69
  import collision from "./physics/collision.js";
68
70
  import * as event from "./system/event.js";
69
71
  import * as device from "./system/device.js";
70
- import loader from "./loader/loader.js";
72
+ import * as loader from "./loader/loader.js";
71
73
  import * as Math from "./math/math.js";
72
74
  import utils from "./utils/utils.js";
73
75
  import * as input from "./input/input.js";
@@ -127,7 +129,9 @@ export {
127
129
  Tween,
128
130
  QuadTree,
129
131
  GLShader,
130
- WebGLCompositor,
132
+ Compositor,
133
+ PrimitiveCompositor,
134
+ QuadCompositor,
131
135
  Renderer,
132
136
  WebGLRenderer,
133
137
  CanvasRenderer,
@@ -55,23 +55,17 @@ var leadingZeroRE = /^0+/;
55
55
  * @ignore
56
56
  */
57
57
  function addMapping(id, mapping) {
58
- var expanded_id = id.replace(vendorProductRE, (_, a, b) => {
59
- return (
60
- "000".slice(a.length - 1) + a + "-" +
61
- "000".slice(b.length - 1) + b + "-"
62
- );
63
- });
64
- var sparse_id = id.replace(vendorProductRE, (_, a, b) => {
65
- return (
66
- a.replace(leadingZeroRE, "") + "-" +
67
- b.replace(leadingZeroRE, "") + "-"
68
- );
69
- });
58
+ var expanded_id = id.replace(vendorProductRE, (_, a, b) =>
59
+ "000".slice(a.length - 1) + a + "-" +
60
+ "000".slice(b.length - 1) + b + "-"
61
+ );
62
+ var sparse_id = id.replace(vendorProductRE, (_, a, b) =>
63
+ a.replace(leadingZeroRE, "") + "-" +
64
+ b.replace(leadingZeroRE, "") + "-"
65
+ );
70
66
 
71
67
  // Normalize optional parameters
72
- mapping.analog = mapping.analog || mapping.buttons.map(() => {
73
- return -1;
74
- });
68
+ mapping.analog = mapping.analog || mapping.buttons.map(() => -1);
75
69
  mapping.normalize_fn = mapping.normalize_fn || function (value) { return value; };
76
70
 
77
71
  remap.set(expanded_id, mapping);
@@ -315,21 +315,7 @@ function dispatchEvent(normalizedEvents) {
315
315
  pointer.gameLocalY = pointer.gameY - parentBounds.y;
316
316
  }
317
317
 
318
- var gameX = pointer.gameX;
319
- var gameY = pointer.gameY;
320
-
321
- // apply inverse transformation for renderable
322
- if (typeof region.currentTransform !== "undefined") {
323
- if (!region.currentTransform.isIdentity()) {
324
- var invV = region.currentTransform.applyInverse(
325
- pool.pull("Vector2d", gameX, gameY)
326
- );
327
- gameX = invV.x;
328
- gameY = invV.y;
329
- pool.push(invV);
330
- }
331
- }
332
- eventInBounds = bounds.contains(gameX, gameY);
318
+ eventInBounds = bounds.contains(pointer.gameX, pointer.gameY);
333
319
 
334
320
  switch (pointer.type) {
335
321
  case POINTER_MOVE[0]:
@@ -1,7 +1,7 @@
1
1
  import utils from "./../utils/utils.js";
2
2
  import * as event from "./../system/event.js";
3
3
  import state from "./../state/state.js";
4
- import loader from "./../loader/loader.js";
4
+ import { getTMX } from "./../loader/loader.js";
5
5
  import { game } from "../index.js";
6
6
  import TMXTileMap from "./tiled/TMXTileMap.js";
7
7
 
@@ -95,7 +95,7 @@ var level = {
95
95
  // just load the level with the XML stuff
96
96
  if (levels[levelId] == null) {
97
97
  //console.log("loading "+ levelId);
98
- levels[levelId] = new TMXTileMap(levelId, loader.getTMX(levelId));
98
+ levels[levelId] = new TMXTileMap(levelId, getTMX(levelId));
99
99
  // level index
100
100
  levelIdx.push(levelId);
101
101
  }
@@ -233,7 +233,6 @@ function preRenderLayer(layer, renderer) {
233
233
 
234
234
  }
235
235
 
236
-
237
236
  // called when the layer is added to the game world or a container
238
237
  onActivateEvent() {
239
238
 
@@ -257,10 +256,6 @@ function preRenderLayer(layer, renderer) {
257
256
  this.preRender = false;
258
257
  }
259
258
 
260
- // Resize the bounding rect
261
- this.getBounds().addBounds(this.getRenderer().getBounds(), true);
262
- this.getBounds().shift(this.pos);
263
-
264
259
  // if pre-rendering method is use, create an offline canvas/renderer
265
260
  if ((this.preRender === true) && (!this.canvasRenderer)) {
266
261
  this.canvasRenderer = new CanvasRenderer({
@@ -300,7 +295,6 @@ function preRenderLayer(layer, renderer) {
300
295
  return this.renderer;
301
296
  }
302
297
 
303
-
304
298
  /**
305
299
  * Return the TileId of the Tile at the specified position
306
300
  * @param {number} x - X coordinate (in world/pixels coordinates)
@@ -415,7 +409,6 @@ function preRenderLayer(layer, renderer) {
415
409
  }
416
410
  return result;
417
411
  }
418
-
419
412
  return false;
420
413
  }
421
414
 
@@ -195,11 +195,15 @@ function readObjectGroup(map, data, z) {
195
195
  // background color
196
196
  this.backgroundcolor = data.backgroundcolor;
197
197
 
198
- // deprecation warning if map tiled version is older than 1.5
199
- if (utils.checkVersion(this.version, "1.5") < 0) {
200
- warning("("+this.name+") Tiled Map format version 1.4 and below", "Tiled 1.5 or higher", "10.4.4");
198
+ // if version is undefined or empty it usually means the map was not created with Tiled
199
+ if (this.version !== "undefined" && this.version !== "") {
200
+ // deprecation warning if map tiled version is older than 1.5
201
+ if (utils.checkVersion(this.version, "1.5") < 0) {
202
+ warning("("+this.name+") Tiled Map format version 1.4 and below", "format 1.5 or higher", "10.4.4");
203
+ }
201
204
  }
202
205
 
206
+
203
207
  // set additional map properties (if any)
204
208
  applyTMXProperties(this, data);
205
209
 
@@ -2,7 +2,7 @@ import Vector2d from "./../../math/vector2.js";
2
2
  import { renderer } from "./../../video/video.js";
3
3
  import * as fileUtil from "./../../utils/file.js";
4
4
  import timer from "./../../system/timer.js";
5
- import loader from "./../../loader/loader.js";
5
+ import { getTMX, getImage } from "./../../loader/loader.js";
6
6
 
7
7
  /**
8
8
  * @classdesc
@@ -30,7 +30,7 @@ import loader from "./../../loader/loader.js";
30
30
  var ext = fileUtil.getExtension(src);
31
31
  if (ext === "tsx" || ext === "json") {
32
32
  // load the external tileset (TSX/JSON)
33
- tileset = loader.getTMX(fileUtil.getBasename(src));
33
+ tileset = getTMX(fileUtil.getBasename(src));
34
34
  if (!tileset) {
35
35
  throw new Error(src + " external TSX/JSON tileset not found");
36
36
  }
@@ -101,7 +101,7 @@ import loader from "./../../loader/loader.js";
101
101
  }
102
102
  }
103
103
  if ("image" in tiles[i]) {
104
- var image = loader.getImage(tiles[i].image);
104
+ var image = getImage(tiles[i].image);
105
105
  if (!image) {
106
106
  throw new Error("melonJS: '" + tiles[i].image + "' file for tile '" + (+i + this.firstgid) + "' not found!");
107
107
  }
@@ -132,7 +132,7 @@ import loader from "./../../loader/loader.js";
132
132
  if (this.isCollection === false) {
133
133
 
134
134
  // get the global tileset texture
135
- this.image = loader.getImage(tileset.image);
135
+ this.image = getImage(tileset.image);
136
136
 
137
137
  if (!this.image) {
138
138
  throw new Error("melonJS: '" + tileset.image + "' file for tileset '" + this.name + "' not found!");
@@ -0,0 +1,16 @@
1
+
2
+ /**
3
+ * where all preloaded content is cached
4
+ */
5
+
6
+ // contains all the images loaded
7
+ export let imgList = {};
8
+
9
+ // contains all the TMX loaded
10
+ export let tmxList = {};
11
+
12
+ // contains all the binary files loaded
13
+ export let binList = {};
14
+
15
+ // contains all the JSON files
16
+ export let jsonList = {};