melonjs 10.6.1 → 10.8.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 (79) hide show
  1. package/dist/melonjs.js +37947 -36530
  2. package/dist/melonjs.min.js +22 -22
  3. package/dist/melonjs.module.d.ts +1352 -307
  4. package/dist/melonjs.module.js +2929 -1501
  5. package/package.json +14 -12
  6. package/src/camera/camera2d.js +1 -1
  7. package/src/entity/entity.js +6 -7
  8. package/src/game.js +5 -5
  9. package/src/geometries/ellipse.js +10 -11
  10. package/src/geometries/line.js +3 -3
  11. package/src/geometries/path2d.js +319 -0
  12. package/src/geometries/poly.js +11 -11
  13. package/src/geometries/rectangle.js +30 -15
  14. package/src/geometries/roundrect.js +67 -0
  15. package/src/index.js +9 -5
  16. package/src/input/gamepad.js +12 -10
  17. package/src/input/keyboard.js +5 -3
  18. package/src/input/pointer.js +1 -1
  19. package/src/input/pointerevent.js +3 -4
  20. package/src/lang/deprecated.js +1 -1
  21. package/src/level/tiled/TMXLayer.js +1 -1
  22. package/src/level/tiled/TMXObject.js +9 -12
  23. package/src/level/tiled/TMXTileMap.js +23 -4
  24. package/src/level/tiled/TMXUtils.js +1 -1
  25. package/src/level/tiled/renderer/TMXHexagonalRenderer.js +1 -1
  26. package/src/level/tiled/renderer/TMXIsometricRenderer.js +1 -1
  27. package/src/level/tiled/renderer/TMXOrthogonalRenderer.js +1 -1
  28. package/src/level/tiled/renderer/TMXRenderer.js +1 -1
  29. package/src/level/tiled/renderer/TMXStaggeredRenderer.js +1 -1
  30. package/src/loader/loader.js +5 -5
  31. package/src/loader/loadingscreen.js +1 -1
  32. package/src/math/color.js +1 -1
  33. package/src/math/matrix2.js +1 -1
  34. package/src/math/matrix3.js +67 -66
  35. package/src/math/observable_vector2.js +1 -1
  36. package/src/math/observable_vector3.js +1 -1
  37. package/src/math/vector2.js +1 -1
  38. package/src/math/vector3.js +1 -1
  39. package/src/particles/emitter.js +130 -430
  40. package/src/particles/particle.js +53 -53
  41. package/src/particles/settings.js +310 -0
  42. package/src/physics/body.js +67 -51
  43. package/src/physics/bounds.js +8 -9
  44. package/src/physics/world.js +1 -1
  45. package/src/polyfill/console.js +7 -7
  46. package/src/polyfill/index.js +7 -0
  47. package/src/polyfill/performance.js +20 -0
  48. package/src/polyfill/requestAnimationFrame.js +10 -10
  49. package/src/renderable/collectable.js +9 -2
  50. package/src/renderable/colorlayer.js +1 -1
  51. package/src/renderable/container.js +1 -1
  52. package/src/renderable/imagelayer.js +3 -3
  53. package/src/renderable/renderable.js +1 -1
  54. package/src/renderable/sprite.js +2 -3
  55. package/src/renderable/trigger.js +10 -4
  56. package/src/state/stage.js +1 -1
  57. package/src/state/state.js +8 -8
  58. package/src/system/device.js +148 -133
  59. package/src/system/event.js +10 -10
  60. package/src/system/pooling.js +156 -149
  61. package/src/system/timer.js +1 -1
  62. package/src/text/bitmaptext.js +1 -1
  63. package/src/text/text.js +1 -1
  64. package/src/utils/agent.js +4 -4
  65. package/src/utils/function.js +2 -2
  66. package/src/utils/utils.js +10 -5
  67. package/src/video/canvas/canvas_renderer.js +104 -36
  68. package/src/video/renderer.js +28 -16
  69. package/src/video/texture.js +1 -1
  70. package/src/video/video.js +11 -11
  71. package/src/video/webgl/glshader.js +30 -194
  72. package/src/video/webgl/utils/attributes.js +16 -0
  73. package/src/video/webgl/utils/precision.js +11 -0
  74. package/src/video/webgl/utils/program.js +58 -0
  75. package/src/video/webgl/utils/string.js +16 -0
  76. package/src/video/webgl/utils/uniforms.js +87 -0
  77. package/src/video/webgl/webgl_compositor.js +1 -14
  78. package/src/video/webgl/webgl_renderer.js +129 -186
  79. package/src/particles/particlecontainer.js +0 -95
