melonjs 15.1.4 → 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 (158) 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 +1 -1
  10. package/dist/melonjs.mjs/camera/camera2d.js +1 -1
  11. package/dist/melonjs.mjs/const.js +1 -1
  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 +4 -3
  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 +1 -1
  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 +97 -84
  136. package/dist/types/loader/loader.d.ts +9 -4
  137. package/dist/types/renderable/renderable.d.ts +1 -1
  138. package/package.json +7 -7
  139. package/src/entity/entity.js +2 -5
  140. package/src/geometries/path2d.js +4 -4
  141. package/src/geometries/poly.js +2 -2
  142. package/src/input/pointerevent.js +9 -9
  143. package/src/level/tiled/TMXLayer.js +3 -3
  144. package/src/level/tiled/TMXUtils.js +3 -3
  145. package/src/level/tiled/renderer/TMXHexagonalRenderer.js +1 -1
  146. package/src/loader/loader.js +3 -2
  147. package/src/physics/bounds.js +1 -1
  148. package/src/physics/detector.js +1 -1
  149. package/src/physics/quadtree.js +1 -1
  150. package/src/physics/sat.js +3 -3
  151. package/src/renderable/container.js +34 -24
  152. package/src/renderable/renderable.js +5 -8
  153. package/src/renderable/ui/uibaseelement.js +6 -3
  154. package/src/renderable/ui/uispriteelement.js +7 -1
  155. package/src/text/bitmaptext.js +2 -2
  156. package/src/text/text.js +1 -1
  157. package/src/video/canvas/canvas_renderer.js +2 -5
  158. package/src/video/texture/canvas_texture.js +1 -1
