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,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
 
@@ -1,10 +1,10 @@
1
- if (typeof window !== "undefined") {
2
- if (typeof window.console === "undefined") {
3
- window.console = {};
4
- window.console.log = function() {};
5
- window.console.assert = function() {};
6
- window.console.warn = function() {};
7
- window.console.error = function() {
1
+ if (typeof globalThis !== "undefined") {
2
+ if (typeof globalThis.console === "undefined") {
3
+ globalThis.console = {};
4
+ globalThis.console.log = function() {};
5
+ globalThis.console.assert = function() {};
6
+ globalThis.console.warn = function() {};
7
+ globalThis.console.error = function() {
8
8
  alert(Array.prototype.slice.call(arguments).join(", "));
9
9
  };
10
10
  }
@@ -0,0 +1,7 @@
1
+ // https://github.com/melonjs/melonJS/issues/1092
2
+ import "core-js/proposals/global-this";
3
+
4
+ // "built-in" polyfills
5
+ import "./console.js";
6
+ import "./performance.js";
7
+ import "./requestAnimationFrame.js";
@@ -0,0 +1,20 @@
1
+ if ("performance" in globalThis === false) {
2
+ globalThis.performance = {};
3
+ }
4
+
5
+ Date.now = (Date.now || function () { // thanks IE8
6
+ return new Date().getTime();
7
+ });
8
+
9
+ if ("now" in globalThis.performance === false) {
10
+
11
+ var nowOffset = Date.now();
12
+
13
+ if (performance.timing && performance.timing.navigationStart) {
14
+ nowOffset = performance.timing.navigationStart;
15
+ }
16
+
17
+ globalThis.performance.now = function now() {
18
+ return Date.now() - nowOffset;
19
+ };
20
+ }
@@ -6,23 +6,23 @@ var x;
6
6
 
7
7
  // standardized functions
8
8
  // https://developer.mozilla.org/fr/docs/Web/API/Window/requestAnimationFrame
9
- var requestAnimationFrame = window.requestAnimationFrame;
10
- var cancelAnimationFrame = window.cancelAnimationFrame;
9
+ var requestAnimationFrame = globalThis.requestAnimationFrame;
10
+ var cancelAnimationFrame = globalThis.cancelAnimationFrame;
11
11
 
12
12
  // get prefixed rAF and cAF is standard one not supported
13
13
  for (x = 0; x < vendors.length && !requestAnimationFrame; ++x) {
14
- requestAnimationFrame = window[vendors[x] + "RequestAnimationFrame"];
14
+ requestAnimationFrame = globalThis[vendors[x] + "RequestAnimationFrame"];
15
15
  }
16
16
  for (x = 0; x < vendors.length && !cancelAnimationFrame; ++x) {
17
- cancelAnimationFrame = window[vendors[x] + "CancelAnimationFrame"] ||
18
- window[vendors[x] + "CancelRequestAnimationFrame"];
17
+ cancelAnimationFrame = globalThis[vendors[x] + "CancelAnimationFrame"] ||
18
+ globalThis[vendors[x] + "CancelRequestAnimationFrame"];
19
19
  }
20
20
 
21
21
  if (!requestAnimationFrame || !cancelAnimationFrame) {
22
22
  requestAnimationFrame = function (callback) {
23
- var currTime = window.performance.now();
23
+ var currTime = globalThis.performance.now();
24
24
  var timeToCall = Math.max(0, (1000 / timer.maxfps) - (currTime - lastTime));
25
- var id = window.setTimeout(function () {
25
+ var id = globalThis.setTimeout(function () {
26
26
  callback(currTime + timeToCall);
27
27
  }, timeToCall);
28
28
  lastTime = currTime + timeToCall;
@@ -30,10 +30,10 @@ if (!requestAnimationFrame || !cancelAnimationFrame) {
30
30
  };
31
31
 
32
32
  cancelAnimationFrame = function (id) {
33
- window.clearTimeout(id);
33
+ globalThis.clearTimeout(id);
34
34
  };
35
35
 
36
36
  // put back in global namespace
37
- window.requestAnimationFrame = requestAnimationFrame;
38
- window.cancelAnimationFrame = cancelAnimationFrame;
37
+ globalThis.requestAnimationFrame = requestAnimationFrame;
38
+ globalThis.cancelAnimationFrame = cancelAnimationFrame;
39
39
  }
@@ -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";
@@ -93,7 +93,7 @@ class ImageLayer extends Sprite {
93
93
  this.repeat = settings.repeat || "repeat";
94
94
 
95
95
  // on context lost, all previous textures are destroyed
96
- event.on(event.WEBGL_ONCONTEXT_RESTORED, this.createPattern, this);
96
+ event.on(event.ONCONTEXT_RESTORED, this.createPattern, this);
97
97
  }
98
98
 
99
99
  /**
@@ -294,7 +294,7 @@ class ImageLayer extends Sprite {
294
294
  destroy() {
295
295
  pool.push(this.ratio);
296
296
  this.ratio = undefined;
297
- event.off(event.WEBGL_ONCONTEXT_RESTORED, this.createPattern);
297
+ event.off(event.ONCONTEXT_RESTORED, this.createPattern);
298
298
  super.destroy();
299
299
  }
300
300
 
@@ -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
 
@@ -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
  */
@@ -45,7 +45,7 @@ function _startRunLoop() {
45
45
  timer.reset();
46
46
 
47
47
  // start the main loop
48
- _animFrameId = window.requestAnimationFrame(_renderFrame);
48
+ _animFrameId = globalThis.requestAnimationFrame(_renderFrame);
49
49
  }
50
50
  }
51
51
 
@@ -85,7 +85,7 @@ function _renderFrame(time) {
85
85
  game.draw(stage);
86
86
  // schedule the next frame update
87
87
  if (_animFrameId !== -1) {
88
- _animFrameId = window.requestAnimationFrame(_renderFrame);
88
+ _animFrameId = globalThis.requestAnimationFrame(_renderFrame);
89
89
  }
90
90
  }
91
91
 
@@ -95,7 +95,7 @@ function _renderFrame(time) {
95
95
  */
96
96
  function _stopRunLoop() {
97
97
  // cancel any previous animationRequestFrame
98
- window.cancelAnimationFrame(_animFrameId);
98
+ globalThis.cancelAnimationFrame(_animFrameId);
99
99
  _animFrameId = -1;
100
100
  }
101
101
 
@@ -268,7 +268,7 @@ var state = {
268
268
  }
269
269
 
270
270
  // store time when stopped
271
- _pauseTime = window.performance.now();
271
+ _pauseTime = globalThis.performance.now();
272
272
 
273
273
  // publish the stop notification
274
274
  event.emit(event.STATE_STOP);
@@ -294,7 +294,7 @@ var state = {
294
294
  }
295
295
 
296
296
  // store time when paused
297
- _pauseTime = window.performance.now();
297
+ _pauseTime = globalThis.performance.now();
298
298
 
299
299
  // publish the pause event
300
300
  event.emit(event.STATE_PAUSE);
@@ -319,7 +319,7 @@ var state = {
319
319
  }
320
320
 
321
321
  // calculate the elpased time
322
- _pauseTime = window.performance.now() - _pauseTime;
322
+ _pauseTime = globalThis.performance.now() - _pauseTime;
323
323
 
324
324
  // force repaint
325
325
  game.repaint();
@@ -347,7 +347,7 @@ var state = {
347
347
  }
348
348
 
349
349
  // calculate the elpased time
350
- _pauseTime = window.performance.now() - _pauseTime;
350
+ _pauseTime = globalThis.performance.now() - _pauseTime;
351
351
 
352
352
  // publish the resume event
353
353
  event.emit(event.STATE_RESUME, _pauseTime);
@@ -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(