melonjs 15.1.3 → 15.1.5

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 (164) hide show
  1. package/dist/melonjs.mjs/_virtual/_commonjsHelpers.js +1 -1
  2. package/dist/melonjs.mjs/_virtual/earcut.js +1 -1
  3. package/dist/melonjs.mjs/_virtual/howler.js +1 -1
  4. package/dist/melonjs.mjs/_virtual/index.js +1 -1
  5. package/dist/melonjs.mjs/application/application.js +1 -1
  6. package/dist/melonjs.mjs/application/header.js +1 -1
  7. package/dist/melonjs.mjs/application/resize.js +1 -1
  8. package/dist/melonjs.mjs/application/settings.js +1 -1
  9. package/dist/melonjs.mjs/audio/audio.js +3 -3
  10. package/dist/melonjs.mjs/camera/camera2d.js +1 -1
  11. package/dist/melonjs.mjs/const.js +2 -2
  12. package/dist/melonjs.mjs/entity/entity.js +3 -6
  13. package/dist/melonjs.mjs/geometries/ellipse.js +1 -1
  14. package/dist/melonjs.mjs/geometries/line.js +1 -1
  15. package/dist/melonjs.mjs/geometries/path2d.js +5 -5
  16. package/dist/melonjs.mjs/geometries/point.js +1 -1
  17. package/dist/melonjs.mjs/geometries/poly.js +3 -3
  18. package/dist/melonjs.mjs/geometries/rectangle.js +1 -1
  19. package/dist/melonjs.mjs/geometries/roundrect.js +1 -1
  20. package/dist/melonjs.mjs/index.js +2 -2
  21. package/dist/melonjs.mjs/input/gamepad.js +1 -1
  22. package/dist/melonjs.mjs/input/input.js +1 -1
  23. package/dist/melonjs.mjs/input/keyboard.js +1 -1
  24. package/dist/melonjs.mjs/input/pointer.js +1 -1
  25. package/dist/melonjs.mjs/input/pointerevent.js +10 -10
  26. package/dist/melonjs.mjs/lang/console.js +1 -1
  27. package/dist/melonjs.mjs/lang/deprecated.js +1 -1
  28. package/dist/melonjs.mjs/level/level.js +1 -1
  29. package/dist/melonjs.mjs/level/tiled/TMXGroup.js +1 -1
  30. package/dist/melonjs.mjs/level/tiled/TMXLayer.js +4 -4
  31. package/dist/melonjs.mjs/level/tiled/TMXObject.js +1 -1
  32. package/dist/melonjs.mjs/level/tiled/TMXTile.js +1 -1
  33. package/dist/melonjs.mjs/level/tiled/TMXTileMap.js +1 -1
  34. package/dist/melonjs.mjs/level/tiled/TMXTileset.js +1 -1
  35. package/dist/melonjs.mjs/level/tiled/TMXTilesetGroup.js +1 -1
  36. package/dist/melonjs.mjs/level/tiled/TMXUtils.js +4 -4
  37. package/dist/melonjs.mjs/level/tiled/constants.js +1 -1
  38. package/dist/melonjs.mjs/level/tiled/renderer/TMXHexagonalRenderer.js +2 -2
  39. package/dist/melonjs.mjs/level/tiled/renderer/TMXIsometricRenderer.js +1 -1
  40. package/dist/melonjs.mjs/level/tiled/renderer/TMXOrthogonalRenderer.js +1 -1
  41. package/dist/melonjs.mjs/level/tiled/renderer/TMXRenderer.js +2 -1
  42. package/dist/melonjs.mjs/level/tiled/renderer/TMXStaggeredRenderer.js +1 -1
  43. package/dist/melonjs.mjs/level/tiled/renderer/autodetect.js +1 -1
  44. package/dist/melonjs.mjs/loader/cache.js +1 -1
  45. package/dist/melonjs.mjs/loader/loader.js +53 -67
  46. package/dist/melonjs.mjs/loader/loadingscreen.js +1 -1
  47. package/dist/melonjs.mjs/loader/melonjs_logo.png.js +1 -1
  48. package/dist/melonjs.mjs/loader/parser.js +1 -1
  49. package/dist/melonjs.mjs/loader/settings.js +1 -1
  50. package/dist/melonjs.mjs/math/color.js +1 -1
  51. package/dist/melonjs.mjs/math/math.js +1 -1
  52. package/dist/melonjs.mjs/math/matrix2.js +1 -1
  53. package/dist/melonjs.mjs/math/matrix3.js +1 -1
  54. package/dist/melonjs.mjs/math/observable_vector2.js +1 -1
  55. package/dist/melonjs.mjs/math/observable_vector3.js +1 -1
  56. package/dist/melonjs.mjs/math/vector2.js +1 -1
  57. package/dist/melonjs.mjs/math/vector3.js +1 -1
  58. package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/esm/arraymultimap.js +1 -1
  59. package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/esm/multimap.js +1 -1
  60. package/dist/melonjs.mjs/node_modules/earcut/src/earcut.js +1 -1
  61. package/dist/melonjs.mjs/node_modules/eventemitter3/index.js +1 -1
  62. package/dist/melonjs.mjs/node_modules/eventemitter3/index2.js +1 -1
  63. package/dist/melonjs.mjs/node_modules/howler/dist/howler.js +1 -1
  64. package/dist/melonjs.mjs/particles/emitter.js +1 -1
  65. package/dist/melonjs.mjs/particles/particle.js +1 -1
  66. package/dist/melonjs.mjs/particles/settings.js +1 -1
  67. package/dist/melonjs.mjs/physics/body.js +1 -1
  68. package/dist/melonjs.mjs/physics/bounds.js +2 -2
  69. package/dist/melonjs.mjs/physics/collision.js +1 -1
  70. package/dist/melonjs.mjs/physics/detector.js +2 -2
  71. package/dist/melonjs.mjs/physics/quadtree.js +2 -2
  72. package/dist/melonjs.mjs/physics/response.js +1 -1
  73. package/dist/melonjs.mjs/physics/sat.js +5 -4
  74. package/dist/melonjs.mjs/physics/world.js +1 -1
  75. package/dist/melonjs.mjs/plugin/plugin.js +3 -3
  76. package/dist/melonjs.mjs/renderable/collectable.js +1 -1
  77. package/dist/melonjs.mjs/renderable/colorlayer.js +1 -1
  78. package/dist/melonjs.mjs/renderable/container.js +35 -25
  79. package/dist/melonjs.mjs/renderable/dragndrop.js +1 -1
  80. package/dist/melonjs.mjs/renderable/imagelayer.js +1 -1
  81. package/dist/melonjs.mjs/renderable/light2d.js +1 -1
  82. package/dist/melonjs.mjs/renderable/nineslicesprite.js +1 -1
  83. package/dist/melonjs.mjs/renderable/renderable.js +6 -9
  84. package/dist/melonjs.mjs/renderable/sprite.js +1 -1
  85. package/dist/melonjs.mjs/renderable/trigger.js +1 -1
  86. package/dist/melonjs.mjs/renderable/ui/uibaseelement.js +7 -4
  87. package/dist/melonjs.mjs/renderable/ui/uispriteelement.js +8 -2
  88. package/dist/melonjs.mjs/renderable/ui/uitextbutton.js +1 -1
  89. package/dist/melonjs.mjs/state/stage.js +1 -1
  90. package/dist/melonjs.mjs/state/state.js +1 -1
  91. package/dist/melonjs.mjs/system/device.js +1 -1
  92. package/dist/melonjs.mjs/system/dom.js +1 -1
  93. package/dist/melonjs.mjs/system/event.js +1 -1
  94. package/dist/melonjs.mjs/system/platform.js +1 -1
  95. package/dist/melonjs.mjs/system/pooling.js +1 -1
  96. package/dist/melonjs.mjs/system/save.js +1 -1
  97. package/dist/melonjs.mjs/system/timer.js +1 -1
  98. package/dist/melonjs.mjs/text/bitmaptext.js +3 -3
  99. package/dist/melonjs.mjs/text/bitmaptextdata.js +1 -1
  100. package/dist/melonjs.mjs/text/glyph.js +1 -1
  101. package/dist/melonjs.mjs/text/text.js +2 -2
  102. package/dist/melonjs.mjs/text/textmetrics.js +1 -1
  103. package/dist/melonjs.mjs/text/textstyle.js +1 -1
  104. package/dist/melonjs.mjs/tweens/easing.js +1 -1
  105. package/dist/melonjs.mjs/tweens/interpolation.js +1 -1
  106. package/dist/melonjs.mjs/tweens/tween.js +1 -1
  107. package/dist/melonjs.mjs/utils/agent.js +1 -1
  108. package/dist/melonjs.mjs/utils/array.js +1 -1
  109. package/dist/melonjs.mjs/utils/file.js +1 -1
  110. package/dist/melonjs.mjs/utils/function.js +1 -1
  111. package/dist/melonjs.mjs/utils/string.js +1 -1
  112. package/dist/melonjs.mjs/utils/utils.js +1 -1
  113. package/dist/melonjs.mjs/video/canvas/canvas_renderer.js +3 -6
  114. package/dist/melonjs.mjs/video/renderer.js +1 -1
  115. package/dist/melonjs.mjs/video/texture/atlas.js +1 -1
  116. package/dist/melonjs.mjs/video/texture/cache.js +1 -1
  117. package/dist/melonjs.mjs/video/texture/canvas_texture.js +2 -2
  118. package/dist/melonjs.mjs/video/utils/autodetect.js +1 -1
  119. package/dist/melonjs.mjs/video/video.js +10 -3
  120. package/dist/melonjs.mjs/video/webgl/buffer/vertex.js +1 -1
  121. package/dist/melonjs.mjs/video/webgl/compositors/compositor.js +1 -1
  122. package/dist/melonjs.mjs/video/webgl/compositors/primitive_compositor.js +1 -1
  123. package/dist/melonjs.mjs/video/webgl/compositors/quad_compositor.js +1 -1
  124. package/dist/melonjs.mjs/video/webgl/glshader.js +1 -1
  125. package/dist/melonjs.mjs/video/webgl/shaders/primitive.frag.js +1 -1
  126. package/dist/melonjs.mjs/video/webgl/shaders/primitive.vert.js +1 -1
  127. package/dist/melonjs.mjs/video/webgl/shaders/quad.frag.js +1 -1
  128. package/dist/melonjs.mjs/video/webgl/shaders/quad.vert.js +1 -1
  129. package/dist/melonjs.mjs/video/webgl/utils/attributes.js +1 -1
  130. package/dist/melonjs.mjs/video/webgl/utils/precision.js +1 -1
  131. package/dist/melonjs.mjs/video/webgl/utils/program.js +1 -1
  132. package/dist/melonjs.mjs/video/webgl/utils/string.js +1 -1
  133. package/dist/melonjs.mjs/video/webgl/utils/uniforms.js +1 -1
  134. package/dist/melonjs.mjs/video/webgl/webgl_renderer.js +1 -1
  135. package/dist/melonjs.module.js +150 -152
  136. package/dist/types/audio/audio.d.ts +2 -2
  137. package/dist/types/const.d.ts +2 -2
  138. package/dist/types/loader/loader.d.ts +54 -55
  139. package/dist/types/renderable/renderable.d.ts +1 -1
  140. package/dist/types/video/video.d.ts +1 -1
  141. package/package.json +8 -8
  142. package/src/audio/audio.js +2 -2
  143. package/src/const.js +1 -1
  144. package/src/entity/entity.js +2 -5
  145. package/src/geometries/path2d.js +4 -4
  146. package/src/geometries/poly.js +2 -2
  147. package/src/input/pointerevent.js +9 -9
  148. package/src/level/tiled/TMXLayer.js +3 -3
  149. package/src/level/tiled/TMXUtils.js +3 -3
  150. package/src/level/tiled/renderer/TMXHexagonalRenderer.js +1 -1
  151. package/src/loader/loader.js +52 -66
  152. package/src/physics/bounds.js +1 -1
  153. package/src/physics/detector.js +1 -1
  154. package/src/physics/quadtree.js +1 -1
  155. package/src/physics/sat.js +3 -3
  156. package/src/renderable/container.js +34 -24
  157. package/src/renderable/renderable.js +5 -8
  158. package/src/renderable/ui/uibaseelement.js +6 -3
  159. package/src/renderable/ui/uispriteelement.js +7 -1
  160. package/src/text/bitmaptext.js +2 -2
  161. package/src/text/text.js +1 -1
  162. package/src/video/canvas/canvas_renderer.js +2 -5
  163. package/src/video/texture/canvas_texture.js +1 -1
  164. package/src/video/video.js +1 -1
