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
@@ -1,6 +1,6 @@
1
1
  import Color from "./../math/color.js";
2
2
  import pool from "./../system/pooling.js";
3
- import loader from "./../loader/loader.js";
3
+ import { getImage, getBinary } from "./../loader/loader.js";
4
4
  import Renderable from "./../renderable/renderable.js";
5
5
  import TextMetrics from "./textmetrics.js";
6
6
 
@@ -95,7 +95,7 @@ import TextMetrics from "./textmetrics.js";
95
95
  * font image
96
96
  * @private
97
97
  */
98
- this.fontImage = (typeof settings.font === "object") ? settings.font : loader.getImage(settings.font);
98
+ this.fontImage = (typeof settings.font === "object") ? settings.font : getImage(settings.font);
99
99
 
100
100
  if (typeof settings.fontData !== "string") {
101
101
  /**
@@ -103,11 +103,11 @@ import TextMetrics from "./textmetrics.js";
103
103
  * @private
104
104
  */
105
105
  // use settings.font to retreive the data from the loader
106
- this.fontData = pool.pull("BitmapTextData", loader.getBinary(settings.font));
106
+ this.fontData = pool.pull("BitmapTextData", getBinary(settings.font));
107
107
  } else {
108
108
  this.fontData = pool.pull("BitmapTextData",
109
109
  // if starting/includes "info face" the whole data string was passed as parameter
110
- (settings.fontData.includes("info face")) ? settings.fontData : loader.getBinary(settings.fontData)
110
+ (settings.fontData.includes("info face")) ? settings.fontData : getBinary(settings.fontData)
111
111
  );
112
112
  }
113
113
 
@@ -176,11 +176,70 @@ import TextMetrics from "./textmetrics.js";
176
176
  this._text = this.metrics.wordWrap(this._text, this.wordWrapWidth);
177
177
  }
178
178
 
179
- this.getBounds().addBounds(this.metrics.measureText(this._text), true);
179
+ this.updateBounds();
180
180
 
181
181
  return this;
182
182
  }
183
183
 
