melonjs 10.9.0 → 10.12.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/LICENSE.md +1 -1
- package/README.md +32 -25
- package/dist/melonjs.js +1635 -2383
- package/dist/melonjs.min.js +4 -4
- package/dist/melonjs.module.d.ts +929 -1504
- package/dist/melonjs.module.js +1581 -2344
- package/package.json +18 -18
- package/src/audio/audio.js +0 -1
- package/src/camera/camera2d.js +1 -16
- package/src/entity/entity.js +6 -11
- package/src/game.js +2 -2
- package/src/geometries/ellipse.js +19 -28
- package/src/geometries/line.js +5 -8
- package/src/geometries/path2d.js +14 -24
- package/src/geometries/poly.js +29 -47
- package/src/geometries/rectangle.js +25 -37
- package/src/geometries/roundrect.js +8 -12
- package/src/index.js +7 -2
- package/src/input/gamepad.js +3 -14
- package/src/input/keyboard.js +1 -9
- package/src/input/pointer.js +0 -1
- package/src/input/pointerevent.js +14 -23
- package/src/lang/deprecated.js +9 -6
- package/src/level/level.js +0 -9
- package/src/level/tiled/TMXGroup.js +0 -4
- package/src/level/tiled/TMXLayer.js +0 -8
- package/src/level/tiled/TMXObject.js +0 -3
- package/src/level/tiled/TMXTile.js +4 -5
- package/src/level/tiled/TMXTileMap.js +1 -7
- package/src/level/tiled/TMXTileset.js +0 -5
- package/src/level/tiled/TMXTilesetGroup.js +1 -4
- package/src/level/tiled/TMXUtils.js +1 -4
- package/src/level/tiled/renderer/TMXHexagonalRenderer.js +2 -3
- package/src/level/tiled/renderer/TMXIsometricRenderer.js +0 -1
- package/src/level/tiled/renderer/TMXRenderer.js +1 -7
- package/src/loader/loader.js +0 -11
- package/src/loader/loadingscreen.js +16 -5
- package/src/math/color.js +10 -30
- package/src/math/math.js +0 -10
- package/src/math/matrix2.js +12 -27
- package/src/math/matrix3.js +1 -22
- package/src/math/observable_vector2.js +0 -29
- package/src/math/observable_vector3.js +0 -29
- package/src/math/vector2.js +3 -40
- package/src/math/vector3.js +4 -41
- package/src/particles/emitter.js +11 -12
- package/src/physics/body.js +4 -5
- package/src/physics/bounds.js +5 -19
- package/src/physics/collision.js +1 -13
- package/src/physics/detector.js +6 -56
- package/src/physics/quadtree.js +0 -7
- package/src/physics/response.js +48 -0
- package/src/physics/sat.js +4 -4
- package/src/physics/world.js +0 -4
- package/src/plugin/plugin.js +0 -2
- package/src/polyfill/roundrect.js +4 -2
- package/src/renderable/GUI.js +11 -14
- package/src/renderable/collectable.js +1 -0
- package/src/renderable/colorlayer.js +9 -7
- package/src/renderable/container.js +38 -64
- package/src/renderable/dragndrop.js +1 -10
- package/src/renderable/imagelayer.js +8 -12
- package/src/renderable/light2d.js +118 -0
- package/src/renderable/renderable.js +27 -48
- package/src/renderable/sprite.js +17 -29
- package/src/renderable/trigger.js +10 -3
- package/src/state/stage.js +72 -6
- package/src/state/state.js +22 -23
- package/src/system/device.js +14 -53
- package/src/system/event.js +11 -0
- package/src/system/pooling.js +20 -9
- package/src/system/save.js +9 -11
- package/src/system/timer.js +239 -218
- package/src/text/bitmaptextdata.js +1 -4
- package/src/text/glyph.js +2 -2
- package/src/text/text.js +25 -24
- package/src/text/textmetrics.js +0 -2
- package/src/tweens/easing.js +1 -1
- package/src/tweens/interpolation.js +2 -2
- package/src/tweens/tween.js +1 -13
- package/src/utils/agent.js +1 -3
- package/src/utils/array.js +0 -3
- package/src/utils/file.js +0 -2
- package/src/utils/function.js +0 -2
- package/src/utils/string.js +0 -6
- package/src/utils/utils.js +0 -3
- package/src/video/canvas/canvas_renderer.js +73 -90
- package/src/video/renderer.js +34 -49
- package/src/video/{texture.js → texture/atlas.js} +10 -8
- package/src/video/{texture_cache.js → texture/cache.js} +4 -5
- package/src/video/texture/canvas_texture.js +99 -0
- package/src/video/video.js +3 -3
- package/src/video/webgl/glshader.js +0 -5
- package/src/video/webgl/utils/uniforms.js +3 -6
- package/src/video/webgl/webgl_compositor.js +0 -14
- package/src/video/webgl/webgl_renderer.js +73 -97
package/src/physics/body.js
CHANGED
|
@@ -13,6 +13,7 @@ import { world } from "./../game.js";
|
|
|
13
13
|
/**
|
|
14
14
|
* @classdesc
|
|
15
15
|
* a Generic Physic Body Object with some physic properties and behavior functionality, to as a member of a Renderable.
|
|
16
|
+
* @see Renderable.body
|
|
16
17
|
*/
|
|
17
18
|
class Body {
|
|
18
19
|
/**
|
|
@@ -368,7 +369,6 @@ class Body {
|
|
|
368
369
|
|
|
369
370
|
/**
|
|
370
371
|
* returns the AABB bounding box for this body
|
|
371
|
-
* @function
|
|
372
372
|
* @returns {Bounds} bounding box Rectangle object
|
|
373
373
|
*/
|
|
374
374
|
getBounds() {
|
|
@@ -439,7 +439,7 @@ class Body {
|
|
|
439
439
|
|
|
440
440
|
/**
|
|
441
441
|
* the built-in function to solve the collision response
|
|
442
|
-
* @param {object} response the collision response object (see {@link
|
|
442
|
+
* @param {object} response the collision response object (see {@link ResponseObject})
|
|
443
443
|
*/
|
|
444
444
|
respondToCollision(response) {
|
|
445
445
|
// the overlap vector
|
|
@@ -510,6 +510,7 @@ class Body {
|
|
|
510
510
|
|
|
511
511
|
/**
|
|
512
512
|
* Returns true if the any of the shape composing the body contains the given point.
|
|
513
|
+
* @method Body#contains
|
|
513
514
|
* @param {Vector2d} point
|
|
514
515
|
* @returns {boolean} true if contains
|
|
515
516
|
*/
|
|
@@ -573,7 +574,6 @@ class Body {
|
|
|
573
574
|
* cap the body velocity (body.maxVel property) to the specified value<br>
|
|
574
575
|
* @param {number} x max velocity on x axis
|
|
575
576
|
* @param {number} y max velocity on y axis
|
|
576
|
-
* @protected
|
|
577
577
|
*/
|
|
578
578
|
setMaxVelocity(x, y) {
|
|
579
579
|
this.maxVel.x = x;
|
|
@@ -584,7 +584,6 @@ class Body {
|
|
|
584
584
|
* set the body default friction
|
|
585
585
|
* @param {number} x horizontal friction
|
|
586
586
|
* @param {number} y vertical friction
|
|
587
|
-
* @protected
|
|
588
587
|
*/
|
|
589
588
|
setFriction(x = 0, y = 0) {
|
|
590
589
|
this.friction.x = x;
|
|
@@ -692,7 +691,7 @@ class Body {
|
|
|
692
691
|
pool.push(this.friction);
|
|
693
692
|
pool.push(this.maxVel);
|
|
694
693
|
this.shapes.forEach((shape) => {
|
|
695
|
-
pool.push(shape);
|
|
694
|
+
pool.push(shape, false);
|
|
696
695
|
});
|
|
697
696
|
|
|
698
697
|
// set to undefined
|
package/src/physics/bounds.js
CHANGED
|
@@ -34,7 +34,6 @@ class Bounds {
|
|
|
34
34
|
* reset the bound
|
|
35
35
|
* @name clear
|
|
36
36
|
* @memberof Bounds
|
|
37
|
-
* @function
|
|
38
37
|
*/
|
|
39
38
|
clear() {
|
|
40
39
|
this.setMinMax(Infinity, Infinity, -Infinity, -Infinity);
|
|
@@ -45,7 +44,6 @@ class Bounds {
|
|
|
45
44
|
* sets the bounds to the given min and max value
|
|
46
45
|
* @name setMinMax
|
|
47
46
|
* @memberof Bounds
|
|
48
|
-
* @function
|
|
49
47
|
* @param {number} minX
|
|
50
48
|
* @param {number} minY
|
|
51
49
|
* @param {number} maxX
|
|
@@ -205,7 +203,6 @@ class Bounds {
|
|
|
205
203
|
* Updates bounds using the given vertices
|
|
206
204
|
* @name update
|
|
207
205
|
* @memberof Bounds
|
|
208
|
-
* @function
|
|
209
206
|
* @param {Vector2d[]} vertices an array of me.Vector2d points
|
|
210
207
|
*/
|
|
211
208
|
update(vertices) {
|
|
@@ -216,7 +213,6 @@ class Bounds {
|
|
|
216
213
|
* add the given vertices to the bounds definition.
|
|
217
214
|
* @name add
|
|
218
215
|
* @memberof Bounds
|
|
219
|
-
* @function
|
|
220
216
|
* @param {Vector2d[]} vertices an array of me.Vector2d points
|
|
221
217
|
* @param {boolean} [clear=false] either to reset the bounds before adding the new vertices
|
|
222
218
|
*/
|
|
@@ -237,7 +233,6 @@ class Bounds {
|
|
|
237
233
|
* add the given bounds to the bounds definition.
|
|
238
234
|
* @name addBounds
|
|
239
235
|
* @memberof Bounds
|
|
240
|
-
* @function
|
|
241
236
|
* @param {Bounds} bounds
|
|
242
237
|
* @param {boolean} [clear=false] either to reset the bounds before adding the new vertices
|
|
243
238
|
*/
|
|
@@ -256,7 +251,6 @@ class Bounds {
|
|
|
256
251
|
* add the given point to the bounds definition.
|
|
257
252
|
* @name addPoint
|
|
258
253
|
* @memberof Bounds
|
|
259
|
-
* @function
|
|
260
254
|
* @param {Vector2d} v
|
|
261
255
|
* @param {Matrix2d} [m] an optional transform to apply to the given point
|
|
262
256
|
*/
|
|
@@ -274,7 +268,6 @@ class Bounds {
|
|
|
274
268
|
* add the given quad coordinates to this bound definition, multiplied by the given matrix
|
|
275
269
|
* @name addFrame
|
|
276
270
|
* @memberof Bounds
|
|
277
|
-
* @function
|
|
278
271
|
* @param {number} x0 - left X coordinates of the quad
|
|
279
272
|
* @param {number} y0 - top Y coordinates of the quad
|
|
280
273
|
* @param {number} x1 - right X coordinates of the quad
|
|
@@ -282,7 +275,7 @@ class Bounds {
|
|
|
282
275
|
* @param {Matrix2d} [m] an optional transform to apply to the given frame coordinates
|
|
283
276
|
*/
|
|
284
277
|
addFrame(x0, y0, x1, y1, m) {
|
|
285
|
-
var v =
|
|
278
|
+
var v = pool.pull("Vector2d");
|
|
286
279
|
|
|
287
280
|
// transform all points and add to the bound definition
|
|
288
281
|
this.addPoint(v.set(x0, y0), m);
|
|
@@ -290,14 +283,14 @@ class Bounds {
|
|
|
290
283
|
this.addPoint(v.set(x0, y1), m);
|
|
291
284
|
this.addPoint(v.set(x1, y1), m);
|
|
292
285
|
|
|
293
|
-
|
|
286
|
+
pool.push(v);
|
|
294
287
|
}
|
|
295
288
|
|
|
296
289
|
/**
|
|
297
290
|
* Returns true if the bounds contains the given point.
|
|
298
291
|
* @name contains
|
|
299
292
|
* @memberof Bounds
|
|
300
|
-
* @
|
|
293
|
+
* @method
|
|
301
294
|
* @param {Vector2d} point
|
|
302
295
|
* @returns {boolean} True if the bounds contain the point, otherwise false
|
|
303
296
|
*/
|
|
@@ -305,7 +298,6 @@ class Bounds {
|
|
|
305
298
|
* Returns true if the bounds contains the given point.
|
|
306
299
|
* @name contains
|
|
307
300
|
* @memberof Bounds
|
|
308
|
-
* @function
|
|
309
301
|
* @param {number} x
|
|
310
302
|
* @param {number} y
|
|
311
303
|
* @returns {boolean} True if the bounds contain the point, otherwise false
|
|
@@ -339,7 +331,6 @@ class Bounds {
|
|
|
339
331
|
* Returns true if the two bounds intersect.
|
|
340
332
|
* @name overlaps
|
|
341
333
|
* @memberof Bounds
|
|
342
|
-
* @function
|
|
343
334
|
* @param {Bounds|Rect} bounds
|
|
344
335
|
* @returns {boolean} True if the bounds overlap, otherwise false
|
|
345
336
|
*/
|
|
@@ -352,7 +343,6 @@ class Bounds {
|
|
|
352
343
|
* determines whether all coordinates of this bounds are finite numbers.
|
|
353
344
|
* @name isFinite
|
|
354
345
|
* @memberof Bounds
|
|
355
|
-
* @function
|
|
356
346
|
* @returns {boolean} false if all coordinates are positive or negative Infinity or NaN; otherwise, true.
|
|
357
347
|
*/
|
|
358
348
|
isFinite() {
|
|
@@ -363,14 +353,13 @@ class Bounds {
|
|
|
363
353
|
* Translates the bounds by the given vector.
|
|
364
354
|
* @name translate
|
|
365
355
|
* @memberof Bounds
|
|
366
|
-
* @
|
|
356
|
+
* @method
|
|
367
357
|
* @param {Vector2d} vector
|
|
368
358
|
*/
|
|
369
359
|
/**
|
|
370
360
|
* Translates the bounds by x on the x axis, and y on the y axis
|
|
371
361
|
* @name translate
|
|
372
362
|
* @memberof Bounds
|
|
373
|
-
* @function
|
|
374
363
|
* @param {number} x
|
|
375
364
|
* @param {number} y
|
|
376
365
|
*/
|
|
@@ -395,14 +384,13 @@ class Bounds {
|
|
|
395
384
|
* Shifts the bounds to the given position vector.
|
|
396
385
|
* @name shift
|
|
397
386
|
* @memberof Bounds
|
|
398
|
-
* @
|
|
387
|
+
* @method
|
|
399
388
|
* @param {Vector2d} position
|
|
400
389
|
*/
|
|
401
390
|
/**
|
|
402
391
|
* Shifts the bounds to the given x, y position.
|
|
403
392
|
* @name shift
|
|
404
393
|
* @memberof Bounds
|
|
405
|
-
* @function
|
|
406
394
|
* @param {number} x
|
|
407
395
|
* @param {number} y
|
|
408
396
|
*/
|
|
@@ -432,7 +420,6 @@ class Bounds {
|
|
|
432
420
|
* clone this bounds
|
|
433
421
|
* @name clone
|
|
434
422
|
* @memberof Bounds
|
|
435
|
-
* @function
|
|
436
423
|
* @returns {Bounds}
|
|
437
424
|
*/
|
|
438
425
|
clone() {
|
|
@@ -445,7 +432,6 @@ class Bounds {
|
|
|
445
432
|
* Returns a polygon whose edges are the same as this bounds.
|
|
446
433
|
* @name toPolygon
|
|
447
434
|
* @memberof Bounds
|
|
448
|
-
* @function
|
|
449
435
|
* @returns {Polygon} a new Polygon that represents this bounds.
|
|
450
436
|
*/
|
|
451
437
|
toPolygon () {
|
package/src/physics/collision.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { rayCast
|
|
1
|
+
import { rayCast } from "./detector.js";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Collision detection (and projection-based collision response) of 2D shapes.<br>
|
|
@@ -91,23 +91,11 @@ var collision = {
|
|
|
91
91
|
ALL_OBJECT : 0xFFFFFFFF // all objects
|
|
92
92
|
},
|
|
93
93
|
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* a global instance of a response object used for collision detection <br>
|
|
97
|
-
* this object will be reused amongst collision detection call if not user-defined response is specified
|
|
98
|
-
* @name response
|
|
99
|
-
* @memberof collision
|
|
100
|
-
* @public
|
|
101
|
-
* @type {collision.ResponseObject}
|
|
102
|
-
*/
|
|
103
|
-
response : globalResponse,
|
|
104
|
-
|
|
105
94
|
/**
|
|
106
95
|
* Checks for object colliding with the given line
|
|
107
96
|
* @name rayCast
|
|
108
97
|
* @memberof collision
|
|
109
98
|
* @public
|
|
110
|
-
* @function
|
|
111
99
|
* @param {Line} line line to be tested for collision
|
|
112
100
|
* @param {Array.<Renderable>} [result] a user defined array that will be populated with intersecting physic objects.
|
|
113
101
|
* @returns {Array.<Renderable>} an array of intersecting physic objects
|
package/src/physics/detector.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import * as SAT from "./sat.js";
|
|
2
|
+
import ResponseObject from "./response.js";
|
|
2
3
|
import Vector2d from "./../math/vector2.js";
|
|
3
4
|
import { world } from "./../game.js";
|
|
4
5
|
|
|
5
6
|
// a dummy object when using Line for raycasting
|
|
6
|
-
|
|
7
|
+
let dummyObj = {
|
|
7
8
|
pos : new Vector2d(0, 0),
|
|
8
9
|
ancestor : {
|
|
9
10
|
_absPos : new Vector2d(0, 0),
|
|
@@ -13,13 +14,15 @@ var dummyObj = {
|
|
|
13
14
|
}
|
|
14
15
|
};
|
|
15
16
|
|
|
17
|
+
// the global response object used for collisions
|
|
18
|
+
let globalResponse = new ResponseObject();
|
|
19
|
+
|
|
16
20
|
/**
|
|
17
21
|
* a function used to determine if two objects should collide (based on both respective objects collision mask and type).<br>
|
|
18
22
|
* you can redefine this function if you need any specific rules over what should collide with what.
|
|
19
23
|
* @name shouldCollide
|
|
20
24
|
* @memberof collision
|
|
21
25
|
* @ignore
|
|
22
|
-
* @function
|
|
23
26
|
* @param {Renderable} a a reference to the object A.
|
|
24
27
|
* @param {Renderable} b a reference to the object B.
|
|
25
28
|
* @returns {boolean} true if they should collide, false otherwise
|
|
@@ -34,66 +37,14 @@ function shouldCollide(a, b) {
|
|
|
34
37
|
);
|
|
35
38
|
};
|
|
36
39
|
|
|
37
|
-
/**
|
|
38
|
-
* @classdesc
|
|
39
|
-
* An object representing the result of an intersection.
|
|
40
|
-
* @property {Renderable} a The first object participating in the intersection
|
|
41
|
-
* @property {Renderable} b The second object participating in the intersection
|
|
42
|
-
* @property {number} overlap Magnitude of the overlap on the shortest colliding axis
|
|
43
|
-
* @property {Vector2d} overlapV The overlap vector (i.e. `overlapN.scale(overlap, overlap)`). If this vector is subtracted from the position of a, a and b will no longer be colliding
|
|
44
|
-
* @property {Vector2d} overlapN The shortest colliding axis (unit-vector)
|
|
45
|
-
* @property {boolean} aInB Whether the first object is entirely inside the second
|
|
46
|
-
* @property {boolean} bInA Whether the second object is entirely inside the first
|
|
47
|
-
* @property {number} indexShapeA The index of the colliding shape for the object a body
|
|
48
|
-
* @property {number} indexShapeB The index of the colliding shape for the object b body
|
|
49
|
-
* @name ResponseObject
|
|
50
|
-
* @memberof collision
|
|
51
|
-
* @public
|
|
52
|
-
*/
|
|
53
|
-
class ResponseObject {
|
|
54
|
-
constructor() {
|
|
55
|
-
this.a = null;
|
|
56
|
-
this.b = null;
|
|
57
|
-
this.overlapN = new Vector2d();
|
|
58
|
-
this.overlapV = new Vector2d();
|
|
59
|
-
this.aInB = true;
|
|
60
|
-
this.bInA = true;
|
|
61
|
-
this.indexShapeA = -1;
|
|
62
|
-
this.indexShapeB = -1;
|
|
63
|
-
this.overlap = Number.MAX_VALUE;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Set some values of the response back to their defaults. <br>
|
|
68
|
-
* Call this between tests if you are going to reuse a single <br>
|
|
69
|
-
* Response object for multiple intersection tests <br>
|
|
70
|
-
* (recommended as it will avoid allocating extra memory) <br>
|
|
71
|
-
* @name clear
|
|
72
|
-
* @memberof collision.ResponseObject
|
|
73
|
-
* @public
|
|
74
|
-
* @function
|
|
75
|
-
* @returns {object} this object for chaining
|
|
76
|
-
*/
|
|
77
|
-
clear () {
|
|
78
|
-
this.aInB = true;
|
|
79
|
-
this.bInA = true;
|
|
80
|
-
this.overlap = Number.MAX_VALUE;
|
|
81
|
-
this.indexShapeA = -1;
|
|
82
|
-
this.indexShapeB = -1;
|
|
83
|
-
return this;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
40
|
|
|
87
|
-
// @ignore
|
|
88
|
-
export var globalResponse = new ResponseObject();
|
|
89
41
|
|
|
90
42
|
/**
|
|
91
43
|
* find all the collisions for the specified object
|
|
92
44
|
* @name collisionCheck
|
|
93
45
|
* @ignore
|
|
94
|
-
* @function
|
|
95
46
|
* @param {Renderable} objA object to be tested for collision
|
|
96
|
-
* @param {
|
|
47
|
+
* @param {ResponseObject} [response] a user defined response object that will be populated if they intersect.
|
|
97
48
|
* @returns {boolean} in case of collision, false otherwise
|
|
98
49
|
*/
|
|
99
50
|
export function collisionCheck(objA, response = globalResponse) {
|
|
@@ -163,7 +114,6 @@ export function collisionCheck(objA, response = globalResponse) {
|
|
|
163
114
|
* Checks for object colliding with the given line
|
|
164
115
|
* @name rayCast
|
|
165
116
|
* @ignore
|
|
166
|
-
* @function
|
|
167
117
|
* @param {Line} line line to be tested for collision
|
|
168
118
|
* @param {Array.<Renderable>} [result] a user defined array that will be populated with intersecting physic objects.
|
|
169
119
|
* @returns {Array.<Renderable>} an array of intersecting physic objects
|
package/src/physics/quadtree.js
CHANGED
|
@@ -165,7 +165,6 @@ class QuadTree {
|
|
|
165
165
|
* Insert the given object container into the node.
|
|
166
166
|
* @name insertContainer
|
|
167
167
|
* @memberof QuadTree
|
|
168
|
-
* @function
|
|
169
168
|
* @param {Container} container group of objects to be added
|
|
170
169
|
*/
|
|
171
170
|
insertContainer(container) {
|
|
@@ -194,7 +193,6 @@ class QuadTree {
|
|
|
194
193
|
* objects to their corresponding subnodes.
|
|
195
194
|
* @name insert
|
|
196
195
|
* @memberof QuadTree
|
|
197
|
-
* @function
|
|
198
196
|
* @param {object} item object to be added
|
|
199
197
|
*/
|
|
200
198
|
insert(item) {
|
|
@@ -239,7 +237,6 @@ class QuadTree {
|
|
|
239
237
|
* Return all objects that could collide with the given object
|
|
240
238
|
* @name retrieve
|
|
241
239
|
* @memberof QuadTree
|
|
242
|
-
* @function
|
|
243
240
|
* @param {object} item object to be checked against
|
|
244
241
|
* @param {object} [fn] a sorting function for the returned array
|
|
245
242
|
* @returns {object[]} array with all detected objects
|
|
@@ -275,7 +272,6 @@ class QuadTree {
|
|
|
275
272
|
* (this function won't recalculate the impacted node)
|
|
276
273
|
* @name remove
|
|
277
274
|
* @memberof QuadTree
|
|
278
|
-
* @function
|
|
279
275
|
* @param {object} item object to be removed
|
|
280
276
|
* @returns {boolean} true if the item was found and removed.
|
|
281
277
|
*/
|
|
@@ -316,7 +312,6 @@ class QuadTree {
|
|
|
316
312
|
* return true if the node is prunable
|
|
317
313
|
* @name isPrunable
|
|
318
314
|
* @memberof QuadTree
|
|
319
|
-
* @function
|
|
320
315
|
* @returns {boolean} true if the node is prunable
|
|
321
316
|
*/
|
|
322
317
|
isPrunable() {
|
|
@@ -327,7 +322,6 @@ class QuadTree {
|
|
|
327
322
|
* return true if the node has any children
|
|
328
323
|
* @name hasChildren
|
|
329
324
|
* @memberof QuadTree
|
|
330
|
-
* @function
|
|
331
325
|
* @returns {boolean} true if the node has any children
|
|
332
326
|
*/
|
|
333
327
|
hasChildren() {
|
|
@@ -344,7 +338,6 @@ class QuadTree {
|
|
|
344
338
|
* clear the quadtree
|
|
345
339
|
* @name clear
|
|
346
340
|
* @memberof QuadTree
|
|
347
|
-
* @function
|
|
348
341
|
* @param {Bounds} [bounds=this.bounds] the bounds to be cleared
|
|
349
342
|
*/
|
|
350
343
|
clear(bounds) {
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import Vector2d from "./../math/vector2.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @classdesc
|
|
5
|
+
* An object representing the result of an intersection.
|
|
6
|
+
* @property {Renderable} a The first object participating in the intersection
|
|
7
|
+
* @property {Renderable} b The second object participating in the intersection
|
|
8
|
+
* @property {number} overlap Magnitude of the overlap on the shortest colliding axis
|
|
9
|
+
* @property {Vector2d} overlapV The overlap vector (i.e. `overlapN.scale(overlap, overlap)`). If this vector is subtracted from the position of a, a and b will no longer be colliding
|
|
10
|
+
* @property {Vector2d} overlapN The shortest colliding axis (unit-vector)
|
|
11
|
+
* @property {boolean} aInB Whether the first object is entirely inside the second
|
|
12
|
+
* @property {boolean} bInA Whether the second object is entirely inside the first
|
|
13
|
+
* @property {number} indexShapeA The index of the colliding shape for the object a body
|
|
14
|
+
* @property {number} indexShapeB The index of the colliding shape for the object b body
|
|
15
|
+
* @name ResponseObject
|
|
16
|
+
* @public
|
|
17
|
+
*/
|
|
18
|
+
export default class ResponseObject {
|
|
19
|
+
constructor() {
|
|
20
|
+
this.a = null;
|
|
21
|
+
this.b = null;
|
|
22
|
+
this.overlapN = new Vector2d();
|
|
23
|
+
this.overlapV = new Vector2d();
|
|
24
|
+
this.aInB = true;
|
|
25
|
+
this.bInA = true;
|
|
26
|
+
this.indexShapeA = -1;
|
|
27
|
+
this.indexShapeB = -1;
|
|
28
|
+
this.overlap = Number.MAX_VALUE;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Set some values of the response back to their defaults. <br>
|
|
33
|
+
* Call this between tests if you are going to reuse a single <br>
|
|
34
|
+
* Response object for multiple intersection tests <br>
|
|
35
|
+
* (recommended as it will avoid allocating extra memory) <br>
|
|
36
|
+
* @name clear
|
|
37
|
+
* @public
|
|
38
|
+
* @returns {object} this object for chaining
|
|
39
|
+
*/
|
|
40
|
+
clear () {
|
|
41
|
+
this.aInB = true;
|
|
42
|
+
this.bInA = true;
|
|
43
|
+
this.overlap = Number.MAX_VALUE;
|
|
44
|
+
this.indexShapeA = -1;
|
|
45
|
+
this.indexShapeB = -1;
|
|
46
|
+
return this;
|
|
47
|
+
}
|
|
48
|
+
}
|
package/src/physics/sat.js
CHANGED
|
@@ -9,19 +9,19 @@ import Vector2d from "./../math/vector2.js";
|
|
|
9
9
|
* Constants for Vornoi regions
|
|
10
10
|
* @ignore
|
|
11
11
|
*/
|
|
12
|
-
|
|
12
|
+
const LEFT_VORNOI_REGION = -1;
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* Constants for Vornoi regions
|
|
16
16
|
* @ignore
|
|
17
17
|
*/
|
|
18
|
-
|
|
18
|
+
const MIDDLE_VORNOI_REGION = 0;
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
21
|
* Constants for Vornoi regions
|
|
22
22
|
* @ignore
|
|
23
23
|
*/
|
|
24
|
-
|
|
24
|
+
const RIGHT_VORNOI_REGION = 1;
|
|
25
25
|
|
|
26
26
|
|
|
27
27
|
/**
|
|
@@ -458,7 +458,7 @@ export function testPolygonEllipse(a, polyA, b, ellipseB, response) {
|
|
|
458
458
|
*/
|
|
459
459
|
export function testEllipsePolygon(a, ellipseA, b, polyB, response) {
|
|
460
460
|
// Test the polygon against the circle.
|
|
461
|
-
var result =
|
|
461
|
+
var result = testPolygonEllipse(b, polyB, a, ellipseA, response);
|
|
462
462
|
if (result && response) {
|
|
463
463
|
// Swap A and B in the response.
|
|
464
464
|
var resa = response.a;
|
package/src/physics/world.js
CHANGED
|
@@ -96,7 +96,6 @@ class World extends Container {
|
|
|
96
96
|
* reset the game world
|
|
97
97
|
* @name reset
|
|
98
98
|
* @memberof World
|
|
99
|
-
* @function
|
|
100
99
|
*/
|
|
101
100
|
reset() {
|
|
102
101
|
// clear the quadtree
|
|
@@ -118,7 +117,6 @@ class World extends Container {
|
|
|
118
117
|
* @name addBody
|
|
119
118
|
* @memberof World
|
|
120
119
|
* @see Container.addChild
|
|
121
|
-
* @function
|
|
122
120
|
* @param {Body} body
|
|
123
121
|
* @returns {World} this game world
|
|
124
122
|
*/
|
|
@@ -133,7 +131,6 @@ class World extends Container {
|
|
|
133
131
|
* @name removeBody
|
|
134
132
|
* @memberof World
|
|
135
133
|
* @see Container.removeChild
|
|
136
|
-
* @function
|
|
137
134
|
* @param {Body} body
|
|
138
135
|
* @returns {World} this game world
|
|
139
136
|
*/
|
|
@@ -147,7 +144,6 @@ class World extends Container {
|
|
|
147
144
|
* update the game world
|
|
148
145
|
* @name reset
|
|
149
146
|
* @memberof World
|
|
150
|
-
* @function
|
|
151
147
|
* @param {number} dt the time passed since the last frame update
|
|
152
148
|
* @returns {boolean} true if the word is dirty
|
|
153
149
|
*/
|
package/src/plugin/plugin.js
CHANGED
|
@@ -44,7 +44,6 @@ export var plugin = {
|
|
|
44
44
|
* @name patch
|
|
45
45
|
* @memberof plugin
|
|
46
46
|
* @public
|
|
47
|
-
* @function
|
|
48
47
|
* @param {object} proto target object
|
|
49
48
|
* @param {string} name target function
|
|
50
49
|
* @param {Function} fn replacement function
|
|
@@ -90,7 +89,6 @@ export var plugin = {
|
|
|
90
89
|
* @memberof plugin
|
|
91
90
|
* @see Base
|
|
92
91
|
* @public
|
|
93
|
-
* @function
|
|
94
92
|
* @param {plugin.Base} pluginObj Plugin object to instantiate and register
|
|
95
93
|
* @param {string} name
|
|
96
94
|
* @param {object} [...arguments] all extra parameters will be passed to the plugin constructor
|
|
@@ -218,8 +218,10 @@
|
|
|
218
218
|
}
|
|
219
219
|
}
|
|
220
220
|
|
|
221
|
-
if (
|
|
222
|
-
|
|
221
|
+
if (globalThis.CanvasRenderingContext2D) {
|
|
222
|
+
if (typeof globalThis.Path2D.prototype.roundRect === "undefined") {
|
|
223
|
+
globalThis.Path2D.prototype.roundRect = roundRect;
|
|
224
|
+
}
|
|
223
225
|
}
|
|
224
226
|
if (globalThis.CanvasRenderingContext2D) {
|
|
225
227
|
if (typeof globalThis.CanvasRenderingContext2D.prototype.roundRect === "undefined") {
|
package/src/renderable/GUI.js
CHANGED
|
@@ -116,13 +116,12 @@ class GUI_Object extends Sprite {
|
|
|
116
116
|
/**
|
|
117
117
|
* function called when the object is pressed (to be extended)
|
|
118
118
|
* @name onClick
|
|
119
|
-
* @memberof GUI_Object
|
|
119
|
+
* @memberof GUI_Object
|
|
120
120
|
* @public
|
|
121
|
-
* @function
|
|
122
121
|
* @param {Pointer} event the event object
|
|
123
122
|
* @returns {boolean} return false if we need to stop propagating the event
|
|
124
123
|
*/
|
|
125
|
-
onClick(
|
|
124
|
+
onClick(event) { // eslint-disable-line no-unused-vars
|
|
126
125
|
return false;
|
|
127
126
|
}
|
|
128
127
|
|
|
@@ -139,12 +138,13 @@ class GUI_Object extends Sprite {
|
|
|
139
138
|
/**
|
|
140
139
|
* function called when the pointer is over the object
|
|
141
140
|
* @name onOver
|
|
142
|
-
* @memberof GUI_Object
|
|
141
|
+
* @memberof GUI_Object
|
|
143
142
|
* @public
|
|
144
|
-
* @function
|
|
145
143
|
* @param {Pointer} event the event object
|
|
146
144
|
*/
|
|
147
|
-
onOver(
|
|
145
|
+
onOver(event) { // eslint-disable-line no-unused-vars
|
|
146
|
+
// to be extended
|
|
147
|
+
}
|
|
148
148
|
|
|
149
149
|
/**
|
|
150
150
|
* function callback for the pointerLeave event
|
|
@@ -160,13 +160,12 @@ class GUI_Object extends Sprite {
|
|
|
160
160
|
/**
|
|
161
161
|
* function called when the pointer is leaving the object area
|
|
162
162
|
* @name onOut
|
|
163
|
-
* @memberof GUI_Object
|
|
163
|
+
* @memberof GUI_Object
|
|
164
164
|
* @public
|
|
165
|
-
* @function
|
|
166
165
|
* @param {Pointer} event the event object
|
|
167
166
|
*/
|
|
168
|
-
onOut(
|
|
169
|
-
|
|
167
|
+
onOut(event) { // eslint-disable-line no-unused-vars
|
|
168
|
+
// to be extended
|
|
170
169
|
}
|
|
171
170
|
|
|
172
171
|
/**
|
|
@@ -185,9 +184,8 @@ class GUI_Object extends Sprite {
|
|
|
185
184
|
/**
|
|
186
185
|
* function called when the object is pressed and released (to be extended)
|
|
187
186
|
* @name onRelease
|
|
188
|
-
* @memberof GUI_Object
|
|
187
|
+
* @memberof GUI_Object
|
|
189
188
|
* @public
|
|
190
|
-
* @function
|
|
191
189
|
* @returns {boolean} return false if we need to stop propagating the event
|
|
192
190
|
*/
|
|
193
191
|
onRelease() {
|
|
@@ -210,9 +208,8 @@ class GUI_Object extends Sprite {
|
|
|
210
208
|
* function called when the object is pressed and held<br>
|
|
211
209
|
* to be extended <br>
|
|
212
210
|
* @name onHold
|
|
213
|
-
* @memberof GUI_Object
|
|
211
|
+
* @memberof GUI_Object
|
|
214
212
|
* @public
|
|
215
|
-
* @function
|
|
216
213
|
*/
|
|
217
214
|
onHold() {}
|
|
218
215
|
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import pool from "./../system/pooling.js";
|
|
2
|
-
import { viewport } from "./../game.js";
|
|
3
2
|
import Renderable from "./renderable.js";
|
|
4
3
|
|
|
5
4
|
|
|
@@ -41,15 +40,18 @@ class ColorLayer extends Renderable {
|
|
|
41
40
|
}
|
|
42
41
|
|
|
43
42
|
/**
|
|
44
|
-
* draw
|
|
45
|
-
* @
|
|
43
|
+
* draw this color layer (automatically called by melonJS)
|
|
44
|
+
* @name draw
|
|
45
|
+
* @memberof ColorLayer
|
|
46
|
+
* @protected
|
|
47
|
+
* @param {CanvasRenderer|WebGLRenderer} renderer a renderer instance
|
|
48
|
+
* @param {Camera2d} [viewport] the viewport to (re)draw
|
|
46
49
|
*/
|
|
47
|
-
draw(renderer,
|
|
48
|
-
var vpos = viewport.pos;
|
|
50
|
+
draw(renderer, viewport) {
|
|
49
51
|
renderer.save();
|
|
50
52
|
renderer.clipRect(
|
|
51
|
-
|
|
52
|
-
|
|
53
|
+
0, 0,
|
|
54
|
+
viewport.width, viewport.height
|
|
53
55
|
);
|
|
54
56
|
renderer.clearColor(this.color);
|
|
55
57
|
renderer.restore();
|