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.
- package/dist/melonjs.js +37947 -36530
- package/dist/melonjs.min.js +22 -22
- package/dist/melonjs.module.d.ts +1352 -307
- package/dist/melonjs.module.js +2929 -1501
- package/package.json +14 -12
- package/src/camera/camera2d.js +1 -1
- package/src/entity/entity.js +6 -7
- package/src/game.js +5 -5
- package/src/geometries/ellipse.js +10 -11
- package/src/geometries/line.js +3 -3
- package/src/geometries/path2d.js +319 -0
- package/src/geometries/poly.js +11 -11
- package/src/geometries/rectangle.js +30 -15
- package/src/geometries/roundrect.js +67 -0
- package/src/index.js +9 -5
- package/src/input/gamepad.js +12 -10
- package/src/input/keyboard.js +5 -3
- package/src/input/pointer.js +1 -1
- package/src/input/pointerevent.js +3 -4
- package/src/lang/deprecated.js +1 -1
- package/src/level/tiled/TMXLayer.js +1 -1
- package/src/level/tiled/TMXObject.js +9 -12
- package/src/level/tiled/TMXTileMap.js +23 -4
- package/src/level/tiled/TMXUtils.js +1 -1
- package/src/level/tiled/renderer/TMXHexagonalRenderer.js +1 -1
- package/src/level/tiled/renderer/TMXIsometricRenderer.js +1 -1
- package/src/level/tiled/renderer/TMXOrthogonalRenderer.js +1 -1
- package/src/level/tiled/renderer/TMXRenderer.js +1 -1
- package/src/level/tiled/renderer/TMXStaggeredRenderer.js +1 -1
- package/src/loader/loader.js +5 -5
- package/src/loader/loadingscreen.js +1 -1
- package/src/math/color.js +1 -1
- package/src/math/matrix2.js +1 -1
- package/src/math/matrix3.js +67 -66
- package/src/math/observable_vector2.js +1 -1
- package/src/math/observable_vector3.js +1 -1
- package/src/math/vector2.js +1 -1
- package/src/math/vector3.js +1 -1
- package/src/particles/emitter.js +130 -430
- package/src/particles/particle.js +53 -53
- package/src/particles/settings.js +310 -0
- package/src/physics/body.js +67 -51
- package/src/physics/bounds.js +8 -9
- package/src/physics/world.js +1 -1
- package/src/polyfill/console.js +7 -7
- package/src/polyfill/index.js +7 -0
- package/src/polyfill/performance.js +20 -0
- package/src/polyfill/requestAnimationFrame.js +10 -10
- package/src/renderable/collectable.js +9 -2
- package/src/renderable/colorlayer.js +1 -1
- package/src/renderable/container.js +1 -1
- package/src/renderable/imagelayer.js +3 -3
- package/src/renderable/renderable.js +1 -1
- package/src/renderable/sprite.js +2 -3
- package/src/renderable/trigger.js +10 -4
- package/src/state/stage.js +1 -1
- package/src/state/state.js +8 -8
- package/src/system/device.js +148 -133
- package/src/system/event.js +10 -10
- package/src/system/pooling.js +156 -149
- package/src/system/timer.js +1 -1
- package/src/text/bitmaptext.js +1 -1
- package/src/text/text.js +1 -1
- package/src/utils/agent.js +4 -4
- package/src/utils/function.js +2 -2
- package/src/utils/utils.js +10 -5
- package/src/video/canvas/canvas_renderer.js +104 -36
- package/src/video/renderer.js +28 -16
- package/src/video/texture.js +1 -1
- package/src/video/video.js +11 -11
- package/src/video/webgl/glshader.js +30 -194
- package/src/video/webgl/utils/attributes.js +16 -0
- package/src/video/webgl/utils/precision.js +11 -0
- package/src/video/webgl/utils/program.js +58 -0
- package/src/video/webgl/utils/string.js +16 -0
- package/src/video/webgl/utils/uniforms.js +87 -0
- package/src/video/webgl/webgl_compositor.js +1 -14
- package/src/video/webgl/webgl_renderer.js +129 -186
- package/src/particles/particlecontainer.js +0 -95
package/src/physics/bounds.js
CHANGED
|
@@ -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
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
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
|
|
package/src/physics/world.js
CHANGED
package/src/polyfill/console.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
if (typeof
|
|
2
|
-
if (typeof
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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,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 =
|
|
10
|
-
var 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 =
|
|
14
|
+
requestAnimationFrame = globalThis[vendors[x] + "RequestAnimationFrame"];
|
|
15
15
|
}
|
|
16
16
|
for (x = 0; x < vendors.length && !cancelAnimationFrame; ++x) {
|
|
17
|
-
cancelAnimationFrame =
|
|
18
|
-
|
|
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 =
|
|
23
|
+
var currTime = globalThis.performance.now();
|
|
24
24
|
var timeToCall = Math.max(0, (1000 / timer.maxfps) - (currTime - lastTime));
|
|
25
|
-
var id =
|
|
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
|
-
|
|
33
|
+
globalThis.clearTimeout(id);
|
|
34
34
|
};
|
|
35
35
|
|
|
36
36
|
// put back in global namespace
|
|
37
|
-
|
|
38
|
-
|
|
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
|
-
|
|
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,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
|
|
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
|
|
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.
|
|
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.
|
|
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
|
|
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
|
|
package/src/renderable/sprite.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import Vector2d from "./../math/vector2.js";
|
|
2
1
|
import { renderer } from "./../video/video.js";
|
|
3
|
-
import
|
|
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 :
|
|
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
|
-
|
|
71
|
-
|
|
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);
|
package/src/state/stage.js
CHANGED
|
@@ -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
|
*/
|
package/src/state/state.js
CHANGED
|
@@ -45,7 +45,7 @@ function _startRunLoop() {
|
|
|
45
45
|
timer.reset();
|
|
46
46
|
|
|
47
47
|
// start the main loop
|
|
48
|
-
_animFrameId =
|
|
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 =
|
|
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
|
-
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
515
|
+
_onSwitchComplete = () => {
|
|
516
516
|
game.viewport.fadeOut(_fade.color, _fade.duration);
|
|
517
517
|
};
|
|
518
518
|
game.viewport.fadeIn(
|