melonjs 9.1.0 → 10.0.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/{LICENSE → LICENSE.md} +0 -0
- package/README.md +93 -57
- package/dist/melonjs.js +10334 -11179
- package/dist/melonjs.min.js +4 -10
- package/dist/melonjs.module.d.ts +13206 -0
- package/dist/melonjs.module.js +9913 -10872
- package/package.json +19 -14
- package/src/audio/audio.js +477 -553
- package/src/camera/camera2d.js +67 -65
- package/src/entity/draggable.js +26 -35
- package/src/entity/droptarget.js +17 -14
- package/src/entity/entity.js +59 -79
- package/src/game.js +194 -204
- package/src/index.js +12 -30
- package/src/input/gamepad.js +8 -19
- package/src/input/keyboard.js +4 -4
- package/src/input/pointer.js +14 -12
- package/src/input/pointerevent.js +15 -13
- package/src/lang/deprecated.js +2 -887
- package/src/level/level.js +3 -3
- package/src/level/tiled/TMXGroup.js +7 -11
- package/src/level/tiled/TMXLayer.js +33 -32
- package/src/level/tiled/TMXTileMap.js +15 -19
- package/src/level/tiled/TMXTileset.js +5 -5
- package/src/level/tiled/TMXUtils.js +3 -3
- package/src/level/tiled/renderer/TMXRenderer.js +4 -0
- package/src/loader/loader.js +8 -23
- package/src/loader/loadingscreen.js +51 -60
- package/src/math/matrix3.js +1 -1
- package/src/particles/emitter.js +36 -39
- package/src/particles/particle.js +27 -12
- package/src/particles/particlecontainer.js +17 -16
- package/src/physics/body.js +80 -118
- package/src/physics/collision.js +5 -235
- package/src/physics/detector.js +235 -0
- package/src/physics/quadtree.js +14 -14
- package/src/physics/world.js +84 -18
- package/src/plugin/plugin.js +26 -24
- package/src/polyfill/console.js +9 -14
- package/src/renderable/GUI.js +48 -62
- package/src/renderable/collectable.js +11 -4
- package/src/renderable/colorlayer.js +28 -26
- package/src/renderable/container.js +120 -96
- package/src/renderable/imagelayer.js +94 -93
- package/src/renderable/renderable.js +164 -138
- package/src/renderable/sprite.js +42 -44
- package/src/renderable/trigger.js +24 -17
- package/src/shapes/ellipse.js +27 -27
- package/src/shapes/line.js +12 -8
- package/src/shapes/poly.js +77 -49
- package/src/shapes/rectangle.js +193 -268
- package/src/state/stage.js +23 -25
- package/src/state/state.js +35 -86
- package/src/system/device.js +233 -285
- package/src/system/event.js +485 -432
- package/src/system/pooling.js +61 -54
- package/src/system/save.js +17 -16
- package/src/system/timer.js +34 -38
- package/src/text/bitmaptext.js +44 -46
- package/src/text/text.js +39 -34
- package/src/tweens/easing.js +0 -2
- package/src/tweens/interpolation.js +3 -8
- package/src/tweens/tween.js +332 -351
- package/src/utils/function.js +6 -8
- package/src/utils/utils.js +34 -30
- package/src/video/canvas/canvas_renderer.js +13 -8
- package/src/video/renderer.js +8 -7
- package/src/video/texture.js +8 -8
- package/src/video/texture_cache.js +5 -5
- package/src/video/video.js +373 -403
- package/src/video/webgl/glshader.js +2 -2
- package/src/video/webgl/webgl_compositor.js +14 -8
- package/src/video/webgl/webgl_renderer.js +21 -19
- package/plugins/debug/debugPanel.js +0 -770
- package/plugins/debug/font/PressStart2P.fnt +0 -100
- package/plugins/debug/font/PressStart2P.ltr +0 -1
- package/plugins/debug/font/PressStart2P.png +0 -0
- package/plugins/debug/particleDebugPanel.js +0 -303
package/src/utils/function.js
CHANGED
|
@@ -12,19 +12,17 @@
|
|
|
12
12
|
* @memberOf me.utils.function
|
|
13
13
|
* @name defer
|
|
14
14
|
* @param {Function} fn The function to be deferred.
|
|
15
|
-
* @param {Object}
|
|
16
|
-
* @param {} [
|
|
17
|
-
* function.
|
|
15
|
+
* @param {Object} thisArg The value to be passed as the this parameter to the target function when the deferred function is called
|
|
16
|
+
* @param {...*} [args] Optional additional arguments to carry for the function.
|
|
18
17
|
* @return {Number} id that can be used to clear the deferred function using
|
|
19
18
|
* clearTimeout
|
|
20
19
|
* @example
|
|
21
20
|
* // execute myFunc() when the stack is empty,
|
|
22
|
-
* // with the current context and
|
|
23
|
-
* me.utils.function.defer(
|
|
21
|
+
* // with the current context and [1, 2, 3] as parameter
|
|
22
|
+
* me.utils.function.defer(myFunc, this, 1, 2, 3);
|
|
24
23
|
*/
|
|
25
|
-
export function defer(
|
|
26
|
-
|
|
27
|
-
return setTimeout(fn.bind.apply(fn, args), 0.01);
|
|
24
|
+
export function defer(func, thisArg, ...args) {
|
|
25
|
+
return setTimeout(func.bind(thisArg), 0.01, ...args);
|
|
28
26
|
};
|
|
29
27
|
|
|
30
28
|
/**
|
package/src/utils/utils.js
CHANGED
|
@@ -3,13 +3,13 @@ import * as arrayUtils from "./array.js";
|
|
|
3
3
|
import * as fileUtils from "./file.js";
|
|
4
4
|
import * as stringUtils from "./string.js";
|
|
5
5
|
import * as fnUtils from "./function.js";
|
|
6
|
-
import
|
|
6
|
+
import { createCanvas } from "./../video/video.js";
|
|
7
7
|
import CanvasRenderer from "./../video/canvas/canvas_renderer.js";
|
|
8
8
|
import { version } from "./../index.js";
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* a collection of utility functions
|
|
12
|
-
* @namespace
|
|
12
|
+
* @namespace utils
|
|
13
13
|
* @memberOf me
|
|
14
14
|
*/
|
|
15
15
|
|
|
@@ -37,7 +37,7 @@ var utils = {
|
|
|
37
37
|
getPixels : function (arg) {
|
|
38
38
|
if (arg instanceof HTMLImageElement) {
|
|
39
39
|
var _context = CanvasRenderer.getContext2d(
|
|
40
|
-
|
|
40
|
+
createCanvas(arg.width, arg.height)
|
|
41
41
|
);
|
|
42
42
|
_context.drawImage(arg, 0, 0);
|
|
43
43
|
return _context.getImageData(0, 0, arg.width, arg.height);
|
|
@@ -100,36 +100,40 @@ var utils = {
|
|
|
100
100
|
* var UriFragment = me.utils.getUriFragment();
|
|
101
101
|
* console.log(UriFragment["mytag"]); //> "value"
|
|
102
102
|
*/
|
|
103
|
-
getUriFragment :
|
|
104
|
-
var
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
var
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
return hash;
|
|
112
|
-
}
|
|
113
|
-
url = document.location;
|
|
114
|
-
parsed = true;
|
|
103
|
+
getUriFragment : function (url) {
|
|
104
|
+
var hash = {};
|
|
105
|
+
|
|
106
|
+
if (typeof url === "undefined") {
|
|
107
|
+
var location = document.location;
|
|
108
|
+
|
|
109
|
+
if (location && location.hash) {
|
|
110
|
+
url = location.hash;
|
|
115
111
|
} else {
|
|
116
|
-
//
|
|
117
|
-
hash
|
|
112
|
+
// No "document.location" exist for Wechat mini game platform.
|
|
113
|
+
return hash;
|
|
118
114
|
}
|
|
119
|
-
|
|
120
|
-
if
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
var v = kv.join("=");
|
|
127
|
-
hash[k] = v || true;
|
|
128
|
-
});
|
|
115
|
+
} else {
|
|
116
|
+
// never cache if a url is passed as parameter
|
|
117
|
+
var index = url.indexOf("#");
|
|
118
|
+
if (index !== -1) {
|
|
119
|
+
url = url.substr(index, url.length);
|
|
120
|
+
} else {
|
|
121
|
+
return hash;
|
|
129
122
|
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// parse the url
|
|
126
|
+
url.substr(1).split("&").filter(function (value) {
|
|
127
|
+
return (value !== "");
|
|
128
|
+
}).forEach(function (value) {
|
|
129
|
+
var kv = value.split("=");
|
|
130
|
+
var k = kv.shift();
|
|
131
|
+
var v = kv.join("=");
|
|
132
|
+
hash[k] = v || true;
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
return hash;
|
|
136
|
+
},
|
|
133
137
|
|
|
134
138
|
/**
|
|
135
139
|
* reset the GUID Base Name
|
|
@@ -2,7 +2,7 @@ import Color from "./../../math/color.js";
|
|
|
2
2
|
import Renderer from "./../renderer.js";
|
|
3
3
|
import TextureCache from "./../texture_cache.js";
|
|
4
4
|
import Ellipse from "./../../shapes/ellipse.js";
|
|
5
|
-
import
|
|
5
|
+
import { createCanvas } from "./../video.js";
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
|
|
@@ -36,7 +36,7 @@ class CanvasRenderer extends Renderer {
|
|
|
36
36
|
|
|
37
37
|
// create the back buffer if we use double buffering
|
|
38
38
|
if (this.settings.doubleBuffering) {
|
|
39
|
-
this.backBufferCanvas =
|
|
39
|
+
this.backBufferCanvas = createCanvas(this.settings.width, this.settings.height, true);
|
|
40
40
|
this.backBufferContext2D = this.getContext2d(this.backBufferCanvas);
|
|
41
41
|
}
|
|
42
42
|
else {
|
|
@@ -281,8 +281,9 @@ class CanvasRenderer extends Renderer {
|
|
|
281
281
|
* @param {Number} start start angle in radians
|
|
282
282
|
* @param {Number} end end angle in radians
|
|
283
283
|
* @param {Boolean} [antiClockwise=false] draw arc anti-clockwise
|
|
284
|
+
* @param {Boolean} [fill=false] also fill the shape with the current color if true
|
|
284
285
|
*/
|
|
285
|
-
strokeArc(x, y, radius, start, end, antiClockwise, fill) {
|
|
286
|
+
strokeArc(x, y, radius, start, end, antiClockwise, fill = false) {
|
|
286
287
|
var context = this.backBufferContext2D;
|
|
287
288
|
|
|
288
289
|
if (context.globalAlpha < 1 / 255) {
|
|
@@ -321,8 +322,9 @@ class CanvasRenderer extends Renderer {
|
|
|
321
322
|
* @param {Number} y ellipse center point y-axis
|
|
322
323
|
* @param {Number} w horizontal radius of the ellipse
|
|
323
324
|
* @param {Number} h vertical radius of the ellipse
|
|
325
|
+
* @param {Boolean} [fill=false] also fill the shape with the current color if true
|
|
324
326
|
*/
|
|
325
|
-
strokeEllipse(x, y, w, h, fill) {
|
|
327
|
+
strokeEllipse(x, y, w, h, fill = false) {
|
|
326
328
|
var context = this.backBufferContext2D;
|
|
327
329
|
|
|
328
330
|
if (context.globalAlpha < 1 / 255) {
|
|
@@ -412,8 +414,9 @@ class CanvasRenderer extends Renderer {
|
|
|
412
414
|
* @memberOf me.CanvasRenderer.prototype
|
|
413
415
|
* @function
|
|
414
416
|
* @param {me.Polygon} poly the shape to draw
|
|
417
|
+
* @param {Boolean} [fill=false] also fill the shape with the current color if true
|
|
415
418
|
*/
|
|
416
|
-
strokePolygon(poly, fill) {
|
|
419
|
+
strokePolygon(poly, fill = false) {
|
|
417
420
|
var context = this.backBufferContext2D;
|
|
418
421
|
|
|
419
422
|
if (context.globalAlpha < 1 / 255) {
|
|
@@ -455,8 +458,9 @@ class CanvasRenderer extends Renderer {
|
|
|
455
458
|
* @param {Number} y
|
|
456
459
|
* @param {Number} width
|
|
457
460
|
* @param {Number} height
|
|
461
|
+
* @param {Boolean} [fill=false] also fill the shape with the current color if true
|
|
458
462
|
*/
|
|
459
|
-
strokeRect(x, y, width, height, fill) {
|
|
463
|
+
strokeRect(x, y, width, height, fill = false) {
|
|
460
464
|
if (fill === true ) {
|
|
461
465
|
this.fillRect(x, y, width, height);
|
|
462
466
|
} else {
|
|
@@ -695,6 +699,8 @@ class CanvasRenderer extends Renderer {
|
|
|
695
699
|
var context = this.backBufferContext2D;
|
|
696
700
|
var _x = mask.pos.x, _y = mask.pos.y;
|
|
697
701
|
|
|
702
|
+
context.save();
|
|
703
|
+
|
|
698
704
|
// https://github.com/melonjs/melonJS/issues/648
|
|
699
705
|
if (mask instanceof Ellipse) {
|
|
700
706
|
var hw = mask.radiusV.x,
|
|
@@ -718,7 +724,6 @@ class CanvasRenderer extends Renderer {
|
|
|
718
724
|
context.bezierCurveTo(xmin, by, lx, ymax, lx, _y);
|
|
719
725
|
context.bezierCurveTo(lx, ymin, xmin, ty, _x, ty);
|
|
720
726
|
} else {
|
|
721
|
-
context.save();
|
|
722
727
|
context.beginPath();
|
|
723
728
|
context.moveTo(_x + mask.points[0].x, _y + mask.points[0].y);
|
|
724
729
|
var point;
|
|
@@ -726,8 +731,8 @@ class CanvasRenderer extends Renderer {
|
|
|
726
731
|
point = mask.points[i];
|
|
727
732
|
context.lineTo(_x + point.x, _y + point.y);
|
|
728
733
|
}
|
|
729
|
-
context.closePath();
|
|
730
734
|
}
|
|
735
|
+
|
|
731
736
|
context.clip();
|
|
732
737
|
}
|
|
733
738
|
|
package/src/video/renderer.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import Color from "./../math/color.js";
|
|
2
2
|
import Matrix3d from "./../math/matrix3.js";
|
|
3
|
-
import
|
|
4
|
-
import event from "./../system/event.js";
|
|
3
|
+
import { createCanvas, renderer } from "./video.js";
|
|
4
|
+
import * as event from "./../system/event.js";
|
|
5
5
|
import device from "./../system/device.js";
|
|
6
6
|
import { setPrefixed } from "./../utils/agent.js";
|
|
7
7
|
import { Texture } from "./texture.js";
|
|
@@ -72,7 +72,7 @@ class Renderer {
|
|
|
72
72
|
} else if (typeof this.settings.canvas !== "undefined") {
|
|
73
73
|
this.canvas = this.settings.canvas;
|
|
74
74
|
} else {
|
|
75
|
-
this.canvas =
|
|
75
|
+
this.canvas = createCanvas(this.settings.zoomX, this.settings.zoomY);
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
// canvas object and context
|
|
@@ -94,8 +94,8 @@ class Renderer {
|
|
|
94
94
|
this.Texture = Texture;
|
|
95
95
|
|
|
96
96
|
// reset the instantiated renderer on game reset
|
|
97
|
-
event.
|
|
98
|
-
|
|
97
|
+
event.on(event.GAME_RESET, () => {
|
|
98
|
+
renderer.reset();
|
|
99
99
|
});
|
|
100
100
|
|
|
101
101
|
return this;
|
|
@@ -288,7 +288,7 @@ class Renderer {
|
|
|
288
288
|
this.currentScissor[2] = width;
|
|
289
289
|
this.currentScissor[3] = height;
|
|
290
290
|
// publish the corresponding event
|
|
291
|
-
event.
|
|
291
|
+
event.emit(event.CANVAS_ONRESIZE, width, height);
|
|
292
292
|
}
|
|
293
293
|
}
|
|
294
294
|
|
|
@@ -367,7 +367,7 @@ class Renderer {
|
|
|
367
367
|
* @return {HTMLCanvasElement|OffscreenCanvas} a new canvas element representing the tinted image
|
|
368
368
|
*/
|
|
369
369
|
tint(src, color, mode) {
|
|
370
|
-
var canvas =
|
|
370
|
+
var canvas = createCanvas(src.width, src.height, true);
|
|
371
371
|
var context = this.getContext2d(canvas);
|
|
372
372
|
|
|
373
373
|
context.save();
|
|
@@ -405,6 +405,7 @@ class Renderer {
|
|
|
405
405
|
* @function
|
|
406
406
|
* @param {me.Rect|me.Polygon|me.Line|me.Ellipse} [mask] the shape defining the mask to be applied
|
|
407
407
|
*/
|
|
408
|
+
// eslint-disable-next-line no-unused-vars
|
|
408
409
|
setMask(mask) {}
|
|
409
410
|
|
|
410
411
|
/**
|
package/src/video/texture.js
CHANGED
|
@@ -2,7 +2,7 @@ import Vector2d from "./../math/vector2.js";
|
|
|
2
2
|
import WebGLRenderer from "./webgl/webgl_renderer.js";
|
|
3
3
|
import TextureCache from "./texture_cache.js";
|
|
4
4
|
import Sprite from "./../renderable/sprite.js";
|
|
5
|
-
import
|
|
5
|
+
import { renderer } from "./video.js";
|
|
6
6
|
import pool from "./../system/pooling.js";
|
|
7
7
|
import loader from "./../loader/loader.js";
|
|
8
8
|
import { ETA } from "./../math/math.js";
|
|
@@ -161,11 +161,11 @@ export class Texture {
|
|
|
161
161
|
|
|
162
162
|
// Add self to TextureCache if cache !== false
|
|
163
163
|
if (cache !== false) {
|
|
164
|
-
this.sources.forEach(
|
|
164
|
+
this.sources.forEach((source) => {
|
|
165
165
|
if (cache instanceof TextureCache) {
|
|
166
166
|
cache.set(source, this);
|
|
167
167
|
} else {
|
|
168
|
-
|
|
168
|
+
renderer.cache.set(source, this);
|
|
169
169
|
}
|
|
170
170
|
});
|
|
171
171
|
}
|
|
@@ -177,8 +177,8 @@ export class Texture {
|
|
|
177
177
|
*/
|
|
178
178
|
parse(data) {
|
|
179
179
|
var atlas = {};
|
|
180
|
-
|
|
181
|
-
data.frames.forEach(
|
|
180
|
+
|
|
181
|
+
data.frames.forEach((frame) => {
|
|
182
182
|
// fix wrongly formatted JSON (e.g. last dummy object in ShoeBox)
|
|
183
183
|
if (frame.hasOwnProperty("filename")) {
|
|
184
184
|
// Source coordinates
|
|
@@ -202,7 +202,7 @@ export class Texture {
|
|
|
202
202
|
height : s.h,
|
|
203
203
|
angle : (frame.rotated === true) ? -ETA : 0
|
|
204
204
|
};
|
|
205
|
-
|
|
205
|
+
this.addUvsMap(atlas, frame.filename, data.meta.size.w, data.meta.size.h);
|
|
206
206
|
}
|
|
207
207
|
});
|
|
208
208
|
return atlas;
|
|
@@ -275,7 +275,7 @@ export class Texture {
|
|
|
275
275
|
*/
|
|
276
276
|
addUvsMap(atlas, frame, w, h) {
|
|
277
277
|
// ignore if using the Canvas Renderer
|
|
278
|
-
if (
|
|
278
|
+
if (renderer instanceof WebGLRenderer) {
|
|
279
279
|
// Source coordinates
|
|
280
280
|
var s = atlas[frame].offset;
|
|
281
281
|
var sw = atlas[frame].width;
|
|
@@ -300,7 +300,7 @@ export class Texture {
|
|
|
300
300
|
*/
|
|
301
301
|
addQuadRegion(name, x, y, w, h) {
|
|
302
302
|
// TODO: Require proper atlas regions instead of caching arbitrary region keys
|
|
303
|
-
if (
|
|
303
|
+
if (renderer.settings.verbose === true) {
|
|
304
304
|
console.warn("Adding texture region", name, "for texture", this);
|
|
305
305
|
}
|
|
306
306
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import { renderer } from "./video.js";
|
|
2
|
+
import * as fileUtil from "./../utils/file.js";
|
|
3
3
|
import { Texture, createAtlas } from "./texture.js";
|
|
4
4
|
import { isPowerOfTwo} from "./../math/math.js";
|
|
5
5
|
|
|
@@ -50,7 +50,7 @@ class TextureCache {
|
|
|
50
50
|
get(image, atlas) {
|
|
51
51
|
if (!this.cache.has(image)) {
|
|
52
52
|
if (!atlas) {
|
|
53
|
-
atlas = createAtlas(image.width, image.height, image.src ?
|
|
53
|
+
atlas = createAtlas(image.width, image.height, image.src ? fileUtil.getBasename(image.src) : undefined);
|
|
54
54
|
}
|
|
55
55
|
this.set(image, new Texture(atlas, image, false));
|
|
56
56
|
}
|
|
@@ -69,7 +69,7 @@ class TextureCache {
|
|
|
69
69
|
}
|
|
70
70
|
|
|
71
71
|
if (!image_cache.has(color)) {
|
|
72
|
-
image_cache.set(color,
|
|
72
|
+
image_cache.set(color, renderer.tint(src, color, "multiply"));
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
return image_cache.get(color);
|
|
@@ -83,7 +83,7 @@ class TextureCache {
|
|
|
83
83
|
var height = image.height;
|
|
84
84
|
|
|
85
85
|
// warn if a non POT texture is added to the cache when using WebGL1
|
|
86
|
-
if (
|
|
86
|
+
if (renderer.WebGLVersion === 1 && (!isPowerOfTwo(width) || !isPowerOfTwo(height))) {
|
|
87
87
|
var src = typeof image.src !== "undefined" ? image.src : image;
|
|
88
88
|
console.warn(
|
|
89
89
|
"[Texture] " + src + " is not a POT texture " +
|