@@ -17,9 +17,9 @@ export * from "./settings.js";
17
17
 
18
18
  /**
19
19
  * onload callback
20
- * @name onload
21
20
  * @default undefined
22
21
  * @memberof loader
22
+ * @type {function}
23
23
  * @example
24
24
  * // set a callback when everything is loaded
25
25
  * me.loader.onload = this.loaded.bind(this);
@@ -30,9 +30,9 @@ export let onload;
30
30
  * onProgress callback<br>
31
31
  * each time a resource is loaded, the loader will fire the specified function,
32
32
  * giving the actual progress [0 ... 1], as argument, and an object describing the resource loaded
33
- * @name onProgress
34
33
  * @default undefined
35
34
  * @memberof loader
35
+ * @type {function}
36
36
  * @example
37
37
  * // set a callback for progress notification
38
38
  * me.loader.onProgress = this.updateProgress.bind(this);
@@ -101,19 +101,25 @@ function onLoadingError(res) {
101
101
  }
102
102
 
103
103
  /**
104
- * set all the specified game resources to be preloaded.
105
- * @name preload
104
+ * an asset definition to be used with the loader
105
+ * @typedef {object} loader.Asset
106
+ * @property {string} name - name of the asset
107
+ * @property {string} type - the type of the asset : "audio", binary", "image", "json", "js", "tmx", "tmj", "tsx", "tsj", "fontface"
108
+ * @property {string} [src] - path and/or file name of the resource (for audio assets only the path is required)
109
+ * @property {string} [data] - TMX data if not provided through a src url
110
+ * @property {boolean} [stream] - Set to true to force HTML5 Audio, which allows not to wait for large file to be downloaded before playing.
111
+ * @see loader.preload
112
+ * @see loader.load
113
+ */
114
+
115
+ /**
116
+ * set all the specified game assets to be preloaded.
106
117
  * @memberof loader
107
- * @public
108
- * @param {object[]} res
109
- * @param {string} res.name - internal name of the resource
110
- * @param {string} res.type - "audio", binary", "image", "json","js", "tmx", "tsx", "fontface"
111
- * @param {string} res.src - path and/or file name of the resource (for audio assets only the path is required)
112
- * @param {boolean} [res.stream] - Set to true to force HTML5 Audio, which allows not to wait for large file to be downloaded before playing.
113
- * @param {Function} [onload=loader.onload] - function to be called when all resources are loaded
118
+ * @param {loader.Asset[]} assets - list of assets to load
119
+ * @param {Function} [onloadcb=loader.onload] - function to be called when all resources are loaded
114
120
  * @param {boolean} [switchToLoadState=true] - automatically switch to the loading screen
115
121
  * @example
116
- * game_resources = [
122
+ * game.assets = [
117
123
  * // PNG tileset
118
124
  * {name: "tileset-platformer", type: "image", src: "data/map/tileset.png"},
119
125
  * // PNG packed texture
@@ -143,15 +149,15 @@ function onLoadingError(res) {
143
149
  * ];
144
150
  * ...
145
151
  * // set all resources to be loaded
146
- * me.loader.preload(game.resources, () => this.loaded());
152
+ * me.loader.preload(game.assets, () => this.loaded());
147
153
  */