@@ -1,4 +1,4 @@
1
- import Vector2d from "./../math/vector2.js";
1
+ import pool from "./../system/pooling.js";
2
2
  import Polygon from "./poly.js";
3
3
 
4
4
  /**
@@ -16,10 +16,10 @@ class Rect extends Polygon {
16
16
  constructor(x, y, w, h) {
17
17
  // parent constructor
18
18
  super(x, y, [
19
- new Vector2d(0, 0), // 0, 0
20
- new Vector2d(w, 0), // 1, 0
21
- new Vector2d(w, h), // 1, 1
22
- new Vector2d(0, h) // 0, 1
19
+ pool.pull("Vector2d", 0, 0), // 0, 0
20
+ pool.pull("Vector2d", w, 0), // 1, 0
21
+ pool.pull("Vector2d", w, h), // 1, 1
22
+ pool.pull("Vector2d", 0, h) // 0, 1
23
23
  ]);
24
24
  this.shapeType = "Rectangle";
25
25
  }
@@ -63,7 +63,7 @@ class Rect extends Polygon {
63
63
  * @public
64
64
  * @type {number}
65
65
  * @name left
66
- * @memberof Rect
66
+ * @memberof Rect.prototype
67
67
  */
68
68
  get left() {
69
69
  return this.pos.x;
@@ -74,7 +74,7 @@ class Rect extends Polygon {
74
74
  * @public
75
75
  * @type {number}
76
76
  * @name right
77
- * @memberof Rect
77
+ * @memberof Rect.prototype
78
78
  */
79
79
  get right() {
80
80
  var w = this.width;
@@ -86,7 +86,7 @@ class Rect extends Polygon {
86
86
  * @public
87
87
  * @type {number}
88
88
  * @name top
89
- * @memberof Rect
89
+ * @memberof Rect.prototype
90
90
  */
91
91
  get top() {
92
92
  return this.pos.y;
@@ -97,7 +97,7 @@ class Rect extends Polygon {
97
97
  * @public
98
98
  * @type {number}
99
99
  * @name bottom
100
- * @memberof Rect
100
+ * @memberof Rect.prototype
101
101
  */
102
102
  get bottom() {
103
103
  var h = this.height;
@@ -109,7 +109,7 @@ class Rect extends Polygon {
109
109
  * @public
110
110
  * @type {number}
111
111
  * @name width
112
- * @memberof Rect
112
+ * @memberof Rect.prototype
113
113
  */
114
114
  get width() {
115
115
  return this.points[2].x;
@@ -125,7 +125,7 @@ class Rect extends Polygon {
125
125
  * @public
126
126
  * @type {number}
127
127
  * @name height
128
- * @memberof Rect
128
+ * @memberof Rect.prototype
129
129
  */
130
130
  get height() {
131
131
  return this.points[2].y;
@@ -141,7 +141,7 @@ class Rect extends Polygon {
141
141
  * @public
142
142
  * @type {number}
143
143
  * @name centerX
144
- * @memberof Rect
144
+ * @memberof Rect.prototype
145
145
  */
146
146
  get centerX() {
147
147
  if (isFinite(this.width)) {
@@ -159,7 +159,7 @@ class Rect extends Polygon {
159
159
  * @public
160
160
  * @type {number}
161
161
  * @name centerY
162
- * @memberof Rect
162
+ * @memberof Rect.prototype
163
163
  */
164
164
  get centerY() {
165
165
  if (isFinite(this.height)) {
@@ -172,6 +172,21 @@ class Rect extends Polygon {
172
172
  this.pos.y = value - (this.height / 2);
173
173
  }
174
174
 
175
+ /**
176
+ * center the rectangle position around the given coordinates
177
+ * @name centerOn
178
+ * @memberof Rect.prototype
179
+ * @function
180
+ * @param {number} x the x coordinate around which to center this rectangle
181
+ * @param {number} x the y coordinate around which to center this rectangle
182
+ * @returns {Rect} this rectangle
183
+ */
184
+ centerOn(x, y) {
185
+ this.centerX = x;
186
+ this.centerY = y;
187
+ return this;
188
+ }
189
+
175
190
  /**
176
191
  * resize the rectangle
177
192
  * @name resize
@@ -286,7 +301,7 @@ class Rect extends Polygon {
286
301
  /**
287
302
  * Returns true if the rectangle contains the given point
288
303
  * @name contains
289
- * @memberof Rect
304
+ * @memberof Rect.prototype
290
305
  * @function
291
306
  * @param {Vector2d} point
292
307
  * @returns {boolean} true if contains
@@ -355,7 +370,7 @@ class Rect extends Polygon {
355
370
  * @returns {Polygon} a new Polygon that represents this rectangle.
356
371
  */
357
372
  toPolygon() {
358
- return new Polygon(
373
+ return pool.pull("Polygon",
359
374
  this.pos.x, this.pos.y, this.points
360
375
  );
361
376
  }
@@ -0,0 +1,67 @@
1
+ import Rect from "./rectangle.js";
2
+
3
+ // https://developer.chrome.com/blog/canvas2d/#round-rect
4
+
5
+ /**
6
+ * @classdesc
7
+ * a rectangle object with rounded corners
8
+ * @augments Rect
9
+ */
10
+ class RoundRect extends Rect {
11
+ /**
12
+ * @param {number} x position of the rounded rectangle
13
+ * @param {number} y position of the rounded rectangle
14
+ * @param {number} width the rectangle width
15
+ * @param {number} height the rectangle height
16
+ * @param {number} [radius=20] the radius of the rounded corner
17
+ */
18
+ constructor(x, y, width, height, radius = 20) {
19
+ // parent constructor
20
+ super(x, y, width, height);
21
+
22
+ // set the corner radius
23
+ this.radius = radius;
24
+ }
25
+
26
+ /** @ignore */
27
+ onResetEvent(x, y, w, h, radius) {
28
+ super.setShape(x, y, w, h);
29
+ this.radius = radius;
30
+ }
31
+
32
+
33
+ /**
34
+ * the radius of the rounded corner
35
+ * @public
36
+ * @type {number}
37
+ * @default 20
38
+ * @name radius
39
+ * @memberof RoundRect.prototype
40
+ */
41
+ get radius() {
42
+ return this._radius;
43
+ }
44
+ set radius(value) {
45
+ // verify the rectangle is at least as wide and tall as the rounded corners.
46
+ if (this.width < 2 * value) {
47
+ value = this.width / 2;
48
+ }
49
+ if (this.height < 2 * value) {
50
+ value = this.height / 2;
51
+ }
52
+ this._radius = value;
53
+ }
54
+
55
+ /**
56
+ * clone this RoundRect
57
+ * @name clone
58
+ * @memberof RoundRect.prototype
59
+ * @function
60
+ * @returns {RoundRect} new RoundRect
61
+ */
62
+ clone() {
63
+ return new RoundRect(this.pos.x, this.pos.y, this.width, this.height, this.radius);
64
+ }
65
+ };
66
+
67
+ export default RoundRect;
package/src/index.js CHANGED
@@ -1,6 +1,5 @@
1
- // ES5 polyfills
2
- import "./polyfill/console.js";
3
- import "./polyfill/requestAnimationFrame.js";
1
+ // ES5/ES6 polyfills
2
+ import "./polyfill/index.js";
4
3
 
5
4
  // utility classes
6
5
  import * as audio from "./audio/audio.js";
@@ -16,7 +15,7 @@ import { plugin, plugins } from "./plugin/plugin.js";
16
15
  import * as video from "./video/video.js";
17
16
  import save from "./system/save.js";
18
17
  import timer from "./system/timer.js";
19
- import * as pool from "./system/pooling.js";
18
+ import pool from "./system/pooling.js";
20
19
  import state from "./state/state.js";
21
20
  import level from "./level/level.js";
22
21
 
@@ -32,6 +31,7 @@ import Polygon from "./geometries/poly.js";
32
31
  import Line from "./geometries/line.js";
33
32
  import Ellipse from "./geometries/ellipse.js";
34
33
  import Rect from "./geometries/rectangle.js";
34
+ import RoundRect from "./geometries/roundrect.js";
35
35
  import QuadTree from "./physics/quadtree.js";
36
36
  import Body from "./physics/body.js";
37
37
  import Bounds from "./physics/bounds.js";
@@ -69,7 +69,8 @@ import Stage from "./state/stage.js";
69
69
  import Camera2d from "./camera/camera2d.js";
70
70
  import Container from "./renderable/container.js";
71
71
  import World from "./physics/world.js";
72
- import { ParticleEmitterSettings, ParticleEmitter } from "./particles/emitter.js";
72
+ import ParticleEmitterSettings from "./particles/settings.js";
73
+ import ParticleEmitter from "./particles/emitter.js";
73
74
  import Particle from "./particles/particle.js";
74
75
  import Entity from "./entity/entity.js";
75
76
 
@@ -117,6 +118,7 @@ export {
117
118
  Line,
118
119
  Ellipse,
119
120
  Rect,
121
+ RoundRect,
120
122
  Tween,
121
123
  QuadTree,
122
124
  GLShader,
@@ -218,6 +220,7 @@ export function boot() {
218
220
  pool.register("me.Matrix2d", Matrix2d, true);
219
221
  pool.register("me.Matrix3d", Matrix3d, true);
220
222
  pool.register("me.Rect", Rect, true);
223
+ pool.register("me.RoundRect", RoundRect, true);
221
224
  pool.register("me.Polygon", Polygon, true);
222
225
  pool.register("me.Line", Line, true);
223
226
  pool.register("me.Ellipse", Ellipse, true);
@@ -245,6 +248,7 @@ export function boot() {
245
248
  pool.register("Matrix2d", Matrix2d, true);
246
249
  pool.register("Matrix3d", Matrix3d, true);
247
250
  pool.register("Rect", Rect, true);
251
+ pool.register("RoundRect", RoundRect, true);
248
252
  pool.register("Polygon", Polygon, true);
249
253
  pool.register("Line", Line, true);
250
254
  pool.register("Ellipse", Ellipse, true);
@@ -265,17 +265,19 @@ var updateGamepads = function () {
265
265
  * gamepad connected callback
266
266
  * @ignore
267
267
  */
268
- window.addEventListener("gamepadconnected", function (e) {
269
- event.emit(event.GAMEPAD_CONNECTED, e.gamepad);
270
- }, false);
268
+ if (globalThis.navigator && typeof globalThis.navigator.getGamepads === "function") {
269
+ globalThis.addEventListener("gamepadconnected", function (e) {
270
+ event.emit(event.GAMEPAD_CONNECTED, e.gamepad);
271
+ }, false);
271
272
 
272
- /**
273
- * gamepad disconnected callback
274
- * @ignore
275
- */
276
- window.addEventListener("gamepaddisconnected", function (e) {
277
- event.emit(event.GAMEPAD_DISCONNECTED, e.gamepad);
278
- }, false);
273
+ /**
274
+ * gamepad disconnected callback
275
+ * @ignore
276
+ */
277
+ globalThis.addEventListener("gamepaddisconnected", function (e) {
278
+ event.emit(event.GAMEPAD_DISCONNECTED, e.gamepad);
279
+ }, false);
280
+ }
279
281
 
280
282
  /*
281
283
  * PUBLIC STUFF
@@ -319,9 +319,11 @@ export var KEY = {
319
319
  export function initKeyboardEvent() {
320
320
  // make sure the keyboard is enable
321
321
  if (keyBoardEventTarget === null && device.isMobile === false) {
322
- keyBoardEventTarget = window;
323
- keyBoardEventTarget.addEventListener("keydown", keyDownEvent, false);
324
- keyBoardEventTarget.addEventListener("keyup", keyUpEvent, false);
322
+ keyBoardEventTarget = globalThis;
323
+ if (typeof keyBoardEventTarget.addEventListener === "function") {
324
+ keyBoardEventTarget.addEventListener("keydown", keyDownEvent, false);
325
+ keyBoardEventTarget.addEventListener("keyup", keyUpEvent, false);
326
+ }
325
327
  }
326
328
  };
327
329
 
@@ -334,7 +334,7 @@ class Pointer extends Bounds {
334
334
  this.gameScreenY = this.y = tmpVec.y;
335
335
 
336
336
  // true if not originally a pointer event
337
- this.isNormalized = !device.PointerEvent || (device.PointerEvent && !(event instanceof window.PointerEvent));
337
+ this.isNormalized = !device.PointerEvent || (device.PointerEvent && !(event instanceof globalThis.PointerEvent));
338
338
 
339
339
  this.locked = locked;
340
340
  this.movementX = event.movementX || 0;
@@ -5,7 +5,7 @@ import { throttle } from "./../utils/function.js";
5
5
  import { remove } from "./../utils/array.js";
6
6
  import * as event from "./../system/event.js";
7
7
  import timer from "./../system/timer.js";
8
- import * as pool from "./../system/pooling.js";
8
+ import pool from "./../system/pooling.js";
9
9
  import device from "./../system/device.js";
10
10
  import Pointer from "./pointer.js";
11
11
  import Rect from "./../geometries/rectangle.js";
@@ -559,8 +559,8 @@ export function globalToLocal(x, y, v) {
559
559
  v = v || pool.pull("Vector2d");
560
560
  var rect = device.getElementBounds(renderer.getScreenCanvas());
561
561
  var pixelRatio = device.devicePixelRatio;
562
- x -= rect.left + (window.pageXOffset || 0);
563
- y -= rect.top + (window.pageYOffset || 0);
562
+ x -= rect.left + (globalThis.pageXOffset || 0);
563
+ y -= rect.top + (globalThis.pageYOffset || 0);
564
564
  var scale = scaleRatio;
565
565
  if (scale.x !== 1.0 || scale.y !== 1.0) {
566
566
  x /= scale.x;
@@ -783,7 +783,6 @@ export function releaseAllPointerEvents(region) {
783
783
  * @memberof input
784
784
  * @public
785
785
  * @function
786
- * @param {Function} [success] callback if the request is successful
787
786
  * @returns {boolean} return true if the request was successfully submitted
788
787
  * @example
789
788
  * // register on the pointer lock change event
@@ -74,7 +74,7 @@ device.turnOffPointerLock = function () {
74
74
  /**
75
75
  * @public
76
76
  * @name Texture
77
- * @memberof Renderer
77
+ * @memberof Renderer#
78
78
  * @deprecated since 10.4.0
79
79
  * @see TextureAtlas
80
80
  */
@@ -1,5 +1,5 @@
1
1
  import { createCanvas } from "./../../video/video.js";
2
- import * as pool from "./../../system/pooling.js";
2
+ import pool from "./../../system/pooling.js";
3
3
  import * as TMXUtils from "./TMXUtils.js";
4
4
  import Tile from "./TMXTile.js";
5
5
  import Renderable from "./../../renderable/renderable.js";
@@ -1,9 +1,6 @@
1
- import Vector2d from "./../../math/vector2.js";
1
+ import pool from "./../../system/pooling.js";
2
2
  import { applyTMXProperties } from "./TMXUtils.js";
3
3
  import Tile from "./TMXTile.js";
4
- import Ellipse from "./../../geometries/ellipse.js";
5
- import Polygon from "./../../geometries/poly.js";
6
- import Line from "./../../geometries/line.js";
7
4
  import { degToRad } from "./../../math/math.js";
8
5
 
9
6
  /**
@@ -260,7 +257,7 @@ export default class TMXObject {
260
257
  // add an ellipse shape
261
258
  if (this.isEllipse === true) {
262
259
  // ellipse coordinates are the center position, so set default to the corresonding radius
263
- shapes.push((new Ellipse(
260
+ shapes.push((pool.pull("Ellipse",
264
261
  this.width / 2,
265
262
  this.height / 2,
266
263
  this.width,
@@ -270,7 +267,7 @@ export default class TMXObject {
270
267
 
271
268
  // add a polygon
272
269
  if (this.isPolygon === true) {
273
- var _polygon = new Polygon(0, 0, this.points);
270
+ var _polygon = pool.pull("Polygon", 0, 0, this.points);
274
271
  // make sure it's a convex polygon
275
272
  if (_polygon.isConvex() === false ) {
276
273
  throw new Error("collision polygones in Tiled should be defined as Convex");
@@ -286,22 +283,22 @@ export default class TMXObject {
286
283
  for (i = 0; i < segments; i++) {
287
284
  // clone the value before, as [i + 1]
288
285
  // is reused later by the next segment
289
- p1 = new Vector2d(p[i].x, p[i].y);
290
- p2 = new Vector2d(p[i + 1].x, p[i + 1].y);
286
+ p1 = pool.pull("Vector2d", p[i].x, p[i].y);
287
+ p2 = pool.pull("Vector2d", p[i + 1].x, p[i + 1].y);
291
288
  if (this.rotation !== 0) {
292
289
  p1 = p1.rotate(this.rotation);
293
290
  p2 = p2.rotate(this.rotation);
294
291
  }
295
- shapes.push(new Line(0, 0, [ p1, p2 ]));
292
+ shapes.push(pool.pull("Line", 0, 0, [ p1, p2 ]));
296
293
  }
297
294
  }
298
295
 
299
296
  // it's a rectangle, returns a polygon object anyway
300
297
  else {
301
- shapes.push((new Polygon(
298
+ shapes.push((pool.pull("Polygon",
302
299
  0, 0, [
303
- new Vector2d(), new Vector2d(this.width, 0),
304
- new Vector2d(this.width, this.height), new Vector2d(0, this.height)
300
+ pool.pull("Vector2d"), pool.pull("Vector2d", this.width, 0),
301
+ pool.pull("Vector2d", this.width, this.height), pool.pull("Vector2d", 0, this.height)
305
302
  ]
306
303
  )).rotate(this.rotation));
307
304
  }
@@ -1,4 +1,4 @@
1
- import * as pool from "./../../system/pooling.js";
1
+ import pool from "./../../system/pooling.js";
2
2
  import * as event from "./../../system/event.js";
3
3
  import { viewport } from "./../../game.js";
4
4
  import collision from "./../../physics/collision.js";
@@ -14,7 +14,6 @@ import TMXLayer from "./TMXLayer.js";
14
14
  import { applyTMXProperties } from "./TMXUtils.js";
15
15
  import Renderable from "./../../renderable/renderable.js";
16
16
  import Container from "./../../renderable/container.js";
17
- import Rect from "./../../geometries/rectangle.js";
18
17
 
19
18
  // constant to identify the collision object layer
20
19
  var COLLISION_GROUP = "collision";
@@ -474,6 +473,8 @@ class TMXTileMap {
474
473
  var settings = group.objects[o];
475
474
  // reference to the instantiated object
476
475
  var obj;
476
+ // a reference to the default shape
477
+ var shape;
477
478
 
478
479
  // Tiled uses 0,0 by default
479
480
  if (typeof (settings.anchorPoint) === "undefined") {
@@ -506,9 +507,18 @@ class TMXTileMap {
506
507
  // set the obj z order
507
508
  obj.pos.z = settings.z;
508
509
  } else if (typeof settings.tile === "object") {
510
+ // create a default shape if none is specified
511
+ shape = settings.shapes;
512
+ if (typeof shape === "undefined") {
513
+ shape = pool.pull("Polygon", 0, 0, [
514
+ pool.pull("Vector2d", 0, 0),
515
+ pool.pull("Vector2d", this.width, 0),
516
+ pool.pull("Vector2d", this.width, this.height)
517
+ ]);
518
+ }
509
519
  // check if a me.Tile object is embedded
510
520
  obj = settings.tile.getRenderable(settings);
511
- obj.body = new Body(obj, settings.shapes || new Rect(0, 0, this.width, this.height));
521
+ obj.body = new Body(obj, shape);
512
522
  obj.body.setStatic(true);
513
523
  // set the obj z order
514
524
  obj.pos.setMuted(settings.x, settings.y, settings.z);
@@ -527,11 +537,20 @@ class TMXTileMap {
527
537
  settings.x, settings.y,
528
538
  settings.width, settings.height
529
539
  );
540
+ // create a default shape if none is specified
541
+ shape = settings.shapes;
542
+ if (typeof shape === "undefined") {
543
+ shape = pool.pull("Polygon", 0, 0, [
544
+ pool.pull("Vector2d", 0, 0),
545
+ pool.pull("Vector2d", this.width, 0),
546
+ pool.pull("Vector2d", this.width, this.height)
547
+ ]);
548
+ }
530
549
  obj.anchorPoint.set(0, 0);
531
550
  obj.name = settings.name;
532
551
  obj.type = settings.type;
533
552
  obj.id = settings.id;
534
- obj.body = new Body(obj, settings.shapes || new Rect(0, 0, obj.width, obj.height));
553
+ obj.body = new Body(obj, shape);
535
554
  obj.body.setStatic(true);
536
555
  obj.resize(obj.body.getBounds().width, obj.body.getBounds().height);
537
556
  }
@@ -138,7 +138,7 @@ export function decodeBase64AsArray(input, bytes) {
138
138
  bytes = bytes || 1;
139
139
 
140
140
  var i, j, len;
141
- var dec = window.atob(input.replace(/[^A-Za-z0-9\+\/\=]/g, ""));
141
+ var dec = globalThis.atob(input.replace(/[^A-Za-z0-9\+\/\=]/g, ""));
142
142
  var ar = new Uint32Array(dec.length / bytes);
143
143
 
144
144
  for (i = 0, len = dec.length / bytes; i < len; i++) {
@@ -1,5 +1,5 @@
1
1
  import Vector2d from "./../../../math/vector2.js";
2
- import * as pool from "./../../../system/pooling.js";
2
+ import pool from "./../../../system/pooling.js";
3
3
  import TMXRenderer from "./TMXRenderer.js";
4
4
  import TMXLayer from "./../TMXLayer.js";
5
5
 
@@ -1,5 +1,5 @@
1
1
  import Vector2d from "./../../../math/vector2.js";
2
- import * as pool from "./../../../system/pooling.js";
2
+ import pool from "./../../../system/pooling.js";
3
3
  import TMXRenderer from "./TMXRenderer.js";
4
4
  import TMXLayer from "./../TMXLayer.js";
5
5
 
@@ -1,5 +1,5 @@
1
1
  import Vector2d from "./../../../math/vector2.js";
2
- import * as pool from "./../../../system/pooling.js";
2
+ import pool from "./../../../system/pooling.js";
3
3
  import TMXRenderer from "./TMXRenderer.js";
4
4
 
5
5
  /**
@@ -1,6 +1,6 @@
1
1
  /* eslint-disable no-unused-vars */
2
2
 
3
- import * as pool from "./../../../system/pooling.js";
3
+ import pool from "./../../../system/pooling.js";
4
4
  import TMXLayer from "./../TMXLayer.js";
5
5
  import Bounds from "./../../../physics/Bounds.js";
6
6
 
@@ -1,5 +1,5 @@
1
1
  import Vector2d from "./../../../math/vector2.js";
2
- import * as pool from "./../../../system/pooling.js";
2
+ import pool from "./../../../system/pooling.js";
3
3
  import TMXHexagonalRenderer from "./TMXHexagonalRenderer.js";
4
4
  import { degToRad } from "./../../../math/math.js";
5
5
 
@@ -46,7 +46,7 @@ function checkLoadStatus(onload) {
46
46
  }
47
47
  }
48
48
  else {
49
- timerId = setTimeout(function() {
49
+ timerId = setTimeout(() => {
50
50
  checkLoadStatus(onload);
51
51
  }, 100);
52
52
  }
@@ -85,7 +85,7 @@ function preloadImage(img, onload, onerror) {
85
85
  function preloadFontFace(data, onload, onerror) {
86
86
  var font = new FontFace(data.name, data.src);
87
87
  // loading promise
88
- font.load().then(function() {
88
+ font.load().then(() => {
89
89
  // apply the font after the font has finished downloading
90
90
  document.fonts.add(font);
91
91
  document.body.style.fontFamily = data.name;
@@ -154,7 +154,7 @@ function preloadTMX(tmxData, onload, onerror) {
154
154
  case "tsx":
155
155
  // ie9 does not fully implement the responseXML
156
156
  if (device.ua.match(/msie/i) || !xmlhttp.responseXML) {
157
- if (window.DOMParser) {
157
+ if (globalThis.DOMParser) {
158
158
  // manually create the XML DOM
159
159
  result = (new DOMParser()).parseFromString(xmlhttp.responseText, "text/xml");
160
160
  } else {
@@ -278,12 +278,12 @@ function preloadJavascript(data, onload, onerror) {
278
278
  }
279
279
  script.defer = true;
280
280
 
281
- script.onload = function() {
281
+ script.onload = () => {
282
282
  // callback
283
283
  onload();
284
284
  };
285
285
 
286
- script.onerror = function() {
286
+ script.onerror = () => {
287
287
  // callback
288
288
  onerror(data.name);
289
289
  };
@@ -2,7 +2,7 @@ import { world, viewport } from "./../game.js";
2
2
  import { createCanvas, renderer } from "./../video/video.js";
3
3
  import * as event from "./../system/event.js";
4
4
  import {nextPowerOfTwo} from "./../math/math.js";
5
- import * as pool from "./../system/pooling.js";
5
+ import pool from "./../system/pooling.js";
6
6
  import Renderable from "./../renderable/renderable.js";
7
7
  import Stage from "./../state/stage.js";
8
8
 
package/src/math/color.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { clamp, random } from "./math.js";
2
- import * as pool from "./../system/pooling.js";
2
+ import pool from "./../system/pooling.js";
3
3
 
4
4
  // convert a give color component to it hexadecimal value
5
5
  var toHex = function (component) {
@@ -1,4 +1,4 @@
1
- import * as pool from "./../system/pooling.js";
1
+ import pool from "./../system/pooling.js";
2
2
  import Matrix3d from "./matrix3.js";
3
3
 
4
4
  /**