184
+ /**
185
+ * update the bounding box for this Bitmap Text.
186
+ * @param {boolean} [absolute=true] - update the bounds size and position in (world) absolute coordinates
187
+ * @returns {Bounds} this Bitmap Text bounding box Rectangle object
188
+ */
189
+ updateBounds(absolute = true) {
190
+ var bounds = this.getBounds();
191
+
192
+ bounds.clear();
193
+
194
+ if (typeof this.metrics !== "undefined") {
195
+ var ax, ay;
196
+
197
+ bounds.addBounds(this.metrics.measureText(this._text));
198
+
199
+ switch (this.textAlign) {
200
+ case "right":
201
+ ax = this.metrics.width * 1.0;
202
+ break;
203
+
204
+ case "center":
205
+ ax = this.metrics.width * 0.5;
206
+ break;
207
+
208
+ default :
209
+ ax = this.metrics.width * 0.0;
210
+ break;
211
+ }
212
+
213
+ // adjust y pos based on alignment value
214
+ switch (this.textBaseline) {
215
+ case "middle":
216
+ ay = this.metrics.height * 0.5;
217
+ break;
218
+
219
+ case "ideographic":
220
+ case "alphabetic":
221
+ case "bottom":
222
+ ay = this.metrics.height * 1.0;
223
+ break;
224
+
225
+ default :
226
+ ay = this.metrics.height * 0.0;
227
+ break;
228
+ }
229
+
230
+ // translate the bounds accordingly
231
+ bounds.translate(ax, ay);
232
+ }
233
+
234
+ if (absolute === true) {
235
+ if (typeof this.ancestor !== "undefined" && typeof this.ancestor.addChild === "function" && this.floating !== true) {
236
+ bounds.translate(this.ancestor.getAbsolutePosition());
237
+ }
238
+ }
239
+
240
+ return bounds;
241
+ }
242
+
184
243
  /**
185
244
  * defines the color used to tint the bitmap text
186
245
  * @public
@@ -207,9 +266,8 @@ import TextMetrics from "./textmetrics.js";
207
266
  resize(scale) {
208
267
  this.fontScale.set(scale, scale);
209
268
 
210
- this.getBounds().addBounds(this.metrics.measureText(this._text), true);
269
+ this.updateBounds();
211
270
 
212
- // clear the cache text to recalculate bounds
213
271
  this.isDirty = true;
214
272
 
215
273
  return this;
package/src/text/text.js CHANGED
@@ -1,5 +1,4 @@
1
1
  import Color from "./../math/color.js";
2
- import WebGLRenderer from "./../video/webgl/webgl_renderer.js";
3
2
  import { renderer as globalRenderer } from "./../video/video.js";
4
3
  import pool from "./../system/pooling.js";
5
4
  import Renderable from "./../renderable/renderable.js";
@@ -19,18 +18,6 @@ import TextMetrics from "./textmetrics.js";
19
18
  const runits = ["ex", "em", "pt", "px"];
20
19
  const toPX = [12, 24, 0.75, 1];
21
20
 
22
- // return a valid 2d context for Text rendering/styling
23
- var getContext2d = function (renderer, text) {
24
- if (text.offScreenCanvas === true) {
25
- return text.canvasTexture.context;
26
- } else {
27
- if (typeof renderer === "undefined") {
28
- renderer = globalRenderer;
29
- }
30
- return renderer.getFontContext();
31
- }
32
- };
33
-
34
21
  /**
35
22
  * @classdesc
36
23
  * a generic system font object.
@@ -45,12 +32,11 @@ var getContext2d = function (renderer, text) {
45
32
  * @param {number|string} settings.size - size, or size + suffix (px, em, pt)
46
33
  * @param {Color|string} [settings.fillStyle="#000000"] - a CSS color value
47
34
  * @param {Color|string} [settings.strokeStyle="#000000"] - a CSS color value
48
- * @param {number} [settings.lineWidth=1] - line width, in pixels, when drawing stroke
35
+ * @param {number} [settings.lineWidth=0] - line width, in pixels, when drawing stroke
49
36
  * @param {string} [settings.textAlign="left"] - horizontal text alignment
50
37
  * @param {string} [settings.textBaseline="top"] - the text baseline
51
38
  * @param {number} [settings.lineHeight=1.0] - line spacing height
52
39
  * @param {Vector2d} [settings.anchorPoint={x:0.0, y:0.0}] - anchor point to draw the text at
53
- * @param {boolean} [settings.offScreenCanvas=false] - whether to draw the font to an individual "cache" texture first
54
40
  * @param {number} [settings.wordWrapWidth] - the maximum length in CSS pixel for a single segment of text
55
41
  * @param {(string|string[])} [settings.text=""] - a string, or an array of strings
56
42
  * @example
@@ -105,9 +91,9 @@ var getContext2d = function (renderer, text) {
105
91
  * sets the current line width, in pixels, when drawing stroke
106
92
  * @public
107
93
  * @type {number}
108
- * @default 1
94
+ * @default 0
109
95
  */
110
- this.lineWidth = settings.lineWidth || 1;
96
+ this.lineWidth = settings.lineWidth || 0;
111
97
 
112
98
  /**
113
99
  * Set the default text alignment (or justification),<br>
@@ -136,16 +122,6 @@ var getContext2d = function (renderer, text) {
136
122
  */
137
123
  this.lineHeight = settings.lineHeight || 1.0;
138
124
 
