melonjs 10.7.0 → 10.9.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 (66) hide show
  1. package/dist/melonjs.js +1488 -666
  2. package/dist/melonjs.min.js +4 -4
  3. package/dist/melonjs.module.d.ts +929 -202
  4. package/dist/melonjs.module.js +1575 -777
  5. package/package.json +9 -9
  6. package/src/camera/camera2d.js +1 -1
  7. package/src/entity/entity.js +6 -7
  8. package/src/geometries/ellipse.js +10 -11
  9. package/src/geometries/line.js +3 -3
  10. package/src/geometries/path2d.js +319 -0
  11. package/src/geometries/poly.js +11 -11
  12. package/src/geometries/rectangle.js +15 -15
  13. package/src/geometries/roundrect.js +164 -0
  14. package/src/index.js +5 -1
  15. package/src/input/gamepad.js +2 -2
  16. package/src/input/pointerevent.js +1 -1
  17. package/src/lang/deprecated.js +1 -1
  18. package/src/level/tiled/TMXLayer.js +1 -1
  19. package/src/level/tiled/TMXObject.js +9 -12
  20. package/src/level/tiled/TMXTileMap.js +23 -4
  21. package/src/level/tiled/renderer/TMXHexagonalRenderer.js +1 -1
  22. package/src/level/tiled/renderer/TMXIsometricRenderer.js +1 -1
  23. package/src/level/tiled/renderer/TMXOrthogonalRenderer.js +1 -1
  24. package/src/level/tiled/renderer/TMXRenderer.js +1 -1
  25. package/src/level/tiled/renderer/TMXStaggeredRenderer.js +1 -1
  26. package/src/loader/loader.js +4 -4
  27. package/src/loader/loadingscreen.js +1 -1
  28. package/src/math/color.js +1 -1
  29. package/src/math/matrix2.js +1 -1
  30. package/src/math/matrix3.js +1 -1
  31. package/src/math/observable_vector2.js +1 -1
  32. package/src/math/observable_vector3.js +1 -1
  33. package/src/math/vector2.js +1 -1
  34. package/src/math/vector3.js +1 -1
  35. package/src/particles/emitter.js +23 -14
  36. package/src/particles/particle.js +3 -2
  37. package/src/physics/body.js +67 -51
  38. package/src/physics/bounds.js +8 -9
  39. package/src/physics/world.js +1 -1
  40. package/src/polyfill/index.js +1 -0
  41. package/src/polyfill/roundrect.js +235 -0
  42. package/src/renderable/collectable.js +9 -2
  43. package/src/renderable/colorlayer.js +1 -1
  44. package/src/renderable/container.js +1 -1
  45. package/src/renderable/imagelayer.js +1 -1
  46. package/src/renderable/renderable.js +2 -2
  47. package/src/renderable/sprite.js +2 -3
  48. package/src/renderable/trigger.js +10 -4
  49. package/src/state/stage.js +1 -1
  50. package/src/state/state.js +1 -1
  51. package/src/system/device.js +10 -8
  52. package/src/system/pooling.js +156 -149
  53. package/src/text/bitmaptext.js +1 -1
  54. package/src/text/text.js +1 -1
  55. package/src/utils/utils.js +2 -2
  56. package/src/video/canvas/canvas_renderer.js +83 -39
  57. package/src/video/renderer.js +36 -16
  58. package/src/video/texture.js +1 -1
  59. package/src/video/webgl/glshader.js +29 -193
  60. package/src/video/webgl/utils/attributes.js +16 -0
  61. package/src/video/webgl/utils/precision.js +11 -0
  62. package/src/video/webgl/utils/program.js +58 -0
  63. package/src/video/webgl/utils/string.js +16 -0
  64. package/src/video/webgl/utils/uniforms.js +87 -0
  65. package/src/video/webgl/webgl_compositor.js +1 -14
  66. package/src/video/webgl/webgl_renderer.js +124 -182
@@ -1,8 +1,8 @@
1
- import Vector2d from "./../math/vector2.js";
2
1
  import Rect from "./../geometries/rectangle.js";
3
2
  import Ellipse from "./../geometries/ellipse.js";
4
3
  import Polygon from "./../geometries/poly.js";
5
4
  import Bounds from "./bounds.js";
5
+ import pool from "./../system/pooling.js";
6
6
  import collision from "./collision.js";
7
7
  import * as arrayUtil from "./../utils/array.js";
