melonjs 10.2.0 → 10.3.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/README.md +1 -1
- package/dist/melonjs.js +4435 -4283
- package/dist/melonjs.min.js +4 -4
- package/dist/melonjs.module.d.ts +3348 -3833
- package/dist/melonjs.module.js +4025 -3920
- package/package.json +13 -14
- package/src/audio/audio.js +45 -45
- package/src/camera/camera2d.js +78 -101
- package/src/entity/draggable.js +21 -29
- package/src/entity/droptarget.js +24 -31
- package/src/entity/entity.js +34 -38
- package/src/game.js +8 -8
- package/src/{shapes → geometries}/ellipse.js +46 -46
- package/src/{shapes → geometries}/line.js +14 -14
- package/src/{shapes → geometries}/poly.js +103 -54
- package/src/{shapes → geometries}/rectangle.js +73 -120
- package/src/index.js +18 -19
- package/src/input/gamepad.js +20 -20
- package/src/input/input.js +3 -3
- package/src/input/keyboard.js +122 -124
- package/src/input/pointer.js +102 -62
- package/src/input/pointerevent.js +97 -42
- package/src/lang/deprecated.js +29 -18
- package/src/level/level.js +34 -26
- package/src/level/tiled/TMXGroup.js +12 -13
- package/src/level/tiled/TMXLayer.js +41 -42
- package/src/level/tiled/TMXObject.js +76 -70
- package/src/level/tiled/TMXTile.js +13 -15
- package/src/level/tiled/TMXTileMap.js +26 -25
- package/src/level/tiled/TMXTileset.js +14 -15
- package/src/level/tiled/TMXTilesetGroup.js +5 -6
- package/src/level/tiled/TMXUtils.js +13 -11
- package/src/level/tiled/renderer/TMXHexagonalRenderer.js +3 -4
- package/src/level/tiled/renderer/TMXIsometricRenderer.js +3 -4
- package/src/level/tiled/renderer/TMXOrthogonalRenderer.js +2 -3
- package/src/level/tiled/renderer/TMXRenderer.js +18 -19
- package/src/level/tiled/renderer/TMXStaggeredRenderer.js +2 -3
- package/src/loader/loader.js +46 -40
- package/src/loader/loadingscreen.js +7 -7
- package/src/math/color.js +68 -88
- package/src/math/math.js +33 -33
- package/src/math/matrix2.js +70 -71
- package/src/math/matrix3.js +90 -91
- package/src/math/observable_vector2.js +91 -92
- package/src/math/observable_vector3.js +110 -106
- package/src/math/vector2.js +116 -104
- package/src/math/vector3.js +129 -110
- package/src/particles/emitter.js +116 -126
- package/src/particles/particle.js +4 -5
- package/src/particles/particlecontainer.js +2 -3
- package/src/physics/body.js +82 -83
- package/src/physics/bounds.js +64 -66
- package/src/physics/collision.js +21 -22
- package/src/physics/detector.js +13 -13
- package/src/physics/quadtree.js +26 -25
- package/src/physics/sat.js +21 -21
- package/src/physics/world.js +23 -22
- package/src/plugin/plugin.js +12 -13
- package/src/renderable/GUI.js +20 -26
- package/src/renderable/collectable.js +6 -7
- package/src/renderable/colorlayer.js +11 -12
- package/src/renderable/container.js +98 -81
- package/src/renderable/imagelayer.js +33 -35
- package/src/renderable/nineslicesprite.js +15 -16
- package/src/renderable/renderable.js +112 -111
- package/src/renderable/sprite.js +71 -58
- package/src/renderable/trigger.js +17 -19
- package/src/state/stage.js +14 -15
- package/src/state/state.js +78 -78
- package/src/system/device.js +137 -180
- package/src/system/event.js +116 -104
- package/src/system/pooling.js +15 -15
- package/src/system/save.js +9 -6
- package/src/system/timer.js +33 -33
- package/src/text/bitmaptext.js +39 -46
- package/src/text/bitmaptextdata.js +14 -15
- package/src/text/text.js +55 -58
- package/src/tweens/easing.js +5 -5
- package/src/tweens/interpolation.js +5 -5
- package/src/tweens/tween.js +49 -40
- package/src/utils/agent.js +12 -11
- package/src/utils/array.js +8 -8
- package/src/utils/file.js +7 -7
- package/src/utils/function.js +8 -8
- package/src/utils/string.js +19 -19
- package/src/utils/utils.js +23 -23
- package/src/video/canvas/canvas_renderer.js +127 -128
- package/src/video/renderer.js +69 -69
- package/src/video/texture.js +80 -82
- package/src/video/texture_cache.js +2 -4
- package/src/video/video.js +38 -38
- package/src/video/webgl/buffer/vertex.js +11 -3
- package/src/video/webgl/glshader.js +31 -32
- package/src/video/webgl/webgl_compositor.js +145 -127
- package/src/video/webgl/webgl_renderer.js +196 -175
|
@@ -5,11 +5,10 @@ import Polygon from "./poly.js";
|
|
|
5
5
|
* @classdesc
|
|
6
6
|
* a line segment Object
|
|
7
7
|
* @class Line
|
|
8
|
-
* @
|
|
9
|
-
* @
|
|
10
|
-
* @
|
|
11
|
-
* @param {
|
|
12
|
-
* @param {Number} y origin point of the Line
|
|
8
|
+
* @augments me.Polygon
|
|
9
|
+
* @memberof me
|
|
10
|
+
* @param {number} x origin point of the Line
|
|
11
|
+
* @param {number} y origin point of the Line
|
|
13
12
|
* @param {me.Vector2d[]} points array of vectors defining the Line
|
|
14
13
|
*/
|
|
15
14
|
|
|
@@ -18,20 +17,20 @@ class Line extends Polygon {
|
|
|
18
17
|
/**
|
|
19
18
|
* Returns true if the Line contains the given point
|
|
20
19
|
* @name contains
|
|
21
|
-
* @
|
|
20
|
+
* @memberof me.Line.prototype
|
|
22
21
|
* @function
|
|
23
22
|
* @param {me.Vector2d} point
|
|
24
|
-
* @
|
|
23
|
+
* @returns {boolean} true if contains
|
|
25
24
|
*/
|
|
26
25
|
|
|
27
26
|
/**
|
|
28
27
|
* Returns true if the Line contains the given point
|
|
29
28
|
* @name contains
|
|
30
|
-
* @
|
|
29
|
+
* @memberof me.Line.prototype
|
|
31
30
|
* @function
|
|
32
|
-
* @param {
|
|
33
|
-
* @param {
|
|
34
|
-
* @
|
|
31
|
+
* @param {number} x x coordinate
|
|
32
|
+
* @param {number} y y coordinate
|
|
33
|
+
* @returns {boolean} true if contains
|
|
35
34
|
*/
|
|
36
35
|
contains() {
|
|
37
36
|
var _x, _y;
|
|
@@ -61,8 +60,9 @@ class Line extends Polygon {
|
|
|
61
60
|
* Computes the calculated collision edges and normals.
|
|
62
61
|
* This **must** be called if the `points` array, `angle`, or `offset` is modified manually.
|
|
63
62
|
* @name recalc
|
|
64
|
-
* @
|
|
63
|
+
* @memberof me.Line.prototype
|
|
65
64
|
* @function
|
|
65
|
+
* @returns {me.Line} this instance for objecf chaining
|
|
66
66
|
*/
|
|
67
67
|
recalc() {
|
|
68
68
|
var edges = this.edges;
|
|
@@ -96,9 +96,9 @@ class Line extends Polygon {
|
|
|
96
96
|
/**
|
|
97
97
|
* clone this line segment
|
|
98
98
|
* @name clone
|
|
99
|
-
* @
|
|
99
|
+
* @memberof me.Line.prototype
|
|
100
100
|
* @function
|
|
101
|
-
* @
|
|
101
|
+
* @returns {me.Line} new Line
|
|
102
102
|
*/
|
|
103
103
|
clone() {
|
|
104
104
|
var copy = [];
|
|
@@ -11,10 +11,9 @@ import pool from "./../system/pooling.js";
|
|
|
11
11
|
* <center><img src="images/convex_polygon.png"/></center><br>
|
|
12
12
|
* A polygon's `winding` is clockwise iff its vertices (points) are declared turning to the right. The image above shows COUNTERCLOCKWISE winding.
|
|
13
13
|
* @class Polygon
|
|
14
|
-
* @
|
|
15
|
-
* @
|
|
16
|
-
* @param {
|
|
17
|
-
* @param {Number} y origin point of the Polygon
|
|
14
|
+
* @memberof me
|
|
15
|
+
* @param {number} x origin point of the Polygon
|
|
16
|
+
* @param {number} y origin point of the Polygon
|
|
18
17
|
* @param {me.Vector2d[]} points array of vector defining the Polygon
|
|
19
18
|
*/
|
|
20
19
|
|
|
@@ -35,7 +34,7 @@ class Polygon {
|
|
|
35
34
|
* @ignore
|
|
36
35
|
* @type {me.Bounds}
|
|
37
36
|
* @name _bounds
|
|
38
|
-
* @
|
|
37
|
+
* @memberof me.Polygon#
|
|
39
38
|
*/
|
|
40
39
|
this._bounds;
|
|
41
40
|
|
|
@@ -45,7 +44,7 @@ class Polygon {
|
|
|
45
44
|
* @public
|
|
46
45
|
* @type {me.Vector2d[]}
|
|
47
46
|
* @name points
|
|
48
|
-
* @
|
|
47
|
+
* @memberof me.Polygon#
|
|
49
48
|
*/
|
|
50
49
|
this.points = [];
|
|
51
50
|
|
|
@@ -84,11 +83,12 @@ class Polygon {
|
|
|
84
83
|
/**
|
|
85
84
|
* set new value to the Polygon
|
|
86
85
|
* @name setShape
|
|
87
|
-
* @
|
|
86
|
+
* @memberof me.Polygon.prototype
|
|
88
87
|
* @function
|
|
89
|
-
* @param {
|
|
90
|
-
* @param {
|
|
91
|
-
* @param {me.Vector2d[]|
|
|
88
|
+
* @param {number} x position of the Polygon
|
|
89
|
+
* @param {number} y position of the Polygon
|
|
90
|
+
* @param {me.Vector2d[]|number[]} points array of vector or vertice defining the Polygon
|
|
91
|
+
* @returns {me.Polygon} this instance for objecf chaining
|
|
92
92
|
*/
|
|
93
93
|
setShape(x, y, points) {
|
|
94
94
|
this.pos.set(x, y);
|
|
@@ -99,9 +99,10 @@ class Polygon {
|
|
|
99
99
|
/**
|
|
100
100
|
* set the vertices defining this Polygon
|
|
101
101
|
* @name setVertices
|
|
102
|
-
* @
|
|
102
|
+
* @memberof me.Polygon.prototype
|
|
103
103
|
* @function
|
|
104
|
-
* @param {me.Vector2d[]}
|
|
104
|
+
* @param {me.Vector2d[]} vertices array of vector or vertice defining the Polygon
|
|
105
|
+
* @returns {me.Polygon} this instance for objecf chaining
|
|
105
106
|
*/
|
|
106
107
|
setVertices(vertices) {
|
|
107
108
|
|
|
@@ -138,10 +139,10 @@ class Polygon {
|
|
|
138
139
|
/**
|
|
139
140
|
* apply the given transformation matrix to this Polygon
|
|
140
141
|
* @name transform
|
|
141
|
-
* @
|
|
142
|
+
* @memberof me.Polygon.prototype
|
|
142
143
|
* @function
|
|
143
|
-
* @param {me.Matrix2d}
|
|
144
|
-
* @
|
|
144
|
+
* @param {me.Matrix2d} m the transformation matrix
|
|
145
|
+
* @returns {me.Polygon} Reference to this object for method chaining
|
|
145
146
|
*/
|
|
146
147
|
transform(m) {
|
|
147
148
|
var points = this.points;
|
|
@@ -157,9 +158,9 @@ class Polygon {
|
|
|
157
158
|
/**
|
|
158
159
|
* apply an isometric projection to this shape
|
|
159
160
|
* @name toIso
|
|
160
|
-
* @
|
|
161
|
+
* @memberof me.Polygon.prototype
|
|
161
162
|
* @function
|
|
162
|
-
* @
|
|
163
|
+
* @returns {me.Polygon} Reference to this object for method chaining
|
|
163
164
|
*/
|
|
164
165
|
toIso() {
|
|
165
166
|
return this.rotate(Math.PI / 4).scale(Math.SQRT2, Math.SQRT1_2);
|
|
@@ -168,9 +169,9 @@ class Polygon {
|
|
|
168
169
|
/**
|
|
169
170
|
* apply a 2d projection to this shape
|
|
170
171
|
* @name to2d
|
|
171
|
-
* @
|
|
172
|
+
* @memberof me.Polygon.prototype
|
|
172
173
|
* @function
|
|
173
|
-
* @
|
|
174
|
+
* @returns {me.Polygon} Reference to this object for method chaining
|
|
174
175
|
*/
|
|
175
176
|
to2d() {
|
|
176
177
|
return this.scale(Math.SQRT1_2, Math.SQRT2).rotate(-Math.PI / 4);
|
|
@@ -179,11 +180,11 @@ class Polygon {
|
|
|
179
180
|
/**
|
|
180
181
|
* Rotate this Polygon (counter-clockwise) by the specified angle (in radians).
|
|
181
182
|
* @name rotate
|
|
182
|
-
* @
|
|
183
|
+
* @memberof me.Polygon.prototype
|
|
183
184
|
* @function
|
|
184
|
-
* @param {
|
|
185
|
+
* @param {number} angle The angle to rotate (in radians)
|
|
185
186
|
* @param {me.Vector2d|me.ObservableVector2d} [v] an optional point to rotate around
|
|
186
|
-
* @
|
|
187
|
+
* @returns {me.Polygon} Reference to this object for method chaining
|
|
187
188
|
*/
|
|
188
189
|
rotate(angle, v) {
|
|
189
190
|
if (angle !== 0) {
|
|
@@ -201,11 +202,11 @@ class Polygon {
|
|
|
201
202
|
/**
|
|
202
203
|
* Scale this Polygon by the given scalar.
|
|
203
204
|
* @name scale
|
|
204
|
-
* @
|
|
205
|
+
* @memberof me.Polygon.prototype
|
|
205
206
|
* @function
|
|
206
|
-
* @param {
|
|
207
|
-
* @param {
|
|
208
|
-
* @
|
|
207
|
+
* @param {number} x
|
|
208
|
+
* @param {number} [y=x]
|
|
209
|
+
* @returns {me.Polygon} Reference to this object for method chaining
|
|
209
210
|
*/
|
|
210
211
|
scale(x, y) {
|
|
211
212
|
y = typeof (y) !== "undefined" ? y : x;
|
|
@@ -223,10 +224,10 @@ class Polygon {
|
|
|
223
224
|
/**
|
|
224
225
|
* Scale this Polygon by the given vector
|
|
225
226
|
* @name scaleV
|
|
226
|
-
* @
|
|
227
|
+
* @memberof me.Polygon.prototype
|
|
227
228
|
* @function
|
|
228
229
|
* @param {me.Vector2d} v
|
|
229
|
-
* @
|
|
230
|
+
* @returns {me.Polygon} Reference to this object for method chaining
|
|
230
231
|
*/
|
|
231
232
|
scaleV(v) {
|
|
232
233
|
return this.scale(v.x, v.y);
|
|
@@ -236,9 +237,9 @@ class Polygon {
|
|
|
236
237
|
* Computes the calculated collision polygon.
|
|
237
238
|
* This **must** be called if the `points` array, `angle`, or `offset` is modified manually.
|
|
238
239
|
* @name recalc
|
|
239
|
-
* @
|
|
240
|
+
* @memberof me.Polygon.prototype
|
|
240
241
|
* @function
|
|
241
|
-
* @
|
|
242
|
+
* @returns {me.Polygon} Reference to this object for method chaining
|
|
242
243
|
*/
|
|
243
244
|
recalc() {
|
|
244
245
|
var i;
|
|
@@ -276,12 +277,13 @@ class Polygon {
|
|
|
276
277
|
return this;
|
|
277
278
|
}
|
|
278
279
|
|
|
280
|
+
|
|
279
281
|
/**
|
|
280
282
|
* returns a list of indices for all triangles defined in this polygon
|
|
281
283
|
* @name getIndices
|
|
282
|
-
* @
|
|
284
|
+
* @memberof me.Polygon.prototype
|
|
283
285
|
* @function
|
|
284
|
-
* @
|
|
286
|
+
* @returns {Array} an array of vertex indices for all triangles forming this polygon.
|
|
285
287
|
*/
|
|
286
288
|
getIndices() {
|
|
287
289
|
if (this.indices.length === 0) {
|
|
@@ -290,22 +292,69 @@ class Polygon {
|
|
|
290
292
|
return this.indices;
|
|
291
293
|
}
|
|
292
294
|
|
|
295
|
+
/**
|
|
296
|
+
* Returns true if the vertices composing this polygon form a convex shape (vertices must be in clockwise order).
|
|
297
|
+
* @name isConvex
|
|
298
|
+
* @memberof me.Polygon.prototype
|
|
299
|
+
* @function
|
|
300
|
+
* @returns {boolean} true if the vertices are convex, false if not, null if not computable
|
|
301
|
+
*/
|
|
302
|
+
isConvex() {
|
|
303
|
+
// http://paulbourke.net/geometry/polygonmesh/
|
|
304
|
+
// Copyright (c) Paul Bourke (use permitted)
|
|
305
|
+
|
|
306
|
+
var flag = 0,
|
|
307
|
+
vertices = this.points,
|
|
308
|
+
n = vertices.length,
|
|
309
|
+
i,
|
|
310
|
+
j,
|
|
311
|
+
k,
|
|
312
|
+
z;
|
|
313
|
+
|
|
314
|
+
if (n < 3) {
|
|
315
|
+
return null;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
for (i = 0; i < n; i++) {
|
|
319
|
+
j = (i + 1) % n;
|
|
320
|
+
k = (i + 2) % n;
|
|
321
|
+
z = (vertices[j].x - vertices[i].x) * (vertices[k].y - vertices[j].y);
|
|
322
|
+
z -= (vertices[j].y - vertices[i].y) * (vertices[k].x - vertices[j].x);
|
|
323
|
+
|
|
324
|
+
if (z < 0) {
|
|
325
|
+
flag |= 1;
|
|
326
|
+
} else if (z > 0) {
|
|
327
|
+
flag |= 2;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
if (flag === 3) {
|
|
331
|
+
return false;
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
if (flag !== 0) {
|
|
336
|
+
return true;
|
|
337
|
+
} else {
|
|
338
|
+
return null;
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
|
|
293
342
|
/**
|
|
294
343
|
* translate the Polygon by the specified offset
|
|
295
344
|
* @name translate
|
|
296
|
-
* @
|
|
345
|
+
* @memberof me.Polygon.prototype
|
|
297
346
|
* @function
|
|
298
|
-
* @param {
|
|
299
|
-
* @param {
|
|
300
|
-
* @
|
|
347
|
+
* @param {number} x x offset
|
|
348
|
+
* @param {number} y y offset
|
|
349
|
+
* @returns {me.Polygon} this Polygon
|
|
301
350
|
*/
|
|
302
351
|
/**
|
|
303
352
|
* translate the Polygon by the specified vector
|
|
304
353
|
* @name translate
|
|
305
|
-
* @
|
|
354
|
+
* @memberof me.Polygon.prototype
|
|
306
355
|
* @function
|
|
307
356
|
* @param {me.Vector2d} v vector offset
|
|
308
|
-
* @
|
|
357
|
+
* @returns {me.Polygon} Reference to this object for method chaining
|
|
309
358
|
*/
|
|
310
359
|
translate() {
|
|
311
360
|
var _x, _y;
|
|
@@ -330,17 +379,17 @@ class Polygon {
|
|
|
330
379
|
/**
|
|
331
380
|
* Shifts the Polygon to the given position vector.
|
|
332
381
|
* @name shift
|
|
333
|
-
* @
|
|
382
|
+
* @memberof me.Polygon
|
|
334
383
|
* @function
|
|
335
384
|
* @param {me.Vector2d} position
|
|
336
385
|
*/
|
|
337
386
|
/**
|
|
338
387
|
* Shifts the Polygon to the given x, y position.
|
|
339
388
|
* @name shift
|
|
340
|
-
* @
|
|
389
|
+
* @memberof me.Polygon
|
|
341
390
|
* @function
|
|
342
|
-
* @param {
|
|
343
|
-
* @param {
|
|
391
|
+
* @param {number} x
|
|
392
|
+
* @param {number} y
|
|
344
393
|
*/
|
|
345
394
|
shift() {
|
|
346
395
|
var _x, _y;
|
|
@@ -363,10 +412,10 @@ class Polygon {
|
|
|
363
412
|
* (Note: it is highly recommended to first do a hit test on the corresponding <br>
|
|
364
413
|
* bounding rect, as the function can be highly consuming with complex shapes)
|
|
365
414
|
* @name contains
|
|
366
|
-
* @
|
|
415
|
+
* @memberof me.Polygon.prototype
|
|
367
416
|
* @function
|
|
368
417
|
* @param {me.Vector2d} point
|
|
369
|
-
* @
|
|
418
|
+
* @returns {boolean} true if contains
|
|
370
419
|
*/
|
|
371
420
|
|
|
372
421
|
/**
|
|
@@ -374,11 +423,11 @@ class Polygon {
|
|
|
374
423
|
* (Note: it is highly recommended to first do a hit test on the corresponding <br>
|
|
375
424
|
* bounding rect, as the function can be highly consuming with complex shapes)
|
|
376
425
|
* @name contains
|
|
377
|
-
* @
|
|
426
|
+
* @memberof me.Polygon.prototype
|
|
378
427
|
* @function
|
|
379
|
-
* @param {
|
|
380
|
-
* @param {
|
|
381
|
-
* @
|
|
428
|
+
* @param {number} x x coordinate
|
|
429
|
+
* @param {number} y y coordinate
|
|
430
|
+
* @returns {boolean} true if contains
|
|
382
431
|
*/
|
|
383
432
|
contains() {
|
|
384
433
|
var _x, _y;
|
|
@@ -412,9 +461,9 @@ class Polygon {
|
|
|
412
461
|
/**
|
|
413
462
|
* returns the bounding box for this shape, the smallest Rectangle object completely containing this shape.
|
|
414
463
|
* @name getBounds
|
|
415
|
-
* @
|
|
464
|
+
* @memberof me.Polygon.prototype
|
|
416
465
|
* @function
|
|
417
|
-
* @
|
|
466
|
+
* @returns {me.Bounds} this shape bounding box Rectangle object
|
|
418
467
|
*/
|
|
419
468
|
getBounds() {
|
|
420
469
|
if (typeof this._bounds === "undefined") {
|
|
@@ -427,9 +476,9 @@ class Polygon {
|
|
|
427
476
|
* update the bounding box for this shape.
|
|
428
477
|
* @ignore
|
|
429
478
|
* @name updateBounds
|
|
430
|
-
* @
|
|
479
|
+
* @memberof me.Polygon.prototype
|
|
431
480
|
* @function
|
|
432
|
-
* @
|
|
481
|
+
* @returns {me.Bounds} this shape bounding box Rectangle object
|
|
433
482
|
*/
|
|
434
483
|
updateBounds() {
|
|
435
484
|
var bounds = this.getBounds();
|
|
@@ -443,9 +492,9 @@ class Polygon {
|
|
|
443
492
|
/**
|
|
444
493
|
* clone this Polygon
|
|
445
494
|
* @name clone
|
|
446
|
-
* @
|
|
495
|
+
* @memberof me.Polygon.prototype
|
|
447
496
|
* @function
|
|
448
|
-
* @
|
|
497
|
+
* @returns {me.Polygon} new Polygon
|
|
449
498
|
*/
|
|
450
499
|
clone() {
|
|
451
500
|
var copy = [];
|