melonjs 10.6.0 → 10.7.1
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 +37468 -36530
- package/dist/melonjs.min.js +21 -21
- package/dist/melonjs.module.d.ts +369 -164
- package/dist/melonjs.module.js +1750 -793
- package/package.json +10 -8
- package/src/game.js +5 -5
- package/src/geometries/rectangle.js +15 -0
- package/src/index.js +4 -4
- 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 +2 -3
- package/src/level/tiled/TMXUtils.js +1 -1
- package/src/loader/loader.js +1 -1
- package/src/math/matrix3.js +66 -65
- package/src/particles/emitter.js +119 -428
- package/src/particles/particle.js +51 -52
- package/src/particles/settings.js +310 -0
- 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/imagelayer.js +2 -2
- package/src/state/state.js +7 -7
- package/src/system/device.js +141 -128
- package/src/system/event.js +10 -10
- package/src/system/timer.js +1 -1
- package/src/text/bitmaptext.js +5 -5
- 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 +15 -2
- package/src/video/renderer.js +2 -2
- package/src/video/video.js +11 -11
- package/src/video/webgl/glshader.js +1 -1
- package/src/video/webgl/webgl_renderer.js +6 -5
- package/src/particles/particlecontainer.js +0 -95
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "melonjs",
|
|
3
|
-
"version": "10.
|
|
3
|
+
"version": "10.7.1",
|
|
4
4
|
"description": "melonJS Game Engine",
|
|
5
5
|
"homepage": "http://www.melonjs.org/",
|
|
6
6
|
"keywords": [
|
|
@@ -38,7 +38,8 @@
|
|
|
38
38
|
"engines": {
|
|
39
39
|
"node": ">= 12"
|
|
40
40
|
},
|
|
41
|
-
"main": "dist/melonjs.js",
|
|
41
|
+
"main": "dist/melonjs.module.js",
|
|
42
|
+
"type": "module",
|
|
42
43
|
"module": "dist/melonjs.module.js",
|
|
43
44
|
"files": [
|
|
44
45
|
"dist/melonjs.js",
|
|
@@ -54,6 +55,7 @@
|
|
|
54
55
|
],
|
|
55
56
|
"dependencies": {
|
|
56
57
|
"@teppeis/multimaps": "^2.0.0",
|
|
58
|
+
"core-js": "^3.22.4",
|
|
57
59
|
"earcut": "2.2.3",
|
|
58
60
|
"eventemitter3": "^4.0.7",
|
|
59
61
|
"howler": "2.2.3"
|
|
@@ -61,13 +63,13 @@
|
|
|
61
63
|
"devDependencies": {
|
|
62
64
|
"@rollup/plugin-buble": "^0.21.3",
|
|
63
65
|
"@rollup/plugin-commonjs": "^22.0.0",
|
|
64
|
-
"@rollup/plugin-node-resolve": "^13.
|
|
66
|
+
"@rollup/plugin-node-resolve": "^13.3.0",
|
|
65
67
|
"@rollup/plugin-replace": "^4.0.0",
|
|
66
68
|
"@types/offscreencanvas": "^2019.6.4",
|
|
67
69
|
"cheerio": "^1.0.0-rc.10",
|
|
68
70
|
"del-cli": "^4.0.1",
|
|
69
71
|
"eslint": "^8.14.0",
|
|
70
|
-
"eslint-plugin-jsdoc": "^39.2.
|
|
72
|
+
"eslint-plugin-jsdoc": "^39.2.9",
|
|
71
73
|
"jasmine-core": "^4.1.0",
|
|
72
74
|
"jsdoc": "^3.6.10",
|
|
73
75
|
"karma": "^6.3.19",
|
|
@@ -77,18 +79,18 @@
|
|
|
77
79
|
"karma-jasmine": "^5.0.0",
|
|
78
80
|
"karma-nyan-reporter": "0.2.5",
|
|
79
81
|
"qs": "^6.10.3",
|
|
80
|
-
"rollup": "^2.
|
|
82
|
+
"rollup": "^2.71.1",
|
|
81
83
|
"rollup-plugin-bundle-size": "^1.0.3",
|
|
82
84
|
"rollup-plugin-string": "^3.0.0",
|
|
83
|
-
"terser": "^5.
|
|
84
|
-
"typescript": "^4.6.
|
|
85
|
+
"terser": "^5.13.1",
|
|
86
|
+
"typescript": "^4.6.4"
|
|
85
87
|
},
|
|
86
88
|
"scripts": {
|
|
87
89
|
"build": "npm run lint && rollup -c --silent",
|
|
88
90
|
"dist": " npm run build && npm run minify && mkdirp dist && cp -f build/*.js dist/ && npm run types",
|
|
89
91
|
"minify": "terser build/melonjs.js --compress --mangle --comments '/(?:^!|@(?:license|preserve|cc_on))/' --output build/melonjs.min.js",
|
|
90
92
|
"lint": "eslint src rollup.config.js",
|
|
91
|
-
"test": "npm run build && karma start tests/karma.conf.
|
|
93
|
+
"test": "npm run build && karma start tests/karma.conf.cjs",
|
|
92
94
|
"doc": "mkdirp docs && jsdoc -c jsdoc_conf.json",
|
|
93
95
|
"release": "npm run dist && npm publish --access public",
|
|
94
96
|
"clean": "del-cli --force build/*.js dist/*.js dist/*.d.ts docs src/**/*.d.ts",
|
package/src/game.js
CHANGED
|
@@ -94,7 +94,7 @@ export let sortOn = "z";
|
|
|
94
94
|
* @name lastUpdate
|
|
95
95
|
* @memberof game
|
|
96
96
|
*/
|
|
97
|
-
export let lastUpdate =
|
|
97
|
+
export let lastUpdate = globalThis.performance.now();
|
|
98
98
|
|
|
99
99
|
/**
|
|
100
100
|
* Fired when a level is fully loaded and all entities instantiated. <br>
|
|
@@ -188,7 +188,7 @@ export function update(time, stage) {
|
|
|
188
188
|
accumulatorUpdateDelta = (timer.interpolation) ? updateDelta : Math.max(updateDelta, updateAverageDelta);
|
|
189
189
|
|
|
190
190
|
while (accumulator >= accumulatorUpdateDelta || timer.interpolation) {
|
|
191
|
-
lastUpdateStart =
|
|
191
|
+
lastUpdateStart = globalThis.performance.now();
|
|
192
192
|
|
|
193
193
|
// game update event
|
|
194
194
|
if (state.isPaused() !== true) {
|
|
@@ -198,7 +198,7 @@ export function update(time, stage) {
|
|
|
198
198
|
// update all objects (and pass the elapsed time since last frame)
|
|
199
199
|
isDirty = stage.update(updateDelta) || isDirty;
|
|
200
200
|
|
|
201
|
-
lastUpdate =
|
|
201
|
+
lastUpdate = globalThis.performance.now();
|
|
202
202
|
updateAverageDelta = lastUpdate - lastUpdateStart;
|
|
203
203
|
|
|
204
204
|
accumulator -= accumulatorUpdateDelta;
|
|
@@ -223,7 +223,7 @@ export function draw(stage) {
|
|
|
223
223
|
|
|
224
224
|
if (renderer.isContextValid === true && (isDirty || isAlwaysDirty)) {
|
|
225
225
|
// publish notification
|
|
226
|
-
event.emit(event.GAME_BEFORE_DRAW,
|
|
226
|
+
event.emit(event.GAME_BEFORE_DRAW, globalThis.performance.now());
|
|
227
227
|
|
|
228
228
|
// prepare renderer to draw a new frame
|
|
229
229
|
renderer.clear();
|
|
@@ -238,6 +238,6 @@ export function draw(stage) {
|
|
|
238
238
|
renderer.flush();
|
|
239
239
|
|
|
240
240
|
// publish notification
|
|
241
|
-
event.emit(event.GAME_AFTER_DRAW,
|
|
241
|
+
event.emit(event.GAME_AFTER_DRAW, globalThis.performance.now());
|
|
242
242
|
}
|
|
243
243
|
};
|
|
@@ -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
|
package/src/index.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
// ES5 polyfills
|
|
2
|
-
import "./polyfill/
|
|
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";
|
|
@@ -69,7 +68,8 @@ import Stage from "./state/stage.js";
|
|
|
69
68
|
import Camera2d from "./camera/camera2d.js";
|
|
70
69
|
import Container from "./renderable/container.js";
|
|
71
70
|
import World from "./physics/world.js";
|
|
72
|
-
import
|
|
71
|
+
import ParticleEmitterSettings from "./particles/settings.js";
|
|
72
|
+
import ParticleEmitter from "./particles/emitter.js";
|
|
73
73
|
import Particle from "./particles/particle.js";
|
|
74
74
|
import Entity from "./entity/entity.js";
|
|
75
75
|
|
package/src/input/gamepad.js
CHANGED
|
@@ -265,17 +265,19 @@ var updateGamepads = function () {
|
|
|
265
265
|
* gamepad connected callback
|
|
266
266
|
* @ignore
|
|
267
267
|
*/
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
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
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
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
|
package/src/input/keyboard.js
CHANGED
|
@@ -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 =
|
|
323
|
-
keyBoardEventTarget.addEventListener
|
|
324
|
-
|
|
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
|
|
package/src/input/pointer.js
CHANGED
|
@@ -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
|
|
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;
|
|
@@ -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 + (
|
|
563
|
-
y -= rect.top + (
|
|
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
|
|
@@ -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 =
|
|
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++) {
|
package/src/loader/loader.js
CHANGED
|
@@ -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 (
|
|
157
|
+
if (globalThis.DOMParser) {
|
|
158
158
|
// manually create the XML DOM
|
|
159
159
|
result = (new DOMParser()).parseFromString(xmlhttp.responseText, "text/xml");
|
|
160
160
|
} else {
|
package/src/math/matrix3.js
CHANGED
|
@@ -475,72 +475,73 @@ class Matrix3d {
|
|
|
475
475
|
* @returns {Matrix3d} Reference to this object for method chaining
|
|
476
476
|
*/
|
|
477
477
|
rotate(angle, v) {
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
// Construct the elements of the rotation matrix
|
|
520
|
-
b00 = x * x * t + c;
|
|
521
|
-
b01 = y * x * t + z * s;
|
|
522
|
-
b02 = z * x * t - y * s;
|
|
523
|
-
b10 = x * y * t - z * s;
|
|
524
|
-
b11 = y * y * t + c;
|
|
525
|
-
b12 = z * y * t + x * s;
|
|
526
|
-
b20 = x * z * t + y * s;
|
|
527
|
-
b21 = y * z * t - x * s;
|
|
528
|
-
b22 = z * z * t + c;
|
|
529
|
-
|
|
530
|
-
// Perform rotation-specific matrix multiplication
|
|
531
|
-
a[0] = a00 * b00 + a10 * b01 + a20 * b02;
|
|
532
|
-
a[1] = a01 * b00 + a11 * b01 + a21 * b02;
|
|
533
|
-
a[2] = a02 * b00 + a12 * b01 + a22 * b02;
|
|
534
|
-
a[3] = a03 * b00 + a13 * b01 + a23 * b02;
|
|
535
|
-
a[4] = a00 * b10 + a10 * b11 + a20 * b12;
|
|
536
|
-
a[5] = a01 * b10 + a11 * b11 + a21 * b12;
|
|
537
|
-
a[6] = a02 * b10 + a12 * b11 + a22 * b12;
|
|
538
|
-
a[7] = a03 * b10 + a13 * b11 + a23 * b12;
|
|
539
|
-
a[8] = a00 * b20 + a10 * b21 + a20 * b22;
|
|
540
|
-
a[9] = a01 * b20 + a11 * b21 + a21 * b22;
|
|
541
|
-
a[10] = a02 * b20 + a12 * b21 + a22 * b22;
|
|
542
|
-
a[11] = a03 * b20 + a13 * b21 + a23 * b22;
|
|
478
|
+
if (angle !== 0) {
|
|
479
|
+
var a = this.val,
|
|
480
|
+
x = v.x,
|
|
481
|
+
y = v.y,
|
|
482
|
+
z = v.z;
|
|
483
|
+
|
|
484
|
+
var len = Math.sqrt(x * x + y * y + z * z);
|
|
485
|
+
|
|
486
|
+
var s, c, t;
|
|
487
|
+
var a00, a01, a02, a03;
|
|
488
|
+
var a10, a11, a12, a13;
|
|
489
|
+
var a20, a21, a22, a23;
|
|
490
|
+
var b00, b01, b02;
|
|
491
|
+
var b10, b11, b12;
|
|
492
|
+
var b20, b21, b22;
|
|
493
|
+
|
|
494
|
+
if (len < EPSILON) {
|
|
495
|
+
return null;
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
len = 1 / len;
|
|
499
|
+
x *= len;
|
|
500
|
+
y *= len;
|
|
501
|
+
z *= len;
|
|
502
|
+
|
|
503
|
+
s = Math.sin(angle);
|
|
504
|
+
c = Math.cos(angle);
|
|
505
|
+
t = 1 - c;
|
|
506
|
+
|
|
507
|
+
a00 = a[0];
|
|
508
|
+
a01 = a[1];
|
|
509
|
+
a02 = a[2];
|
|
510
|
+
a03 = a[3];
|
|
511
|
+
a10 = a[4];
|
|
512
|
+
a11 = a[5];
|
|
513
|
+
a12 = a[6];
|
|
514
|
+
a13 = a[7];
|
|
515
|
+
a20 = a[8];
|
|
516
|
+
a21 = a[9];
|
|
517
|
+
a22 = a[10];
|
|
518
|
+
a23 = a[11];
|
|
543
519
|
|
|
520
|
+
// Construct the elements of the rotation matrix
|
|
521
|
+
b00 = x * x * t + c;
|
|
522
|
+
b01 = y * x * t + z * s;
|
|
523
|
+
b02 = z * x * t - y * s;
|
|
524
|
+
b10 = x * y * t - z * s;
|
|
525
|
+
b11 = y * y * t + c;
|
|
526
|
+
b12 = z * y * t + x * s;
|
|
527
|
+
b20 = x * z * t + y * s;
|
|
528
|
+
b21 = y * z * t - x * s;
|
|
529
|
+
b22 = z * z * t + c;
|
|
530
|
+
|
|
531
|
+
// Perform rotation-specific matrix multiplication
|
|
532
|
+
a[0] = a00 * b00 + a10 * b01 + a20 * b02;
|
|
533
|
+
a[1] = a01 * b00 + a11 * b01 + a21 * b02;
|
|
534
|
+
a[2] = a02 * b00 + a12 * b01 + a22 * b02;
|
|
535
|
+
a[3] = a03 * b00 + a13 * b01 + a23 * b02;
|
|
536
|
+
a[4] = a00 * b10 + a10 * b11 + a20 * b12;
|
|
537
|
+
a[5] = a01 * b10 + a11 * b11 + a21 * b12;
|
|
538
|
+
a[6] = a02 * b10 + a12 * b11 + a22 * b12;
|
|
539
|
+
a[7] = a03 * b10 + a13 * b11 + a23 * b12;
|
|
540
|
+
a[8] = a00 * b20 + a10 * b21 + a20 * b22;
|
|
541
|
+
a[9] = a01 * b20 + a11 * b21 + a21 * b22;
|
|
542
|
+
a[10] = a02 * b20 + a12 * b21 + a22 * b22;
|
|
543
|
+
a[11] = a03 * b20 + a13 * b21 + a23 * b22;
|
|
544
|
+
}
|
|
544
545
|
return this;
|
|
545
546
|
}
|
|
546
547
|
|