@@ -210,7 +210,7 @@ function enablePointerEvent() {
210
210
  */
211
211
  function findActiveEvent(activeEventList, eventTypes) {
212
212
  for (let i = 0; i < eventTypes.length; i++) {
213
- let event = activeEventList.indexOf(eventTypes[i]);
213
+ const event = activeEventList.indexOf(eventTypes[i]);
214
214
  if (event !== -1) {
215
215
  return eventTypes[i];
216
216
  }
@@ -223,7 +223,7 @@ function findActiveEvent(activeEventList, eventTypes) {
223
223
  function findAllActiveEvents(activeEventList, eventTypes) {
224
224
  let events = [];
225
225
  for (let i = 0; i < eventTypes.length; i++) {
226
- let event = activeEventList.indexOf(eventTypes[i]);
226
+ const event = activeEventList.indexOf(eventTypes[i]);
227
227
  if (event !== -1) {
228
228
  events.push(eventTypes[i]);
229
229
  }
@@ -293,10 +293,10 @@ function dispatchEvent(normalizedEvents) {
293
293
 
294
294
  for (let c = candidates.length, candidate; c--, (candidate = candidates[c]);) {
295
295
  if (eventHandlers.has(candidate) && (candidate.isKinematic !== true)) {
296
- let handlers = eventHandlers.get(candidate);
297
- let region = handlers.region;
298
- let ancestor = region.ancestor;
299
- let bounds = region.getBounds();
296
+ const handlers = eventHandlers.get(candidate);
297
+ const region = handlers.region;
298
+ const ancestor = region.ancestor;
299
+ const bounds = region.getBounds();
300
300
  let eventInBounds = false;
301
301
 
302
302
  if (region.isFloating === true) {
@@ -404,7 +404,7 @@ function normalizeEvent(originalEvent) {
404
404
  if (device.touchEvent && originalEvent.changedTouches) {
405
405
  // iOS/Android Touch event
406
406
  for (let i = 0, l = originalEvent.changedTouches.length; i < l; i++) {
407
- let touchEvent = originalEvent.changedTouches[i];
407
+ const touchEvent = originalEvent.changedTouches[i];
408
408
  _pointer = T_POINTERS.pop();
409
409
  _pointer.setEvent(
410
410
  originalEvent,
@@ -682,7 +682,7 @@ export function registerPointerEvent(eventType, region, callback) {
682
682
  // allocate array if not defined
683
683
  let handlers = eventHandlers.get(region);
684
684
  for (let i = 0; i < eventTypes.length; i++) {
685
- eventType = eventTypes[i];
685
+ const eventType = eventTypes[i];
686
686
  if (handlers.callbacks[eventType]) {
687
687
  handlers.callbacks[eventType].push(callback);
688
688
  } else {
@@ -715,7 +715,7 @@ export function releasePointerEvent(eventType, region, callback) {
715
715
  let handlers = eventHandlers.get(region);
716
716
  if (typeof (handlers) !== "undefined") {
717
717
  for (let i = 0; i < eventTypes.length; i++) {
718
- eventType = eventTypes[i];
718
+ const eventType = eventTypes[i];
719
719
  if (handlers.callbacks[eventType]) {
720
720
  if (typeof (callback) !== "undefined") {
721
721
  remove(handlers.callbacks[eventType], callback);
@@ -42,7 +42,7 @@ function setLayerData(layer, bounds, data) {
42
42
  for (let y = 0; y < height; y++) {
43
43
  for (let x = 0; x < width; x++) {
44
44
  // get the value of the gid
45
- let gid = data[idx++];
45
+ const gid = data[idx++];
46
46
  // fill the array
47
47
  if (gid !== 0) {
48
48
  // add a new tile to the layer
@@ -61,7 +61,7 @@ function preRenderLayer(layer, renderer) {
61
61
  for (let y = 0; y < layer.rows; y++) {
62
62
  for (let x = 0; x < layer.cols; x++) {
63
63
  // get the value of the gid
64
- let tile = layer.layerData[x][y];
64
+ const tile = layer.layerData[x][y];
65
65
  // draw the tile if defined
66
66
  if (tile instanceof Tile) {
67
67
  // add a new tile to the layer
@@ -128,7 +128,7 @@ function preRenderLayer(layer, renderer) {
128
128
  "height" : 0
129
129
  };
130
130
  for (let i = 0; i < this.tilesets.length; i++) {
131
- let tileset = this.tilesets.getTilesetByIndex(i);
131
+ const tileset = this.tilesets.getTilesetByIndex(i);
132
132
  this.maxTileSize.width = Math.max(this.maxTileSize.width, tileset.tilewidth);
133
133
  this.maxTileSize.height = Math.max(this.maxTileSize.height, tileset.tileheight);
134
134
  }
@@ -83,7 +83,7 @@ function parseAttributes(obj, elt) {
83
83
  // do attributes
84
84
  if (elt.attributes && elt.attributes.length > 0) {
85
85
  for (let j = 0; j < elt.attributes.length; j++) {
86
- let attribute = elt.attributes.item(j);
86
+ const attribute = elt.attributes.item(j);
87
87
  if (typeof(attribute.name) !== "undefined") {
88
88
  // DOM4 (Attr no longer inherit from Node)
89
89
  obj[attribute.name] = attribute.value;
@@ -282,8 +282,8 @@ export function normalize(obj, item) {
282
282
  var points = parse(item).points.split(" "); // <= "Unexpected lexical declaration in case block" if using let
283
283
 
284
284
  // And normalize them into an array of vectors
285
- for (let i = 0, v; i < points.length; i++) {
286
- v = points[i].split(",");
285
+ for (let i = 0; i < points.length; i++) {
286
+ const v = points[i].split(",");
287
287
  obj[nodeName].push({
288
288
  "x" : +v[0],
289
289
  "y" : +v[1]
@@ -284,7 +284,7 @@ const offsetsStaggerY = [
284
284
  let nearest = 0;
285
285
  let minDist = Number.MAX_VALUE;
286
286
  for (let i = 0; i < 4; ++i) {
287
- let dc = this.centers[i].sub(rel).length2();
287
+ const dc = this.centers[i].sub(rel).length2();
288
288
  if (dc < minDist) {
289
289
  minDist = dc;
290
290
  nearest = i;
@@ -104,8 +104,9 @@ function onLoadingError(res) {
104
104
  * an asset definition to be used with the loader
105
105
  * @typedef {object} loader.Asset
106
106
  * @property {string} name - name of the asset
107
- * @property {string} type - the type of the asset : "audio", binary", "image", "json","js", "tmx", "tsx", "fontface"
108
- * @property {string} src - path and/or file name of the resource (for audio assets only the path is required)
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
109
110
  * @property {boolean} [stream] - Set to true to force HTML5 Audio, which allows not to wait for large file to be downloaded before playing.
110
111
  * @see loader.preload
111
112
  * @see loader.load
@@ -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);