139
- /**
140
- * whether to draw the font to a indidividual offscreen canvas texture first <br>
141
- * Note: this will improve performances when using WebGL, but will impact
142
- * memory consumption as every text element will have its own canvas texture
143
- * @public
144
- * @type {boolean}
145
- * @default false
146
- */
147
- this.offScreenCanvas = false;
148
-
149
125
  /**
150
126
  * the maximum length in CSS pixel for a single segment of text.
151
127
  * (use -1 to disable word wrapping)
@@ -192,10 +168,8 @@ var getContext2d = function (renderer, text) {
192
168
  this.italic();
193
169
  }
194
170
 
195
- if (settings.offScreenCanvas === true) {
196
- this.offScreenCanvas = true;
197
- this.canvasTexture = pool.pull("CanvasTexture", 2, 2, { offscreenCanvas: true });
198
- }
171
+ // the canvas Texture used to render this text
172
+ this.canvasTexture = pool.pull("CanvasTexture", 2, 2, { offscreenCanvas: true });
199
173
 
200
174
  // instance to text metrics functions
201
175
  this.metrics = new TextMetrics(this);
@@ -284,38 +258,38 @@ var getContext2d = function (renderer, text) {
284
258
 
285
259
  // word wrap if necessary
286
260
  if (this._text.length > 0 && this.wordWrapWidth > 0) {
287
- this._text = this.metrics.wordWrap(this._text, this.wordWrapWidth, getContext2d(globalRenderer, this));
261
+ this._text = this.metrics.wordWrap(this._text, this.wordWrapWidth, this.canvasTexture.context);
288
262
  }
289
263
 
290
264
  // calculcate the text size and update the bounds accordingly
291
- bounds.addBounds(this.metrics.measureText(this._text, getContext2d(globalRenderer, this)), true);
265
+ bounds.addBounds(this.metrics.measureText(this._text, this.canvasTexture.context), true);
292
266
 
293
267
  // update the offScreenCanvas texture if required
294
- if (this.offScreenCanvas === true) {
295
- var width = Math.ceil(this.metrics.width),
296
- height = Math.ceil(this.metrics.height);
297
-
298
- if (globalRenderer instanceof WebGLRenderer) {
299
- // invalidate the previous corresponding texture so that it can reuploaded once changed
300
- this.glTextureUnit = globalRenderer.cache.getUnit(globalRenderer.cache.get(this.canvasTexture.canvas));
301
- globalRenderer.currentCompositor.unbindTexture2D(null, this.glTextureUnit);
302
-
303
- if (globalRenderer.WebGLVersion === 1) {
304
- // round size to next Pow2
305
- width = nextPowerOfTwo(this.metrics.width);
306
- height = nextPowerOfTwo(this.metrics.height);
307
- }
308
- }
309
-
310
- // resize the cache canvas if necessary
311
- if (this.canvasTexture.width < width || this.canvasTexture.height < height) {
312
- this.canvasTexture.resize(width, height);
268
+ var width = Math.ceil(this.metrics.width),
269
+ height = Math.ceil(this.metrics.height);
270
+
271
+ if (typeof globalRenderer.gl !== "undefined") {
272
+ // make sure the right compositor is active
273
+ globalRenderer.setCompositor("quad");
274
+ // invalidate the previous corresponding texture so that it can reuploaded once changed
275
+ this.glTextureUnit = globalRenderer.cache.getUnit(globalRenderer.cache.get(this.canvasTexture.canvas));
276
+ globalRenderer.currentCompositor.unbindTexture2D(null, this.glTextureUnit);
277
+
278
+ if (globalRenderer.WebGLVersion === 1) {
279
+ // round size to next Pow2
280
+ width = nextPowerOfTwo(this.metrics.width);
281
+ height = nextPowerOfTwo(this.metrics.height);
313
282
  }
283
+ }
314
284
 
315
- this.canvasTexture.clear();
316
- this._drawFont(this.canvasTexture.context, this._text, this.pos.x - this.metrics.x, this.pos.y - this.metrics.y, false);
285
+ // resize the cache canvas if necessary
286
+ if (this.canvasTexture.width < width || this.canvasTexture.height < height) {
287
+ this.canvasTexture.resize(width, height);
317
288
  }
318
289
 
290
+ this.canvasTexture.clear();
291
+ this._drawFont(this.canvasTexture.context, this._text, this.pos.x - this.metrics.x, this.pos.y - this.metrics.y);
292
+
319
293
  this.isDirty = true;
320
294
 
321
295
  return this;
@@ -328,7 +302,7 @@ var getContext2d = function (renderer, text) {
328
302
  * @returns {TextMetrics} a TextMetrics object defining the dimensions of the given piece of text
329
303
  */
330
304
  measureText(renderer, text = this._text) {
331
- return this.metrics.measureText(text, getContext2d(renderer, this));
305
+ return this.metrics.measureText(text, this.canvasTexture.context);
332
306
  }
333
307
 
334
308
 