148
- export function preload(res, onloadcb, switchToLoadState = true) {
154
+ export function preload(assets, onloadcb, switchToLoadState = true) {
149
155
  // parse the resources
150
- for (let i = 0; i < res.length; i++) {
156
+ for (let i = 0; i < assets.length; i++) {
151
157
  resourceCount += load(
152
- res[i],
153
- onResourceLoaded.bind(this, res[i]),
154
- onLoadingError.bind(this, res[i])
158
+ assets[i],
159
+ onResourceLoaded.bind(this, assets[i]),
160
+ onLoadingError.bind(this, assets[i])
155
161
  );
156
162
  }
157
163
  // set the onload callback if defined
@@ -169,15 +175,9 @@ export function preload(res, onloadcb, switchToLoadState = true) {
169
175
  }
170
176
 
171
177
  /**
172
- * Load a single resource (to be used if you need to load additional resource during the game)
173
- * @name load
178
+ * Load a single asset (to be used if you need to load additional asset(s) during the game)
174
179
  * @memberof loader
175
- * @public
176
- * @param {object} res
177
- * @param {string} res.name - internal name of the resource
178
- * @param {string} res.type - "audio", binary", "image", "json", "tmx", "tsx"
179
- * @param {string} res.src - path and/or file name of the resource (for audio assets only the path is required)
180
- * @param {boolean} [res.stream] - Set to true to force HTML5 Audio, which allows not to wait for large file to be downloaded before playing.
180
+ * @param {loader.Asset} asset
181
181
  * @param {Function} [onload] - function to be called when the resource is loaded
182
182
  * @param {Function} [onerror] - function to be called in case of error
183
183
  * @returns {number} the amount of corresponding resource to be preloaded
@@ -195,83 +195,79 @@ export function preload(res, onloadcb, switchToLoadState = true) {
195
195
  * me.audio.play("bgmusic");
196
196
  * });
197
197
  */
198
- export function load(res, onload, onerror) {
198
+ export function load(asset, onload, onerror) {
199
199
  // transform the url if necessary
200
- if (typeof (baseURL[res.type]) !== "undefined") {
201
- res.src = baseURL[res.type] + res.src;
200
+ if (typeof (baseURL[asset.type]) !== "undefined") {
201
+ asset.src = baseURL[asset.type] + asset.src;
202
202
  }
203
203
  // check ressource type
204
- switch (res.type) {
204
+ switch (asset.type) {
205
205
  case "binary":
206
206
  // reuse the preloadImage fn
207
- preloadBinary.call(this, res, onload, onerror);
207
+ preloadBinary.call(this, asset, onload, onerror);
208
208
  return 1;
209
209
 
210
210
  case "image":
211
211
  // reuse the preloadImage fn
212
- preloadImage.call(this, res, onload, onerror);
212
+ preloadImage.call(this, asset, onload, onerror);
213
213
  return 1;
214
214
 
215
215
  case "json":
216
- preloadJSON.call(this, res, onload, onerror);
216
+ preloadJSON.call(this, asset, onload, onerror);
217
217
  return 1;
218
218
 
219
219
  case "js":
220
- preloadJavascript.call(this, res, onload, onerror);
220
+ preloadJavascript.call(this, asset, onload, onerror);
221
221
  return 1;
222
222
 
223
223
  case "tmx":
224
224
  case "tsx":
225
- preloadTMX.call(this, res, onload, onerror);
225
+ preloadTMX.call(this, asset, onload, onerror);
226
226
  return 1;
227
227
 
228
228
  case "audio":
229
- audio.load(res, !!res.stream, onload, onerror);
229
+ audio.load(asset, !!asset.stream, onload, onerror);
230
230
  return 1;
231
231
 
232
232
  case "fontface":
233
- preloadFontFace.call(this, res, onload, onerror);
233
+ preloadFontFace.call(this, asset, onload, onerror);
234
234
  return 1;
235
235
 
236
236
  default:
237
- throw new Error("load : unknown or invalid resource type : " + res.type);
237
+ throw new Error("load : unknown or invalid resource type : " + asset.type);
238
238
  }
239
239
  }
240
240
 
241
241
  /**
242
- * unload specified resource to free memory
243
- * @name unload
242
+ * unload the specified asset to free memory
244
243
  * @memberof loader
245
- * @public
246
- * @param {object} res
247
- * @param {string} res.name - internal name of the resource
248
- * @param {string} res.type - "audio", binary", "image", "json", "tmx", "tsx"
244
+ * @param {loader.Asset} asset
249
245
  * @returns {boolean} true if unloaded
250
246
  * @example me.loader.unload({name: "avatar", type:"image"});
251
247
  */
252
- export function unload(res) {
253
- switch (res.type) {
248
+ export function unload(asset) {
249
+ switch (asset.type) {
254
250
  case "binary":
255
- if (!(res.name in binList)) {
251
+ if (!(asset.name in binList)) {
256
252
  return false;
257
253
  }
258
254
 
259
- delete binList[res.name];
255
+ delete binList[asset.name];
260
256
  return true;
261
257
 
262
258
  case "image":
263
- if (!(res.name in imgList)) {
259
+ if (!(asset.name in imgList)) {
264
260
  return false;
265
261
  }
266
- delete imgList[res.name];
262
+ delete imgList[asset.name];
267
263
  return true;
268
264
 
269
265
  case "json":
270
- if (!(res.name in jsonList)) {
266
+ if (!(asset.name in jsonList)) {
271
267
  return false;
272
268
  }
273
269
 
274
- delete jsonList[res.name];
270
+ delete jsonList[asset.name];
275
271
  return true;
276
272
 
277
273
  case "js":
@@ -284,26 +280,24 @@ export function unload(res) {
284
280
 
285
281
  case "tmx":
286
282
  case "tsx":
287
- if (!(res.name in tmxList)) {
283
+ if (!(asset.name in tmxList)) {
288
284
  return false;
289
285
  }
290
286
 
291
- delete tmxList[res.name];
287
+ delete tmxList[asset.name];
292
288
  return true;
293
289
 
294
290
  case "audio":
295
- return audio.unload(res.name);
291
+ return audio.unload(asset.name);
296
292
 
297
293
  default:
298
- throw new Error("unload : unknown or invalid resource type : " + res.type);
294
+ throw new Error("unload : unknown or invalid resource type : " + asset.type);
299
295
  }
300
296
  }
301
297
 
302
298
  /**
303
299
  * unload all resources to free memory
304
- * @name unloadAll
305
300
  * @memberof loader
306
- * @public
307
301
  * @example me.loader.unloadAll();
308
302
  */
309
303
  export function unloadAll() {
@@ -355,9 +349,7 @@ export function unloadAll() {
355
349
 
356
350
  /**
357
351
  * return the specified TMX/TSX object
358
- * @name getTMX
359
352
  * @memberof loader
360
- * @public
361
353
  * @param {string} elt - name of the tmx/tsx element ("map1");
362
354
  * @returns {object} requested element or null if not found
363
355
  */
@@ -372,9 +364,7 @@ export function getTMX(elt) {
372
364
 
373
365
  /**
374
366
  * return the specified Binary object
375
- * @name getBinary
376
367
  * @memberof loader
377
- * @public
378
368
  * @param {string} elt - name of the binary object ("ymTrack");
379
369
  * @returns {object} requested element or null if not found
380
370
  */
@@ -389,9 +379,7 @@ export function getBinary(elt) {
389
379
 
390
380
  /**
391
381
  * return the specified Image Object
392
- * @name getImage
393
382
  * @memberof loader
394
- * @public
395
383
  * @param {string} image - name of the Image element ("tileset-platformer");
396
384
  * @returns {HTMLImageElement} requested element or null if not found
397
385
  */
@@ -407,9 +395,7 @@ export function getImage(image) {
407
395
 
408
396
  /**
409
397
  * return the specified JSON Object
410
- * @name getJSON
411
398
  * @memberof loader
412
- * @public
413
399
  * @param {string} elt - name of the json file to load
414
400
  * @returns {object}
415
401
  */
@@ -190,7 +190,7 @@ import Vector2d from "./../math/vector2.js";
190
190
  this.clear();
191
191
  }
192
192
  for (let i = 0; i < vertices.length; i++) {
193
- let vertex = vertices[i];
193
+ const vertex = vertices[i];
194
194
  if (vertex.x > this.max.x) this.max.x = vertex.x;
195
195
  if (vertex.x < this.min.x) this.min.x = vertex.x;
196
196
  if (vertex.y > this.max.y) this.max.y = vertex.y;
@@ -170,7 +170,7 @@ export default class Detector {
170
170
  if (objB.body && line.getBounds().overlaps(objB.getBounds())) {
171
171
 
172
172
  // go trough all defined shapes in B (if any)
173
- let bLen = objB.body.shapes.length;
173
+ const bLen = objB.body.shapes.length;
174
174
  if ( objB.body.shapes.length === 0) {
175
175
  continue;
176
176
  }
@@ -352,7 +352,7 @@ let QT_VECTOR = new Vector2d();
352
352
  */
353
353
  hasChildren() {
354
354
  for (let i = 0; i < this.nodes.length; i = i + 1) {
355
- let subnode = this.nodes[i];
355
+ const subnode = this.nodes[i];
356
356
  if (subnode.length > 0 || subnode.objects.length > 0) {
357
357
  return true;
358
358
  }
@@ -58,7 +58,7 @@ function flattenPointsOn(points, normal, result) {
58
58
  let len = points.length;
59
59
  for (let i = 0; i < len; i++) {
60
60
  // The magnitude of the projection of the point onto the normal
61
- let dot = points[i].dot(normal);
61
+ const dot = points[i].dot(normal);
62
62
  if (dot < min) { min = dot; }
63
63
  if (dot > max) { max = dot; }
64
64
  }
@@ -305,8 +305,8 @@ export function testPolygonEllipse(a, polyA, b, ellipseB, response) {
305
305
 
306
306
  // For each edge in the polygon:
307
307
  for (let i = 0; i < len; i++) {
308
- let next = i === len - 1 ? 0 : i + 1;
309
- let prev = i === 0 ? len - 1 : i - 1;
308
+ const next = i === len - 1 ? 0 : i + 1;
309
+ const prev = i === 0 ? len - 1 : i - 1;
310
310
  let overlap = 0;
311
311
  let overlapN = null;
312
312
 
@@ -193,10 +193,16 @@ let globalFloatingCounter = 0;
193
193
  }
194
194
  }
195
195
 
196
+ // add the new child
196
197
  child.ancestor = this;
197
198
  this.getChildren().push(child);
199
+
200
+ // update child bounds to reflect the new ancestor
198
201
  if (typeof child.updateBounds === "function") {
199
- // update child bounds to reflect the new ancestor
202
+ if (this.isFloating === true) {
203
+ // only parent container can be floating
204
+ child.floating = false;
205
+ }
200
206
  child.updateBounds();
201
207
  }
202
208
 
@@ -217,12 +223,7 @@ let globalFloatingCounter = 0;
217
223
  child.onActivateEvent();
218
224
  }
219
225
 
220
- // force repaint in case this is a static non-animated object
221
- if (this.isAttachedToRoot() === true) {
222
- this.isDirty = true;
223
- }
224
-
225
- // force bounds update if required
226
+ // force container bounds update if required
226
227
  if (this.enableChildBoundsUpdate === true) {
227
228
  this.updateBounds();
228
229
  }
@@ -245,6 +246,9 @@ let globalFloatingCounter = 0;
245
246
  }
246
247
  }
247
248
 
249
+ // mark the container for repaint
250
+ this.isDirty = true;
251
+
248
252
  // triggered callback if defined
249
253
  this.onChildChange.call(this, this.getChildren().length - 1);
250
254
 
@@ -271,20 +275,25 @@ let globalFloatingCounter = 0;
271
275
  child.GUID = utils.createGUID();
272
276
  }
273
277
  }
274
- child.ancestor = this;
275
278
 
279
+ // add the new child
280
+ child.ancestor = this;
276
281
  this.getChildren().splice(index, 0, child);
277
282
 
278
- if (typeof child.onActivateEvent === "function" && this.isAttachedToRoot()) {
279
- child.onActivateEvent();
283
+ // update child bounds to reflect the new ancestor
284
+ if (typeof child.updateBounds === "function") {
285
+ if (this.isFloating === true) {
286
+ // only parent container can be floating
287
+ child.floating = false;
288
+ }
289
+ child.updateBounds();
280
290
  }
281
291
 
282
- // force repaint in case this is a static non-animated object
283
- if (this.isAttachedToRoot() === true) {
284
- this.isDirty = true;
292
+ if (typeof child.onActivateEvent === "function" && this.isAttachedToRoot()) {
293
+ child.onActivateEvent();
285
294
  }
286
295
 
287
- // force bounds update if required
296
+ // force container bounds update if required
288
297
  if (this.enableChildBoundsUpdate === true) {
289
298
  this.updateBounds();
290
299
  }
@@ -307,6 +316,9 @@ let globalFloatingCounter = 0;
307
316
  }
308
317
  }
309
318
 
319
+ // mark the container for repaint
320
+ this.isDirty = true;
321
+
310
322
  // triggered callback if defined
311
323
  this.onChildChange.call(this, index);
312
324
 
@@ -531,10 +543,9 @@ let globalFloatingCounter = 0;
531
543
  }
532
544
 
533
545
  /**
534
- * update the bounding box for this shape.
535
- * @ignore
536
- * @param {boolean} absolute - update the bounds size and position in (world) absolute coordinates
537
- * @returns {Bounds} this shape bounding box Rectangle object
546
+ * update the bounding box for this container.
547
+ * @param {boolean} [absolute=true] - update the bounds size and position in (world) absolute coordinates
548
+ * @returns {Bounds} this container bounding box Rectangle object
538
549
  */
539
550
  updateBounds(absolute = true) {
540
551
  let bounds = this.getBounds();
@@ -545,13 +556,14 @@ let globalFloatingCounter = 0;
545
556
  if (this.enableChildBoundsUpdate === true) {
546
557
  this.forEach((child) => {
547
558
  if (child.isRenderable) {
548
- let childBounds = child.getBounds();
559
+ let childBounds = child.updateBounds(true);
549
560
  if (childBounds.isFinite()) {
550
561
  bounds.addBounds(childBounds);
551
562
  }
552
563
  }
553
564
  });
554
565
  }
566
+
555
567
  return bounds;
556
568
  }
557
569
 
@@ -675,16 +687,14 @@ let globalFloatingCounter = 0;
675
687
  child.ancestor = undefined;
676
688
  }
677
689
 
678
- // force repaint in case this is a static non-animated object
679
- if (this.isAttachedToRoot() === true) {
680
- this.isDirty = true;
681
- }
682
-
683
690
  // force bounds update if required
684
691
  if (this.enableChildBoundsUpdate === true) {
685
692
  this.updateBounds();
686
693
  }
687
694
 
695
+ // mark the container for repaint
696
+ this.isDirty = true;
697
+
688
698
  // triggered callback if defined
689
699
  this.onChildChange.call(this, childIndex);
690
700
  }
@@ -263,12 +263,12 @@ import Color from "./../math/color.js";
263
263
  }
264
264
 
265
265
  /**
266
- * Whether the renderable object is floating, or contained in a floating container
266
+ * Whether the renderable object is floating (i.e. used screen coordinates), or contained in a floating parent container
267
267
  * @see Renderable#floating
268
268
  * @type {boolean}
269
269
  */
270
270
  get isFloating() {
271
- return this.floating === true || (typeof this.ancestor !== "undefined" && this.ancestor.floating === true);
271
+ return this.floating === true || (typeof this.ancestor !== "undefined" && this.ancestor.isFloating === true);
272
272
  }
273
273
 
274
274
  /**
@@ -577,11 +577,8 @@ import Color from "./../math/color.js";
577
577
  }
578
578
 
579
579
  if (absolute === true) {
580
- bounds.centerOn(this.pos.x + bounds.x + bounds.width / 2, this.pos.y + bounds.y + bounds.height / 2);
581
- if (typeof this.ancestor !== "undefined" && typeof this.ancestor.addChild === "function" && this.floating !== true) {
582
- bounds.translate(this.ancestor.getAbsolutePosition());
583
- }
584
-
580
+ var absPos = this.getAbsolutePosition();
581
+ bounds.centerOn(absPos.x + bounds.x + bounds.width / 2, absPos.y + bounds.y + bounds.height / 2);
585
582
  }
586
583
  return bounds;
587
584
 
@@ -610,7 +607,7 @@ import Color from "./../math/color.js";
610
607
  }
611
608
  // XXX Cache me or something
612
609
  this._absPos.set(this.pos.x, this.pos.y);
613
- if (typeof this.ancestor !== "undefined" && typeof this.ancestor.addChild === "function" && this.floating !== true) {
610
+ if (typeof this.ancestor !== "undefined" && typeof this.ancestor.getAbsolutePosition === "function" && this.floating !== true) {
614
611
  this._absPos.add(this.ancestor.getAbsolutePosition());
615
612
  }
616
613
  return this._absPos;
@@ -64,7 +64,7 @@ import pool from "../../system/pooling.js";
64
64
 
65
65
  /**
66
66
  * UI base elements use screen coordinates by default
67
- * (Note: any child elements added to a UIBaseElement should set their floating property to false)
67
+ * (Note: any child elements added to a UIBaseElement should have their floating property to false)
68
68
  * @see Renderable.floating
69
69
  * @type {boolean}
70
70
  * @default true
@@ -76,6 +76,9 @@ import pool from "../../system/pooling.js";
76
76
 
77
77
  // enable event detection
78
78
  this.isKinematic = false;
79
+
80
+ // update container and children bounds automatically
81
+ this.enableChildBoundsUpdate = true;
79
82
  }
80
83
 
81
84
  /**
@@ -110,7 +113,7 @@ import pool from "../../system/pooling.js";
110
113
  * @returns {boolean} return false if we need to stop propagating the event
111
114
  */
112
115
  onClick(event) { // eslint-disable-line no-unused-vars
113
- return false;
116
+ return true;
114
117
  }
115
118
 
116
119
  /**
@@ -203,7 +206,7 @@ import pool from "../../system/pooling.js";
203
206
  * @returns {boolean} return false if we need to stop propagating the event
204
207
  */
205
208
  onRelease() {
206
- return false;
209
+ return true;
207
210
  }
208
211
 
209
212
  /**
@@ -73,7 +73,13 @@ import { registerPointerEvent, releasePointerEvent} from "./../../input/input.js
73
73
  this.holdTimeout = -1;
74
74
  this.released = true;
75
75
 
76
- // GUI items use screen coordinates
76
+ /**
77
+ * if this UISpriteElement should use screen coordinates or local coordinates
78
+ * (Note: any UISpriteElement elements added to a floating parent container should have their floating property to false)
79
+ * @see Renderable.floating
80
+ * @type {boolean}
81
+ * @default true
82
+ */
77
83
  this.floating = true;
78
84
 
79
85
  // enable event detection
@@ -232,7 +232,7 @@ import TextMetrics from "./textmetrics.js";
232
232
  }
233
233
 
234
234
  if (absolute === true) {
235
- if (typeof this.ancestor !== "undefined" && typeof this.ancestor.addChild === "function" && this.floating !== true) {
235
+ if (typeof this.ancestor !== "undefined" && typeof this.ancestor.getAbsolutePosition === "function" && this.floating !== true) {
236
236
  bounds.translate(this.ancestor.getAbsolutePosition());
237
237
  }
238
238
  }
@@ -311,7 +311,7 @@ import TextMetrics from "./textmetrics.js";
311
311
 
312
312
  for (let i = 0; i < this._text.length; i++) {
313
313
  x = lX;
314
- let string = this._text[i].trimEnd();
314
+ const string = this._text[i].trimEnd();
315
315
  // adjust x pos based on alignment value
316
316
  let stringWidth = this.metrics.lineWidth(string);
317
317
  switch (this.textAlign) {
package/src/text/text.js CHANGED
@@ -375,7 +375,7 @@ const toPX = [12, 24, 0.75, 1];
375
375
  setContextStyle(context, this);
376
376
 
377
377
  for (let i = 0; i < text.length; i++) {
378
- let string = text[i].trimEnd();
378
+ const string = text[i].trimEnd();
379
379
  // draw the string
380
380
  if (this.fillStyle.alpha > 0) {
381
381
  context.fillText(string, x, y);
@@ -392,9 +392,8 @@ import * as event from "./../../system/event.js";
392
392
  this.translate(poly.pos.x, poly.pos.y);
393
393
  context.beginPath();
394
394
  context.moveTo(poly.points[0].x, poly.points[0].y);
395
- let point;
396
395
  for (let i = 1; i < poly.points.length; i++) {
397
- point = poly.points[i];
396
+ const point = poly.points[i];
398
397
  context.lineTo(point.x, point.y);
399
398
  }
400
399
  context.lineTo(poly.points[0].x, poly.points[0].y);
@@ -689,11 +688,9 @@ import * as event from "./../../system/event.js";
689
688
  } else {
690
689
  // polygon
691
690
  const _x = mask.pos.x, _y = mask.pos.y;
692
- let point;
693
-
694
691
  context.moveTo(_x + mask.points[0].x, _y + mask.points[0].y);
695
692
  for (let i = 1; i < mask.points.length; i++) {
696
- point = mask.points[i];
693
+ const point = mask.points[i];
697
694
  context.lineTo(_x + point.x, _y + point.y);
698
695
  }
699
696
  }
@@ -38,7 +38,7 @@ class CanvasTexture {
38
38
  * the rendering context of this CanvasTexture
39
39
  * @type {CanvasRenderingContext2D}
40
40
  */
41
- this.context = this.canvas.getContext("2d", { willReadFrequently: attributes.willReadFrequently });
41
+ this.context = this.canvas.getContext(attributes.context, { willReadFrequently: attributes.willReadFrequently });
42
42
 
43
43
  // enable or disable antiAlias if specified
44
44
  this.setAntiAlias(attributes.antiAlias);
@@ -155,7 +155,7 @@ export function createCanvas(width, height, returnOffscreenCanvas = false) {
155
155
  throw new Error("width or height was zero, Canvas could not be initialized !");
156
156
  }
157
157
 
158
- if (device.hasOffscreenCanvas === true && returnOffscreenCanvas === true) {
158
+ if (device.offscreenCanvas === true && returnOffscreenCanvas === true) {
159
159
  _canvas = new globalThis.OffscreenCanvas(0, 0);
160
160
  // stubbing style for compatibility,
161
161
  // as OffscreenCanvas is detached from the DOM