8
8
  import timer from "./../system/timer.js";
@@ -37,7 +37,7 @@ class Body {
37
37
  * @public
38
38
  * @type {Bounds}
39
39
  */
40
- this.bounds = new Bounds();
40
+ this.bounds = pool.pull("Bounds");
41
41
  }
42
42
 
43
43
  if (typeof this.shapes === "undefined") {
@@ -71,55 +71,54 @@ class Body {
71
71
  */
72
72
  this.collisionType = collision.types.ENEMY_OBJECT;
73
73
 
74
- /**
75
- * body velocity
76
- * @public
77
- * @type {Vector2d}
78
- * @default <0,0>
79
- */
80
74
  if (typeof this.vel === "undefined") {
81
- this.vel = new Vector2d();
75
+ /**
76
+ * body velocity
77
+ * @public
78
+ * @type {Vector2d}
79
+ * @default <0,0>
80
+ */
81
+ this.vel = pool.pull("Vector2d");
82
82
  }
83
83
  this.vel.set(0, 0);
84
84
 
85
- /**
86
- * body force or acceleration (automatically) applied to the body.
87
- * when defining a force, user should also define a max velocity
88
- * @public
89
- * @type {Vector2d}
90
- * @default <0,0>
91
- * @see Body.setMaxVelocity
92
- * @example
93
- * // define a default maximum acceleration, initial force and friction
94
- * this.body.force.set(0, 0);
95
- * this.body.friction.set(0.4, 0);
96
- * this.body.setMaxVelocity(3, 15);
97
- *
98
- * // apply a postive or negative force when pressing left of right key
99
- * update(dt) {
100
- * if (me.input.isKeyPressed("left")) {
101
- * this.body.force.x = -this.body.maxVel.x;
102
- * } else if (me.input.isKeyPressed("right")) {
103
- * this.body.force.x = this.body.maxVel.x;
104
- * } else {
105
- * this.body.force.x = 0;
106
- * }
107
- * }
108
- */
109
85
  if (typeof this.force === "undefined") {
110
- this.force = new Vector2d();
86
+ /**
87
+ * body force or acceleration (automatically) applied to the body.
88
+ * when defining a force, user should also define a max velocity
89
+ * @public
90
+ * @type {Vector2d}
91
+ * @default <0,0>
92
+ * @see Body.setMaxVelocity
93
+ * @example
94
+ * // define a default maximum acceleration, initial force and friction
95
+ * this.body.force.set(0, 0);
96
+ * this.body.friction.set(0.4, 0);
97
+ * this.body.setMaxVelocity(3, 15);
98
+ *
99
+ * // apply a postive or negative force when pressing left of right key
100
+ * update(dt) {
101
+ * if (me.input.isKeyPressed("left")) {
102
+ * this.body.force.x = -this.body.maxVel.x;
103
+ * } else if (me.input.isKeyPressed("right")) {
104
+ * this.body.force.x = this.body.maxVel.x;
105
+ * } else {
106
+ * this.body.force.x = 0;
107
+ * }
108
+ * }
109
+ */
110
+ this.force = pool.pull("Vector2d");
111
111
  }
112
112
  this.force.set(0, 0);
113
113
 
114
-
115
- /**
116
- * body friction
117
- * @public
118
- * @type {Vector2d}
119
- * @default <0,0>
120
- */
121
114
  if (typeof this.friction === "undefined") {
122
- this.friction = new Vector2d();
115
+ /**
116
+ * body friction
117
+ * @public
118
+ * @type {Vector2d}
119
+ * @default <0,0>
120
+ */
121
+ this.friction = pool.pull("Vector2d");
123
122
  }
124
123
  this.friction.set(0, 0);
125
124
 
@@ -140,14 +139,14 @@ class Body {
140
139
  */
141
140
  this.mass = 1;
142
141
 
143
- /**
144
- * max velocity (to limit body velocity)
145
- * @public
146
- * @type {Vector2d}
147
- * @default <490,490>
148
- */
149
142
  if (typeof this.maxVel === "undefined") {
150
- this.maxVel = new Vector2d();
143
+ /**
144
+ * max velocity (to limit body velocity)
145
+ * @public
146
+ * @type {Vector2d}
147
+ * @default <490,490>
148
+ */
149
+ this.maxVel = pool.pull("Vector2d");
151
150
  }
152
151
  // cap by default to half the default gravity force
153
152
  this.maxVel.set(490, 490);
@@ -297,7 +296,7 @@ class Body {
297
296
  polygon.setShape(0, 0, vertices);
298
297
  } else {
299
298
  // this will replace any other non polygon shape type if defined
300
- this.shapes[index] = new Polygon(0, 0, vertices);
299
+ this.shapes[index] = pool.pull("Polygon", 0, 0, vertices);
301
300
  }
302
301
 
303
302
  // update the body bounds to take in account the new vertices
@@ -686,11 +685,28 @@ class Body {
686
685
  * @ignore
687
686
  */
688
687
  destroy() {
688
+ // push back instance into object pool
689
+ pool.push(this.bounds);
690
+ pool.push(this.vel);
691
+ pool.push(this.force);
692
+ pool.push(this.friction);
693
+ pool.push(this.maxVel);
694
+ this.shapes.forEach((shape) => {
695
+ pool.push(shape);
696
+ });
697
+
698
+ // set to undefined
689
699
  this.onBodyUpdate = undefined;
690
700
  this.ancestor = undefined;
691
701
  this.bounds = undefined;
692
- this.setStatic(false);
702
+ this.vel = undefined;
703
+ this.force = undefined;
704
+ this.friction = undefined;
705
+ this.maxVel = undefined;
693
706
  this.shapes.length = 0;
707
+
708
+ // reset some variable to default
709
+ this.setStatic(false);
694
710
  }
695
711
  };
696
712
 
@@ -1,5 +1,5 @@
1
+ import pool from "./../system/pooling.js";
1
2
  import Vector2d from "./../math/vector2.js";
2
- import Polygon from "./../geometries/poly.js";
3
3
 
4
4
  /**
5
5
  * @classdesc
@@ -10,6 +10,8 @@ class Bounds {
10
10
  * @param {Vector2d[]} [vertices] an array of me.Vector2d points
11
11
  */
12
12
  constructor(vertices) {
13
+ // @ignore
14
+ this._center = new Vector2d();
13
15
  this.onResetEvent(vertices);
14
16
  }
15
17
 
@@ -26,9 +28,6 @@ class Bounds {
26
28
  if (typeof vertices !== "undefined") {
27
29
  this.update(vertices);
28
30
  }
29
-
30
- // @ignore
31
- this._center = new Vector2d();
32
31
  }
33
32
 
34
33
  /**
@@ -450,11 +449,11 @@ class Bounds {
450
449
  * @returns {Polygon} a new Polygon that represents this bounds.
451
450
  */
452
451
  toPolygon () {
453
- return new Polygon(this.x, this.y, [
454
- new Vector2d(0, 0),
455
- new Vector2d(this.width, 0),
456
- new Vector2d(this.width, this.height),
457
- new Vector2d(0, this.height)
452
+ return pool.pull("Polygon", this.x, this.y, [
453
+ pool.pull("Vector2d", 0, 0),
454
+ pool.pull("Vector2d", this.width, 0),
455
+ pool.pull("Vector2d", this.width, this.height),
456
+ pool.pull("Vector2d", 0, this.height)
458
457
  ]);
459
458
  }
460
459
 
@@ -69,7 +69,7 @@ class World extends Container {
69
69
  * @name bodies
70
70
  * @memberof World
71
71
  * @public
72
- * @type {Set}
72
+ * @type {Set<Body>}
73
73
  */
74
74
  this.bodies = new Set();
75
75
 
@@ -5,3 +5,4 @@ import "core-js/proposals/global-this";
5
5
  import "./console.js";
6
6
  import "./performance.js";
7
7
  import "./requestAnimationFrame.js";
8
+ import "./roundrect.js";
@@ -0,0 +1,235 @@
1
+ /*
2
+ * based on https://www.npmjs.com/package/canvas-roundrect-polyfill
3
+ * @version 0.0.1
4
+ */
5
+ (() => {
6
+
7
+ "use strict";
8
+
9
+ /** @ignore */
10
+ function roundRect(x, y, w, h, radii) {
11
+
12
+ if (!([x, y, w, h].every((input) => Number.isFinite(input)))) {
13
+
14
+ return;
15
+
16
+ }
17
+
18
+ radii = parseRadiiArgument(radii);
19
+
20
+ let upperLeft, upperRight, lowerRight, lowerLeft;
21
+
22
+ if (radii.length === 4) {
23
+
24
+ upperLeft = toCornerPoint(radii[0]);
25
+ upperRight = toCornerPoint(radii[1]);
26
+ lowerRight = toCornerPoint(radii[2]);
27
+ lowerLeft = toCornerPoint(radii[3]);
28
+
29
+ } else if (radii.length === 3) {
30
+
31
+ upperLeft = toCornerPoint(radii[0]);
32
+ upperRight = toCornerPoint(radii[1]);
33
+ lowerLeft = toCornerPoint(radii[1]);
34
+ lowerRight = toCornerPoint(radii[2]);
35
+
36
+ } else if (radii.length === 2) {
37
+
38
+ upperLeft = toCornerPoint(radii[0]);
39
+ lowerRight = toCornerPoint(radii[0]);
40
+ upperRight = toCornerPoint(radii[1]);
41
+ lowerLeft = toCornerPoint(radii[1]);
42
+
43
+ } else if (radii.length === 1) {
44
+
45
+ upperLeft = toCornerPoint(radii[0]);
46
+ upperRight = toCornerPoint(radii[0]);
47
+ lowerRight = toCornerPoint(radii[0]);
48
+ lowerLeft = toCornerPoint(radii[0]);
49
+
50
+ } else {
51
+
52
+ throw new Error(radii.length + " is not a valid size for radii sequence.");
53
+
54
+ }
55
+
56
+ const corners = [upperLeft, upperRight, lowerRight, lowerLeft];
57
+ const negativeCorner = corners.find(({x, y}) => x < 0 || y < 0);
58
+ //const negativeValue = negativeCorner?.x < 0 ? negativeCorner.x : negativeCorner?.y
59
+
60
+ if (corners.some(({x, y}) => !Number.isFinite(x) || !Number.isFinite(y))) {
61
+
62
+ return;
63
+
64
+ }
65
+
66
+ if (negativeCorner) {
67
+
68
+ throw new Error("Radius value " + negativeCorner + " is negative.");
69
+
70
+ }
71
+
72
+ fixOverlappingCorners(corners);
73
+
74
+ if (w < 0 && h < 0) {
75
+
76
+ this.moveTo(x - upperLeft.x, y);
77
+ this.ellipse(x + w + upperRight.x, y - upperRight.y, upperRight.x, upperRight.y, 0, -Math.PI * 1.5, -Math.PI);
78
+ this.ellipse(x + w + lowerRight.x, y + h + lowerRight.y, lowerRight.x, lowerRight.y, 0, -Math.PI, -Math.PI / 2);
79
+ this.ellipse(x - lowerLeft.x, y + h + lowerLeft.y, lowerLeft.x, lowerLeft.y, 0, -Math.PI / 2, 0);
80
+ this.ellipse(x - upperLeft.x, y - upperLeft.y, upperLeft.x, upperLeft.y, 0, 0, -Math.PI / 2);
81
+
82
+ } else if (w < 0) {
83
+
84
+ this.moveTo(x - upperLeft.x, y);
85
+ this.ellipse(x + w + upperRight.x, y + upperRight.y, upperRight.x, upperRight.y, 0, -Math.PI / 2, -Math.PI, 1);
86
+ this.ellipse(x + w + lowerRight.x, y + h - lowerRight.y, lowerRight.x, lowerRight.y, 0, -Math.PI, -Math.PI * 1.5, 1);
87
+ this.ellipse(x - lowerLeft.x, y + h - lowerLeft.y, lowerLeft.x, lowerLeft.y, 0, Math.PI / 2, 0, 1);
88
+ this.ellipse(x - upperLeft.x, y + upperLeft.y, upperLeft.x, upperLeft.y, 0, 0, -Math.PI / 2, 1);
89
+
90
+ } else if (h < 0) {
91
+
92
+ this.moveTo(x + upperLeft.x, y);
93
+ this.ellipse(x + w - upperRight.x, y - upperRight.y, upperRight.x, upperRight.y, 0, Math.PI / 2, 0, 1);
94
+ this.ellipse(x + w - lowerRight.x, y + h + lowerRight.y, lowerRight.x, lowerRight.y, 0, 0, -Math.PI / 2, 1);
95
+ this.ellipse(x + lowerLeft.x, y + h + lowerLeft.y, lowerLeft.x, lowerLeft.y, 0, -Math.PI / 2, -Math.PI, 1);
96
+ this.ellipse(x + upperLeft.x, y - upperLeft.y, upperLeft.x, upperLeft.y, 0, -Math.PI, -Math.PI * 1.5, 1);
97
+
98
+ } else {
99
+
100
+ this.moveTo(x + upperLeft.x, y);
101
+ this.ellipse(x + w - upperRight.x, y + upperRight.y, upperRight.x, upperRight.y, 0, -Math.PI / 2, 0);
102
+ this.ellipse(x + w - lowerRight.x, y + h - lowerRight.y, lowerRight.x, lowerRight.y, 0, 0, Math.PI / 2);
103
+ this.ellipse(x + lowerLeft.x, y + h - lowerLeft.y, lowerLeft.x, lowerLeft.y, 0, Math.PI / 2, Math.PI);
104
+ this.ellipse(x + upperLeft.x, y + upperLeft.y, upperLeft.x, upperLeft.y, 0, Math.PI, Math.PI * 1.5);
105
+
106
+ }
107
+
108
+ this.closePath();
109
+ this.moveTo(x, y);
110
+
111
+ /** @ignore */
112
+ function toDOMPointInit(value) {
113
+
114
+ const {x, y, z, w} = value;
115
+ return {x, y, z, w};
116
+
117
+ }
118
+
119
+ /** @ignore */
120
+ function parseRadiiArgument(value) {
121
+
122
+ // https://webidl.spec.whatwg.org/#es-union
123
+ // with 'optional (unrestricted double or DOMPointInit
124
+ // or sequence<(unrestricted double or DOMPointInit)>) radii = 0'
125
+ const type = typeof value;
126
+
127
+ if (type === "undefined" || value === null) {
128
+
129
+ return [0];
130
+
131
+ }
132
+ if (type === "function") {
133
+
134
+ return [NaN];
135
+
136
+ }
137
+ if (type === "object") {
138
+
139
+ if (typeof value[Symbol.iterator] === "function") {
140
+
141
+ return [...value].map((elem) => {
142
+ // https://webidl.spec.whatwg.org/#es-union
143
+ // with '(unrestricted double or DOMPointInit)'
144
+ const elemType = typeof elem;
145
+ if (elemType === "undefined" || elem === null) {
146
+ return 0;
147
+ }
148
+ if (elemType === "function") {
149
+ return NaN;
150
+ }
151
+ if (elemType === "object") {
152
+ return toDOMPointInit(elem);
153
+ }
154
+ return toUnrestrictedNumber(elem);
155
+ });
156
+
157
+ }
158
+
159
+ return [toDOMPointInit(value)];
160
+
161
+ }
162
+
163
+ return [toUnrestrictedNumber(value)];
164
+
165
+ }
166
+
167
+ /** @ignore */
168
+ function toUnrestrictedNumber(value) {
169
+
170
+ return +value;
171
+
172
+ }
173
+
174
+ /** @ignore */
175
+ function toCornerPoint(value) {
176
+
177
+ const asNumber = toUnrestrictedNumber(value);
178
+ if (Number.isFinite(asNumber)) {
179
+
180
+ return {
181
+ x: asNumber,
182
+ y: asNumber
183
+ };
184
+
185
+ }
186
+ if (Object(value) === value) {
187
+
188
+ return {
189
+ x: toUnrestrictedNumber(value.x || 0),
190
+ y: toUnrestrictedNumber(value.y || 0)
191
+ };
192
+
193
+ }
194
+
195
+ return {
196
+ x: NaN,
197
+ y: NaN
198
+ };
199
+
200
+ }
201
+
202
+ /** @ignore */
203
+ function fixOverlappingCorners(corners) {
204
+ const [upperLeft, upperRight, lowerRight, lowerLeft] = corners;
205
+ const factors = [
206
+ Math.abs(w) / (upperLeft.x + upperRight.x),
207
+ Math.abs(h) / (upperRight.y + lowerRight.y),
208
+ Math.abs(w) / (lowerRight.x + lowerLeft.x),
209
+ Math.abs(h) / (upperLeft.y + lowerLeft.y)
210
+ ];
211
+ const minFactor = Math.min(...factors);
212
+ if (minFactor <= 1) {
213
+ corners.forEach((radii) => {
214
+ radii.x *= minFactor;
215
+ radii.y *= minFactor;
216
+ });
217
+ }
218
+ }
219
+ }
220
+
221
+ if (typeof Path2D.prototype.roundRect === "undefined") {
222
+ Path2D.prototype.roundRect = roundRect;
223
+ }
224
+ if (globalThis.CanvasRenderingContext2D) {
225
+ if (typeof globalThis.CanvasRenderingContext2D.prototype.roundRect === "undefined") {
226
+ globalThis.CanvasRenderingContext2D.prototype.roundRect = roundRect;
227
+ }
228
+ }
229
+ if (globalThis.OffscreenCanvasRenderingContext2D) {
230
+ if (typeof globalThis.OffscreenCanvasRenderingContext2D.prototype.roundRect === "undefined") {
231
+ globalThis.OffscreenCanvasRenderingContext2D.prototype.roundRect = roundRect;
232
+ }
233
+ }
234
+
235
+ })();
@@ -1,6 +1,5 @@
1
1
  import Sprite from "./sprite.js";
2
2
  import Body from "./../physics/body.js";
3
- import Rect from "./../geometries/rectangle.js";
4
3
  import collision from "./../physics/collision.js";
5
4
 
6
5
  /**
@@ -24,7 +23,15 @@ class Collectable extends Sprite {
24
23
  this.id = settings.id;
25
24
 
26
25
  // add and configure the physic body
27
- this.body = new Body(this, settings.shapes || new Rect(0, 0, this.width, this.height));
26
+ var shape = settings.shapes;
27
+ if (typeof shape === "undefined") {
28
+ shape = pool.pull("Polygon", 0, 0, [
29
+ pool.pull("Vector2d", 0, 0),
30
+ pool.pull("Vector2d", this.width, 0),
31
+ pool.pull("Vector2d", this.width, this.height)
32
+ ]);
33
+ }
34
+ this.body = new Body(this, shape);
28
35
  this.body.collisionType = collision.types.COLLECTABLE_OBJECT;
29
36
  // by default only collides with PLAYER_OBJECT
30
37
  this.body.setCollisionMask(collision.types.PLAYER_OBJECT);
@@ -1,4 +1,4 @@
1
- import * as pool from "./../system/pooling.js";
1
+ import pool from "./../system/pooling.js";
2
2
  import { viewport } from "./../game.js";
3
3
  import Renderable from "./renderable.js";
4
4
 
@@ -1,7 +1,7 @@
1
1
  import utils from "./../utils/utils.js";
2
2
  import * as game from "./../game.js";
3
3
  import * as event from "./../system/event.js";
4
- import * as pool from "./../system/pooling.js";
4
+ import pool from "./../system/pooling.js";
5
5
  import state from "./../state/state.js";
6
6
  import Renderable from "./renderable.js";
7
7
  import Body from "./../physics/body.js";
@@ -1,6 +1,6 @@
1
1
  import { renderer } from "./../video/video.js";
2
2
  import * as event from "./../system/event.js";
3
- import * as pool from "./../system/pooling.js";
3
+ import pool from "./../system/pooling.js";
4
4
  import { viewport } from "./../game.js";
5
5
  import Sprite from "./sprite.js";
6
6
  import * as stringUtil from "./../utils/string.js";
@@ -2,7 +2,7 @@ import ObservableVector2d from "./../math/observable_vector2.js";
2
2
  import ObservableVector3d from "./../math/observable_vector3.js";
3
3
  import Rect from "./../geometries/rectangle.js";
4
4
  import Container from "./container.js";
5
- import * as pool from "./../system/pooling.js";
5
+ import pool from "./../system/pooling.js";
6
6
  import { releaseAllPointerEvents } from "./../input/input.js";
7
7
  import { clamp } from "./../math/math.js";
8
8
 
@@ -227,7 +227,7 @@ class Renderable extends Rect {
227
227
  * A mask limits rendering elements to the shape and position of the given mask object.
228
228
  * So, if the renderable is larger than the mask, only the intersecting part of the renderable will be visible.
229
229
  * @public
230
- * @type {Rect|Polygon|Line|Ellipse}
230
+ * @type {Rect|RoundRect|Polygon|Line|Ellipse}
231
231
  * @name mask
232
232
  * @default undefined
233
233
  * @memberof Renderable#
@@ -1,6 +1,5 @@
1
- import Vector2d from "./../math/vector2.js";
2
1
  import { renderer } from "./../video/video.js";
3
- import * as pool from "./../system/pooling.js";
2
+ import pool from "./../system/pooling.js";
4
3
  import loader from "./../loader/loader.js";
5
4
  import { TextureAtlas } from "./../video/texture.js";
6
5
  import Renderable from "./renderable.js";
@@ -99,7 +98,7 @@ class Sprite extends Renderable {
99
98
  // length of the current animation name
100
99
  length : 0,
101
100
  //current frame texture offset
102
- offset : new Vector2d(),
101
+ offset : pool.pull("Vector2d"),
103
102
  // current frame size
104
103
  width : 0,
105
104
  height : 0,
@@ -1,7 +1,6 @@
1
1
  import Renderable from "./renderable.js";
2
2
  import collision from "./../physics/collision.js";
3
3
  import Body from "./../physics/body.js";
4
- import Rect from "./../geometries/rectangle.js";
5
4
  import level from "./../level/level.js";
6
5
  import { world, viewport } from "./../game.js";
7
6
 
@@ -66,9 +65,16 @@ class Trigger extends Renderable {
66
65
  }
67
66
  }.bind(this));
68
67
 
69
-
70
- // physic body to check for collision against
71
- this.body = new Body(this, settings.shapes || new Rect(0, 0, this.width, this.height));
68
+ // add and configure the physic body
69
+ var shape = settings.shapes;
70
+ if (typeof shape === "undefined") {
71
+ shape = pool.pull("Polygon", 0, 0, [
72
+ pool.pull("Vector2d", 0, 0),
73
+ pool.pull("Vector2d", this.width, 0),
74
+ pool.pull("Vector2d", this.width, this.height)
75
+ ]);
76
+ }
77
+ this.body = new Body(this, shape);
72
78
  this.body.collisionType = collision.types.ACTION_OBJECT;
73
79
  // by default only collides with PLAYER_OBJECT
74
80
  this.body.setCollisionMask(collision.types.PLAYER_OBJECT);
@@ -31,7 +31,7 @@ class Stage {
31
31
  * Cameras will be renderered based on this order defined in this list.
32
32
  * Only the "default" camera will be resized when the window or canvas is resized.
33
33
  * @public
34
- * @type {Map}
34
+ * @type {Map<Camera2d>}
35
35
  * @name cameras
36
36
  * @memberof Stage
37
37
  */
@@ -512,7 +512,7 @@ var state = {
512
512
  // if fading effect
513
513
  if (_fade.duration && _stages[state].transition) {
514
514
  /** @ignore */
515
- _onSwitchComplete = function() {
515
+ _onSwitchComplete = () => {
516
516
  game.viewport.fadeOut(_fade.color, _fade.duration);
517
517
  };
518
518
  game.viewport.fadeIn(
@@ -112,12 +112,6 @@ function _checkCapabilities() {
112
112
  // detect device type/platform
113
113
  _detectDevice();
114
114
 
115
- // Mobile browser hacks
116
- if (device.isMobile) {
117
- // Prevent the webview from moving on a swipe
118
- device.enableSwipe(false);
119
- }
120
-
121
115
  // Touch/Gesture Event feature detection
122
116
  device.TouchEvent = !!("ontouchstart" in globalThis);
123
117
  device.PointerEvent = !!globalThis.PointerEvent;
@@ -239,6 +233,13 @@ function _checkCapabilities() {
239
233
  );
240
234
  }
241
235
  }
236
+
237
+ // Mobile browser hacks
238
+ if (device.isMobile) {
239
+ // Prevent the webview from moving on a swipe
240
+ device.enableSwipe(false);
241
+ }
242
+
242
243
  };
243
244
 
244
245
 
@@ -676,13 +677,14 @@ let device = {
676
677
  * @param {boolean} [enable=true] enable or disable swipe.
677
678
  */
678
679
  enableSwipe(enable) {
680
+ var moveEvent = device.PointerEvent ? "pointermove" : (device.TouchEvent ? "touchmove" : "mousemove");
679
681
  if (enable !== false) {
680
682
  if (swipeEnabled === false) {
681
- globalThis.document.removeEventListener("touchmove", _disableSwipeFn, false);
683
+ globalThis.document.removeEventListener(moveEvent, _disableSwipeFn);
682
684
  swipeEnabled = true;
683
685
  }
684
686
  } else if (swipeEnabled === true) {
685
- globalThis.document.addEventListener("touchmove", _disableSwipeFn, false);
687
+ globalThis.document.addEventListener(moveEvent, _disableSwipeFn, { passive: false });
686
688
  swipeEnabled = false;
687
689
  }
688
690
  },