@@ -338,9 +312,8 @@ var getContext2d = function (renderer, text) {
338
312
  * @param {string} [text]
339
313
  * @param {number} [x]
340
314
  * @param {number} [y]
341
- * @param {boolean} [stroke=false] - draw stroke the the text if true
342
315
  */
343
- draw(renderer, text, x = this.pos.x, y = this.pos.y, stroke = false) {
316
+ draw(renderer, text, x = this.pos.x, y = this.pos.y) {
344
317
  // "hacky patch" for backward compatibilty
345
318
  if (typeof this.ancestor === "undefined") {
346
319
 
@@ -354,21 +327,18 @@ var getContext2d = function (renderer, text) {
354
327
  // update text cache
355
328
  this.setText(text);
356
329
 
357
- x = this.metrics.x;
358
- y = this.metrics.y;
359
-
360
330
  // save the previous context
361
331
  renderer.save();
362
332
 
363
333
  // apply the defined alpha value
364
334
  renderer.setGlobalAlpha(renderer.globalAlpha() * this.getOpacity());
365
335
 
366
- } else {
367
- // added directly to an object container
368
- x = this.pos.x;
369
- y = this.pos.y;
370
336
  }
371
337
 
338
+ // adjust x,y position based on the bounding box
339
+ x = this.metrics.x;
340
+ y = this.metrics.y;
341
+
372
342
  // clamp to pixel grid if required
373
343
  if (renderer.settings.subPixel === false) {
374
344
  x = ~~x;
@@ -376,12 +346,7 @@ var getContext2d = function (renderer, text) {
376
346
  }
377
347
 
378
348
  // draw the text
379
- if (this.offScreenCanvas === true) {
380
- renderer.drawImage(this.canvasTexture.canvas, x, y);
381
- } else {
382
- renderer.drawFont(this._drawFont(renderer.getFontContext(), this._text, x, y, stroke));
383
- }
384
-
349
+ renderer.drawImage(this.canvasTexture.canvas, x, y);
385
350
 
386
351
  // for backward compatibilty
387
352
  if (typeof this.ancestor === "undefined") {
@@ -391,28 +356,33 @@ var getContext2d = function (renderer, text) {
391
356
  }
392
357
 
393
358
  /**
394
- * draw a stroke text at the specified coord, as defined <br>
395
- * by the `lineWidth` and `fillStroke` properties. <br>
396
- * Note : using drawStroke is not recommended for performance reasons
359
+ * draw a stroke text at the specified coord, as defined by the `lineWidth` and `fillStroke` properties.
360
+ * @deprecated since 15.0.0
397
361
  * @param {CanvasRenderer|WebGLRenderer} renderer - Reference to the destination renderer instance
398
362
  * @param {string} text
399
363
  * @param {number} x
400
364
  * @param {number} y
401
365
  */
402
366
  drawStroke(renderer, text, x, y) {
403
- this.draw(renderer, text, x, y, true);
367
+ this.draw(renderer, text, x, y);
404
368
  }
405
369
 
406
370
  /**
407
371
  * @ignore
408
372
  */
409
- _drawFont(context, text, x, y, stroke = false) {
410
- setContextStyle(context, this, stroke);
373
+ _drawFont(context, text, x, y) {
374
+ setContextStyle(context, this);
411
375
 
412
376
  for (var i = 0; i < text.length; i++) {
413
377
  var string = text[i].trimEnd();
414
378
  // draw the string
415
- context[stroke ? "strokeText" : "fillText"](string, x, y);
379
+ if (this.fillStyle.alpha > 0) {
380
+ context.fillText(string, x, y);
381
+ }
382
+ // stroke the text
383
+ if (this.lineWidth > 0 && this.strokeStyle.alpha > 0) {
384
+ context.strokeText(string, x, y);
385
+ }
416
386
  // add leading space
417
387
  y += this.metrics.lineHeight();
418
388
  }
@@ -424,15 +394,15 @@ var getContext2d = function (renderer, text) {
424
394
  * @ignore
425
395
  */
426
396
  destroy() {
427
- if (this.offScreenCanvas === true) {
428
- if (globalRenderer instanceof WebGLRenderer) {
429
- globalRenderer.currentCompositor.deleteTexture2D(globalRenderer.currentCompositor.getTexture2D(this.glTextureUnit));
430
- this.glTextureUnit = undefined;
431
- }
432
- globalRenderer.cache.delete(this.canvasTexture.canvas);
433
- pool.push(this.canvasTexture);
434
- this.canvasTexture = undefined;
397
+ if (typeof globalRenderer.gl !== "undefined") {
398
+ // make sure the right compositor is active
399
+ globalRenderer.setCompositor("quad");
400
+ globalRenderer.currentCompositor.deleteTexture2D(globalRenderer.currentCompositor.getTexture2D(this.glTextureUnit));
401
+ this.glTextureUnit = undefined;
435
402
  }
403
+ globalRenderer.cache.delete(this.canvasTexture.canvas);
404
+ pool.push(this.canvasTexture);
405
+ this.canvasTexture = undefined;
436
406
  pool.push(this.fillStyle);
437
407
  pool.push(this.strokeStyle);
438
408
  this.fillStyle = this.strokeStyle = undefined;
@@ -2,13 +2,11 @@
2
2
  * apply the current text style to the given context
3
3
  * @ignore
4
4
  */
5
- export default function setContextStyle(context, style, stroke = false) {
5
+ export default function setContextStyle(context, style) {
6
6
  context.font = style.font;
7
7
  context.fillStyle = style.fillStyle.toRGBA();
8
- if (stroke === true) {
9
- context.strokeStyle = style.strokeStyle.toRGBA();
10
- context.lineWidth = style.lineWidth;
11
- }
8
+ context.strokeStyle = style.strokeStyle.toRGBA();
9
+ context.lineWidth = style.lineWidth;
12
10
  context.textAlign = style.textAlign;
13
11
  context.textBaseline = style.textBaseline;
14
12
  }
@@ -27,7 +27,7 @@ export function isNumeric(str) {
27
27
  if (typeof str === "string") {
28
28
  str = str.trim();
29
29
  }
30
- return !isNaN(str) && /[+-]?([0-9]*[.])?[0-9]+/.test(str);
30
+ return !isNaN(str) && /^[+-]?(\d+(\.\d+)?|\.\d+)$/.test(str);
31
31
  }
32
32
 
33
33
  /**
@@ -99,9 +99,7 @@ var utils = {
99
99
  }
100
100
 
101
101
  // parse the url
102
- url.slice(1).split("&").filter((value) => {
103
- return (value !== "");
104
- }).forEach((value) => {
102
+ url.slice(1).split("&").filter((value) => value !== "").forEach((value) => {
105
103
  var kv = value.split("=");
106
104
  var k = kv.shift();
107
105
  var v = kv.join("=");
@@ -59,6 +59,11 @@ import * as event from "./../../system/event.js";
59
59
  this.isContextValid = true;
60
60
  event.emit(event.ONCONTEXT_RESTORED, this);
61
61
  }, false );
62
+
63
+ // reset the renderer on game reset
64
+ event.on(event.GAME_RESET, () => {
65
+ this.reset();
66
+ });
62
67
  }
63
68
 
64
69
  /**
@@ -534,15 +539,6 @@ import * as event from "./../../system/event.js";
534
539
  this.strokePoint(x, y);
535
540
  }
536
541
 
537
- /**
538
- * return a reference to the font 2d Context
539
- * @ignore
540
- */
541
- getFontContext() {
542
- // in canvas mode we can directly use the 2d context
543
- return this.getContext();
544
- }
545
-
546
542
  /**
547
543
  * save the canvas context
548
544
  * @name save
@@ -115,11 +115,6 @@ import Point from "../geometries/point.js";
115
115
 
116
116
  // default uvOffset
117
117
  this.uvOffset = 0;
118
-
119
- // reset the renderer on game reset
120
- event.on(event.GAME_RESET, () => {
121
- this.reset();
122
- });
123
118
  }
124
119
 
125
120
  /**
@@ -412,10 +407,4 @@ import Point from "../geometries/point.js";
412
407
  // reset to default
413
408
  this.currentTint.setColor(255, 255, 255, 1.0);
414
409
  }
415
-
416
- /**
417
- * @ignore
418
- */
419
- drawFont(/*bounds*/) {}
420
-
421
410
  }
@@ -1,10 +1,8 @@
1
1
  import Vector2d from "./../../math/vector2.js";
2
- import WebGLRenderer from "./../webgl/webgl_renderer.js";
3
- import TextureCache from "./../texture/cache.js";
4
2
  import Sprite from "./../../renderable/sprite.js";
5
3
  import { renderer } from "./../video.js";
6
4
  import pool from "./../../system/pooling.js";
7
- import loader from "./../../loader/loader.js";
5
+ import { getImage } from "./../../loader/loader.js";
8
6
  import { ETA } from "./../../math/math.js";
9
7
 
10
8
  /**
@@ -98,7 +96,7 @@ export class TextureAtlas {
98
96
  // set the texture
99
97
  if (typeof(src) === "undefined") {
100
98
  // get the texture name from the atlas meta data
101
- var image = loader.getImage(atlas.meta.image);
99
+ var image = getImage(atlas.meta.image);
102
100
  if (!image) {
103
101
  throw new Error(
104
102
  "Atlas texture '" + image + "' not found"
@@ -106,7 +104,7 @@ export class TextureAtlas {
106
104
  }
107
105
  this.sources.set(atlas.meta.image, image);
108
106
  } else {
109
- this.sources.set(atlas.meta.image || "default", typeof src === "string" ? loader.getImage(src) : src);
107
+ this.sources.set(atlas.meta.image || "default", typeof src === "string" ? getImage(src) : src);
110
108
  }
111
109
  this.repeat = "no-repeat";
112
110
  }
@@ -120,13 +118,13 @@ export class TextureAtlas {
120
118
  }
121
119
  this.format = "ShoeBox";
122
120
  this.repeat = "no-repeat";
123
- this.sources.set("default", typeof src === "string" ? loader.getImage(src) : src);
121
+ this.sources.set("default", typeof src === "string" ? getImage(src) : src);
124
122
  }
125
123
  // Internal texture atlas
126
124
  else if (atlas.meta.app.includes("melonJS")) {
127
125
  this.format = "melonJS";
128
126
  this.repeat = atlas.meta.repeat || "no-repeat";
129
- this.sources.set("default", typeof src === "string" ? loader.getImage(src) : src);
127
+ this.sources.set("default", typeof src === "string" ? getImage(src) : src);
130
128
  }
131
129
  // initialize the atlas
132
130
  this.atlases.set(atlas.meta.image || "default", this.parse(atlas));
@@ -140,7 +138,7 @@ export class TextureAtlas {
140
138
 
141
139
  if (typeof(src) !== "undefined") {
142
140
  // overwrite if specified
143
- atlas.image = typeof src === "string" ? loader.getImage(src) : src;
141
+ atlas.image = typeof src === "string" ? getImage(src) : src;
144
142
  }
145
143
  // initialize the atlas
146
144
  this.atlases.set("default", this.parseFromSpriteSheet(atlas));
@@ -159,11 +157,7 @@ export class TextureAtlas {
159
157
  // Add self to TextureCache if cache !== false
160
158
  if (cache !== false) {
161
159
  this.sources.forEach((source) => {
162
- if (cache instanceof TextureCache) {
163
- cache.set(source, this);
164
- } else {
165
- renderer.cache.set(source, this);
166
- }
160
+ renderer.cache.set(source, this);
167
161
  });
168
162
  }
169
163
  }
@@ -346,12 +340,13 @@ export class TextureAtlas {
346
340
  region = this.getAtlas(atlas)[name];
347
341
  } else {
348
342
  // look for the given region in each existing atlas
349
- this.atlases.forEach((atlas) => {
343
+ for (let atlas of this.atlases.values()) {
350
344
  if (typeof atlas[name] !== "undefined") {
351
345
  // there should be only one
352
346
  region = atlas[name];
347
+ break;
353
348
  }
354
- });
349
+ }
355
350
  }
356
351
  return region;
357
352
  }
@@ -387,7 +382,7 @@ export class TextureAtlas {
387
382
  */
388
383
  addUVs(atlas, name, w, h) {
389
384
  // ignore if using the Canvas Renderer
390
- if (renderer instanceof WebGLRenderer) {
385
+ if (typeof renderer.gl !== "undefined") {
391
386
  // Source coordinates
392
387
  var s = atlas[name].offset;
393
388
  var sw = atlas[name].width;
@@ -56,8 +56,8 @@ class TextureCache {
56
56
  } else {
57
57
  // manage cases where a specific atlas is specified
58
58
  this.cache.forEach((value, key) => {
59
- var _atlas = value.getAtlas();
60
- if (key === image && _atlas[0].width === atlas.framewidth && _atlas[0].height === atlas.frameheight) {
59
+ var _atlas = value.getAtlas()[0];
60
+ if (key === image && _atlas.width === atlas.framewidth && _atlas.height === atlas.frameheight) {
61
61
  entry = value;
62
62
  }
63
63
  });
@@ -87,7 +87,7 @@ export function init(width, height, options) {
87
87
  // initialize the default game Application with the given options
88
88
  game.init(width, height, options);
89
89
  } catch (e) {
90
- console(e.message);
90
+ console.log(e.message);
91
91
  // me.video.init() historically returns false if failing at creating/using a HTML5 canvas
92
92
  return false;
93
93
  }
@@ -7,18 +7,18 @@
7
7
 
8
8
  export default class VertexArrayBuffer {
9
9
 
10
- constructor(vertex_size, vertex_per_quad) {
10
+ constructor(vertex_size, vertex_per_obj) {
11
11
  // the size of one vertex in float
12
12
  this.vertexSize = vertex_size;
13
- // size of a quad in vertex
14
- this.quadSize = vertex_per_quad;
13
+ // size of an object in vertex
14
+ this.objSize = vertex_per_obj;
15
15
  // the maximum number of vertices the vertex array buffer can hold
16
- this.maxVertex = 256;
16
+ this.maxVertex = 256; // (note: this seems to be the sweet spot performance-wise when using batching)
17
17
  // the current number of vertices added to the vertex array buffer
18
18
  this.vertexCount = 0;
19
19
 
20
20
  // the actual vertex data buffer
21
- this.buffer = new ArrayBuffer(this.maxVertex * this.vertexSize * this.quadSize);
21
+ this.buffer = new ArrayBuffer(this.maxVertex * this.vertexSize * this.objSize);
22
22
  // Float32 and Uint32 view of the vertex data array buffer
23
23
  this.bufferF32 = new Float32Array(this.buffer);
24
24
  this.bufferU32 = new Uint32Array(this.buffer);
@@ -37,7 +37,7 @@
37
37
  * return true if full
38
38
  * @ignore
39
39
  */
40
- isFull(vertex = this.quadSize) {
40
+ isFull(vertex = this.objSize) {
41
41
  return (this.vertexCount + vertex >= this.maxVertex);
42
42
  }
43
43
 
@@ -45,14 +45,18 @@
45
45
  * resize the vertex buffer, retaining its original contents
46
46
  * @ignore
47
47
  */
48
- resize() {
49
- // double the vertex size
50
- this.maxVertex <<= 1;
48
+ resize(vertexCount) {
49
+
50
+ while (vertexCount > this.maxVertex) {
51
+ // double the vertex size
52
+ this.maxVertex <<= 1;
53
+ }
54
+
51
55
  // save a reference to the previous data
52
56
  var data = this.bufferF32;
53
57
 
54
58
  // recreate ArrayBuffer and views
55
- this.buffer = new ArrayBuffer(this.maxVertex * this.vertexSize * this.quadSize);
59
+ this.buffer = new ArrayBuffer(this.maxVertex * this.vertexSize * this.objSize);
56
60
  this.bufferF32 = new Float32Array(this.buffer);
57
61
  this.bufferU32 = new Uint32Array(this.buffer);
58
62
 
@@ -70,19 +74,19 @@
70
74
  var offset = this.vertexCount * this.vertexSize;
71
75
 
72
76
  if (this.vertexCount >= this.maxVertex) {
73
- this.resize();
77
+ this.resize(this.vertexCount);
74
78
  }
75
79
 
76
- this.bufferF32[offset + 0] = x;
77
- this.bufferF32[offset + 1] = y;
80
+ this.bufferF32[offset] = x;
81
+ this.bufferF32[++offset] = y;
78
82
 
79
83
  if (typeof u !== "undefined") {
80
- this.bufferF32[offset + 2] = u;
81
- this.bufferF32[offset + 3] = v;
84
+ this.bufferF32[++offset] = u;
85
+ this.bufferF32[++offset] = v;
82
86
  }
83
87
 
84
88
  if (typeof tint !== "undefined") {
85
- this.bufferU32[offset + 4] = tint;
89
+ this.bufferU32[++offset] = tint;
86
90
  }
87
91
 
88
92
  this.vertexCount++;