melonjs 10.2.1 → 10.2.2
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 +2735 -2760
- package/dist/melonjs.min.js +3 -3
- package/dist/melonjs.module.d.ts +2186 -2162
- package/dist/melonjs.module.js +2323 -2362
- package/package.json +8 -9
- package/src/audio/audio.js +43 -43
- package/src/camera/camera2d.js +52 -74
- package/src/entity/draggable.js +18 -17
- package/src/entity/droptarget.js +19 -18
- package/src/entity/entity.js +22 -26
- package/src/game.js +2 -2
- package/src/index.js +11 -11
- package/src/input/gamepad.js +13 -13
- package/src/input/input.js +1 -1
- package/src/input/keyboard.js +14 -16
- package/src/input/pointer.js +42 -35
- package/src/input/pointerevent.js +18 -26
- package/src/lang/deprecated.js +3 -3
- package/src/level/level.js +24 -16
- package/src/level/tiled/TMXGroup.js +6 -6
- package/src/level/tiled/TMXLayer.js +31 -31
- package/src/level/tiled/TMXObject.js +19 -19
- package/src/level/tiled/TMXTile.js +11 -12
- package/src/level/tiled/TMXTileMap.js +23 -21
- package/src/level/tiled/TMXTileset.js +13 -13
- package/src/level/tiled/TMXTilesetGroup.js +4 -4
- package/src/level/tiled/TMXUtils.js +13 -11
- package/src/level/tiled/renderer/TMXHexagonalRenderer.js +1 -1
- package/src/level/tiled/renderer/TMXIsometricRenderer.js +1 -1
- package/src/level/tiled/renderer/TMXRenderer.js +17 -17
- package/src/loader/loader.js +29 -25
- package/src/math/color.js +45 -64
- package/src/math/math.js +17 -17
- package/src/math/matrix2.js +46 -46
- package/src/math/matrix3.js +64 -64
- package/src/math/observable_vector2.js +45 -57
- package/src/math/observable_vector3.js +56 -70
- package/src/math/vector2.js +60 -59
- package/src/math/vector3.js +65 -64
- package/src/particles/emitter.js +53 -55
- package/src/particles/particle.js +1 -1
- package/src/physics/body.js +44 -44
- package/src/physics/bounds.js +34 -34
- package/src/physics/collision.js +15 -16
- package/src/physics/detector.js +10 -10
- package/src/physics/quadtree.js +19 -17
- package/src/physics/sat.js +17 -17
- package/src/physics/world.js +12 -10
- package/src/plugin/plugin.js +6 -6
- package/src/renderable/GUI.js +13 -18
- package/src/renderable/collectable.js +3 -3
- package/src/renderable/colorlayer.js +4 -4
- package/src/renderable/container.js +64 -46
- package/src/renderable/imagelayer.js +30 -31
- package/src/renderable/nineslicesprite.js +13 -13
- package/src/renderable/renderable.js +68 -66
- package/src/renderable/sprite.js +57 -43
- package/src/renderable/trigger.js +14 -15
- package/src/shapes/ellipse.js +27 -26
- package/src/shapes/line.js +8 -7
- package/src/shapes/poly.js +33 -31
- package/src/shapes/rectangle.js +50 -96
- package/src/state/stage.js +6 -6
- package/src/state/state.js +54 -54
- package/src/system/device.js +97 -84
- package/src/system/event.js +72 -72
- package/src/system/pooling.js +14 -14
- package/src/system/save.js +6 -3
- package/src/system/timer.js +20 -20
- package/src/text/bitmaptext.js +27 -33
- package/src/text/bitmaptextdata.js +9 -9
- package/src/text/text.js +39 -41
- package/src/tweens/easing.js +4 -4
- package/src/tweens/interpolation.js +4 -4
- package/src/tweens/tween.js +37 -27
- package/src/utils/agent.js +9 -8
- package/src/utils/array.js +4 -4
- package/src/utils/file.js +4 -4
- package/src/utils/function.js +5 -5
- package/src/utils/string.js +12 -12
- package/src/utils/utils.js +19 -19
- package/src/video/canvas/canvas_renderer.js +90 -90
- package/src/video/renderer.js +40 -39
- package/src/video/texture.js +74 -75
- package/src/video/video.js +30 -30
- package/src/video/webgl/buffer/vertex.js +9 -1
- package/src/video/webgl/glshader.js +20 -20
- package/src/video/webgl/webgl_compositor.js +33 -34
- package/src/video/webgl/webgl_renderer.js +104 -104
package/src/physics/bounds.js
CHANGED
|
@@ -9,7 +9,7 @@ import Polygon from "./../shapes/poly.js";
|
|
|
9
9
|
* @constructor
|
|
10
10
|
* @memberOf me
|
|
11
11
|
* @param {me.Vector2d[]} [vertices] an array of me.Vector2d points
|
|
12
|
-
* @
|
|
12
|
+
* @returns {me.Bounds} A new bounds object
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
15
|
class Bounds {
|
|
@@ -49,10 +49,10 @@ class Bounds {
|
|
|
49
49
|
* @name setMinMax
|
|
50
50
|
* @memberOf me.Bounds
|
|
51
51
|
* @function
|
|
52
|
-
* @param {
|
|
53
|
-
* @param {
|
|
54
|
-
* @param {
|
|
55
|
-
* @param {
|
|
52
|
+
* @param {number} minX
|
|
53
|
+
* @param {number} minY
|
|
54
|
+
* @param {number} maxX
|
|
55
|
+
* @param {number} maxY
|
|
56
56
|
*/
|
|
57
57
|
setMinMax(minX, minY, maxX, maxY) {
|
|
58
58
|
this.min.x = minX;
|
|
@@ -65,7 +65,7 @@ class Bounds {
|
|
|
65
65
|
/**
|
|
66
66
|
* x position of the bound
|
|
67
67
|
* @public
|
|
68
|
-
* @type {
|
|
68
|
+
* @type {number}
|
|
69
69
|
* @name x
|
|
70
70
|
* @memberOf me.Bounds
|
|
71
71
|
*/
|
|
@@ -82,7 +82,7 @@ class Bounds {
|
|
|
82
82
|
/**
|
|
83
83
|
* y position of the bounds
|
|
84
84
|
* @public
|
|
85
|
-
* @type {
|
|
85
|
+
* @type {number}
|
|
86
86
|
* @name y
|
|
87
87
|
* @memberOf me.Bounds
|
|
88
88
|
*/
|
|
@@ -100,7 +100,7 @@ class Bounds {
|
|
|
100
100
|
/**
|
|
101
101
|
* width of the bounds
|
|
102
102
|
* @public
|
|
103
|
-
* @type {
|
|
103
|
+
* @type {number}
|
|
104
104
|
* @name width
|
|
105
105
|
* @memberOf me.Bounds
|
|
106
106
|
*/
|
|
@@ -115,7 +115,7 @@ class Bounds {
|
|
|
115
115
|
/**
|
|
116
116
|
* width of the bounds
|
|
117
117
|
* @public
|
|
118
|
-
* @type {
|
|
118
|
+
* @type {number}
|
|
119
119
|
* @name width
|
|
120
120
|
* @memberOf me.Bounds
|
|
121
121
|
*/
|
|
@@ -130,7 +130,7 @@ class Bounds {
|
|
|
130
130
|
/**
|
|
131
131
|
* left coordinate of the bound
|
|
132
132
|
* @public
|
|
133
|
-
* @type {
|
|
133
|
+
* @type {number}
|
|
134
134
|
* @name left
|
|
135
135
|
* @memberOf me.Bounds
|
|
136
136
|
*/
|
|
@@ -141,7 +141,7 @@ class Bounds {
|
|
|
141
141
|
/**
|
|
142
142
|
* right coordinate of the bound
|
|
143
143
|
* @public
|
|
144
|
-
* @type {
|
|
144
|
+
* @type {number}
|
|
145
145
|
* @name right
|
|
146
146
|
* @memberOf me.Bounds
|
|
147
147
|
*/
|
|
@@ -152,7 +152,7 @@ class Bounds {
|
|
|
152
152
|
/**
|
|
153
153
|
* top coordinate of the bound
|
|
154
154
|
* @public
|
|
155
|
-
* @type {
|
|
155
|
+
* @type {number}
|
|
156
156
|
* @name top
|
|
157
157
|
* @memberOf me.Bounds
|
|
158
158
|
*/
|
|
@@ -163,7 +163,7 @@ class Bounds {
|
|
|
163
163
|
/**
|
|
164
164
|
* bottom coordinate of the bound
|
|
165
165
|
* @public
|
|
166
|
-
* @type {
|
|
166
|
+
* @type {number}
|
|
167
167
|
* @name bottom
|
|
168
168
|
* @memberOf me.Bounds
|
|
169
169
|
*/
|
|
@@ -174,7 +174,7 @@ class Bounds {
|
|
|
174
174
|
/**
|
|
175
175
|
* center position of the bound on the x axis
|
|
176
176
|
* @public
|
|
177
|
-
* @type {
|
|
177
|
+
* @type {number}
|
|
178
178
|
* @name centerX
|
|
179
179
|
* @memberOf me.Bounds
|
|
180
180
|
*/
|
|
@@ -185,7 +185,7 @@ class Bounds {
|
|
|
185
185
|
/**
|
|
186
186
|
* center position of the bound on the y axis
|
|
187
187
|
* @public
|
|
188
|
-
* @type {
|
|
188
|
+
* @type {number}
|
|
189
189
|
* @name centerY
|
|
190
190
|
* @memberOf me.Bounds
|
|
191
191
|
*/
|
|
@@ -260,8 +260,8 @@ class Bounds {
|
|
|
260
260
|
* @name addPoint
|
|
261
261
|
* @memberOf me.Bounds
|
|
262
262
|
* @function
|
|
263
|
-
* @param {me.Vector2d}
|
|
264
|
-
* @param {me.Matrix2d} [
|
|
263
|
+
* @param {me.Vector2d} v
|
|
264
|
+
* @param {me.Matrix2d} [m] an optional transform to apply to the given point
|
|
265
265
|
*/
|
|
266
266
|
addPoint(v, m) {
|
|
267
267
|
if (typeof m !== "undefined") {
|
|
@@ -278,11 +278,11 @@ class Bounds {
|
|
|
278
278
|
* @name addFrame
|
|
279
279
|
* @memberOf me.Bounds
|
|
280
280
|
* @function
|
|
281
|
-
* @param {
|
|
282
|
-
* @param {
|
|
283
|
-
* @param {
|
|
284
|
-
* @param {
|
|
285
|
-
* @param {me.Matrix2d} [
|
|
281
|
+
* @param {number} x0 - left X coordinates of the quad
|
|
282
|
+
* @param {number} y0 - top Y coordinates of the quad
|
|
283
|
+
* @param {number} x1 - right X coordinates of the quad
|
|
284
|
+
* @param {number} y1 - bottom y coordinates of the quad
|
|
285
|
+
* @param {me.Matrix2d} [m] an optional transform to apply to the given frame coordinates
|
|
286
286
|
*/
|
|
287
287
|
addFrame(x0, y0, x1, y1, m) {
|
|
288
288
|
var v = me.pool.pull("Vector2d");
|
|
@@ -302,16 +302,16 @@ class Bounds {
|
|
|
302
302
|
* @memberOf me.Bounds
|
|
303
303
|
* @function
|
|
304
304
|
* @param {me.Vector2d} point
|
|
305
|
-
* @
|
|
305
|
+
* @returns {boolean} True if the bounds contain the point, otherwise false
|
|
306
306
|
*/
|
|
307
307
|
/**
|
|
308
308
|
* Returns true if the bounds contains the given point.
|
|
309
309
|
* @name contains
|
|
310
310
|
* @memberOf me.Bounds
|
|
311
311
|
* @function
|
|
312
|
-
* @param {
|
|
313
|
-
* @param {
|
|
314
|
-
* @
|
|
312
|
+
* @param {number} x
|
|
313
|
+
* @param {number} y
|
|
314
|
+
* @returns {boolean} True if the bounds contain the point, otherwise false
|
|
315
315
|
*/
|
|
316
316
|
contains() {
|
|
317
317
|
var arg0 = arguments[0];
|
|
@@ -344,7 +344,7 @@ class Bounds {
|
|
|
344
344
|
* @memberOf me.Bounds
|
|
345
345
|
* @function
|
|
346
346
|
* @param {me.Bounds|me.Rect} bounds
|
|
347
|
-
* @
|
|
347
|
+
* @returns {boolean} True if the bounds overlap, otherwise false
|
|
348
348
|
*/
|
|
349
349
|
overlaps(bounds) {
|
|
350
350
|
return !(this.right < bounds.left || this.left > bounds.right ||
|
|
@@ -356,7 +356,7 @@ class Bounds {
|
|
|
356
356
|
* @name isFinite
|
|
357
357
|
* @memberOf me.Bounds
|
|
358
358
|
* @function
|
|
359
|
-
* @
|
|
359
|
+
* @returns {boolean} false if all coordinates are positive or negative Infinity or NaN; otherwise, true.
|
|
360
360
|
*/
|
|
361
361
|
isFinite() {
|
|
362
362
|
return (isFinite(this.min.x) && isFinite(this.max.x) && isFinite(this.min.y) && isFinite(this.max.y));
|
|
@@ -374,8 +374,8 @@ class Bounds {
|
|
|
374
374
|
* @name translate
|
|
375
375
|
* @memberOf me.Bounds
|
|
376
376
|
* @function
|
|
377
|
-
* @param {
|
|
378
|
-
* @param {
|
|
377
|
+
* @param {number} x
|
|
378
|
+
* @param {number} y
|
|
379
379
|
*/
|
|
380
380
|
translate() {
|
|
381
381
|
var _x, _y;
|
|
@@ -406,8 +406,8 @@ class Bounds {
|
|
|
406
406
|
* @name shift
|
|
407
407
|
* @memberOf me.Bounds
|
|
408
408
|
* @function
|
|
409
|
-
* @param {
|
|
410
|
-
* @param {
|
|
409
|
+
* @param {number} x
|
|
410
|
+
* @param {number} y
|
|
411
411
|
*/
|
|
412
412
|
shift() {
|
|
413
413
|
var _x, _y;
|
|
@@ -436,7 +436,7 @@ class Bounds {
|
|
|
436
436
|
* @name clone
|
|
437
437
|
* @memberOf me.Bounds
|
|
438
438
|
* @function
|
|
439
|
-
* @
|
|
439
|
+
* @returns {me.Bounds}
|
|
440
440
|
*/
|
|
441
441
|
clone() {
|
|
442
442
|
var bounds = new Bounds();
|
|
@@ -449,7 +449,7 @@ class Bounds {
|
|
|
449
449
|
* @name toPolygon
|
|
450
450
|
* @memberOf me.Bounds
|
|
451
451
|
* @function
|
|
452
|
-
* @
|
|
452
|
+
* @returns {me.Polygon} a new Polygon that represents this bounds.
|
|
453
453
|
*/
|
|
454
454
|
toPolygon () {
|
|
455
455
|
return new Polygon(this.x, this.y, [
|
package/src/physics/collision.js
CHANGED
|
@@ -14,7 +14,7 @@ var collision = {
|
|
|
14
14
|
* @name maxChildren
|
|
15
15
|
* @memberOf me.collision
|
|
16
16
|
* @public
|
|
17
|
-
* @type {
|
|
17
|
+
* @type {number}
|
|
18
18
|
* @default 8
|
|
19
19
|
* @see me.game.world.broadphase
|
|
20
20
|
*/
|
|
@@ -25,27 +25,26 @@ var collision = {
|
|
|
25
25
|
* @name maxDepth
|
|
26
26
|
* @memberOf me.collision
|
|
27
27
|
* @public
|
|
28
|
-
* @type {
|
|
28
|
+
* @type {number}
|
|
29
29
|
* @default 4
|
|
30
30
|
* @see me.game.world.broadphase
|
|
31
|
-
*
|
|
32
31
|
*/
|
|
33
32
|
maxDepth : 4,
|
|
34
33
|
|
|
35
34
|
/**
|
|
36
35
|
* Enum for collision type values.
|
|
37
|
-
* @property NO_OBJECT to disable collision check
|
|
38
|
-
* @property PLAYER_OBJECT
|
|
39
|
-
* @property NPC_OBJECT
|
|
40
|
-
* @property ENEMY_OBJECT
|
|
41
|
-
* @property COLLECTABLE_OBJECT
|
|
42
|
-
* @property ACTION_OBJECT e.g. doors
|
|
43
|
-
* @property PROJECTILE_OBJECT e.g. missiles
|
|
44
|
-
* @property WORLD_SHAPE e.g. walls; for map collision shapes
|
|
45
|
-
* @property USER user-defined collision types (see example)
|
|
46
|
-
* @property ALL_OBJECT all of the above (including user-defined types)
|
|
36
|
+
* @property {number} NO_OBJECT to disable collision check
|
|
37
|
+
* @property {number} PLAYER_OBJECT playbable characters
|
|
38
|
+
* @property {number} NPC_OBJECT non playable characters
|
|
39
|
+
* @property {number} ENEMY_OBJECT enemies objects
|
|
40
|
+
* @property {number} COLLECTABLE_OBJECT collectable objects
|
|
41
|
+
* @property {number} ACTION_OBJECT e.g. doors
|
|
42
|
+
* @property {number} PROJECTILE_OBJECT e.g. missiles
|
|
43
|
+
* @property {number} WORLD_SHAPE e.g. walls; for map collision shapes
|
|
44
|
+
* @property {number} USER user-defined collision types (see example)
|
|
45
|
+
* @property {number} ALL_OBJECT all of the above (including user-defined types)
|
|
47
46
|
* @readonly
|
|
48
|
-
* @enum {
|
|
47
|
+
* @enum {number}
|
|
49
48
|
* @name types
|
|
50
49
|
* @memberOf me.collision
|
|
51
50
|
* @see me.body.setCollisionMask
|
|
@@ -112,7 +111,7 @@ var collision = {
|
|
|
112
111
|
* @function
|
|
113
112
|
* @param {me.Line} line line to be tested for collision
|
|
114
113
|
* @param {Array.<me.Renderable>} [result] a user defined array that will be populated with intersecting physic objects.
|
|
115
|
-
* @
|
|
114
|
+
* @returns {Array.<me.Renderable>} an array of intersecting physic objects
|
|
116
115
|
* @example
|
|
117
116
|
* // define a line accross the viewport
|
|
118
117
|
* var ray = new me.Line(
|
|
@@ -131,7 +130,7 @@ var collision = {
|
|
|
131
130
|
* // ...
|
|
132
131
|
* }
|
|
133
132
|
*/
|
|
134
|
-
rayCast(line,
|
|
133
|
+
rayCast(line, result) { return rayCast(line, result); }
|
|
135
134
|
};
|
|
136
135
|
|
|
137
136
|
export default collision;
|
package/src/physics/detector.js
CHANGED
|
@@ -22,7 +22,7 @@ var dummyObj = {
|
|
|
22
22
|
* @function
|
|
23
23
|
* @param {me.Renderable} a a reference to the object A.
|
|
24
24
|
* @param {me.Renderable} b a reference to the object B.
|
|
25
|
-
* @
|
|
25
|
+
* @returns {boolean} true if they should collide, false otherwise
|
|
26
26
|
*/
|
|
27
27
|
function shouldCollide(a, b) {
|
|
28
28
|
return (
|
|
@@ -38,13 +38,13 @@ function shouldCollide(a, b) {
|
|
|
38
38
|
* An object representing the result of an intersection.
|
|
39
39
|
* @property {me.Renderable} a The first object participating in the intersection
|
|
40
40
|
* @property {me.Renderable} b The second object participating in the intersection
|
|
41
|
-
* @property {
|
|
41
|
+
* @property {number} overlap Magnitude of the overlap on the shortest colliding axis
|
|
42
42
|
* @property {me.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
|
|
43
43
|
* @property {me.Vector2d} overlapN The shortest colliding axis (unit-vector)
|
|
44
|
-
* @property {
|
|
45
|
-
* @property {
|
|
46
|
-
* @property {
|
|
47
|
-
* @property {
|
|
44
|
+
* @property {boolean} aInB Whether the first object is entirely inside the second
|
|
45
|
+
* @property {boolean} bInA Whether the second object is entirely inside the first
|
|
46
|
+
* @property {number} indexShapeA The index of the colliding shape for the object a body
|
|
47
|
+
* @property {number} indexShapeB The index of the colliding shape for the object b body
|
|
48
48
|
* @name ResponseObject
|
|
49
49
|
* @memberOf me.collision
|
|
50
50
|
* @public
|
|
@@ -60,7 +60,6 @@ class ResponseObject {
|
|
|
60
60
|
this.indexShapeA = -1;
|
|
61
61
|
this.indexShapeB = -1;
|
|
62
62
|
this.overlap = Number.MAX_VALUE;
|
|
63
|
-
return this;
|
|
64
63
|
}
|
|
65
64
|
|
|
66
65
|
/**
|
|
@@ -72,6 +71,7 @@ class ResponseObject {
|
|
|
72
71
|
* @memberOf me.collision.ResponseObject
|
|
73
72
|
* @public
|
|
74
73
|
* @function
|
|
74
|
+
* @returns {object} this object for chaining
|
|
75
75
|
*/
|
|
76
76
|
clear () {
|
|
77
77
|
this.aInB = true;
|
|
@@ -91,9 +91,9 @@ export var globalResponse = new ResponseObject();
|
|
|
91
91
|
* @name collisionCheck
|
|
92
92
|
* @ignore
|
|
93
93
|
* @function
|
|
94
|
-
* @param {me.Renderable}
|
|
94
|
+
* @param {me.Renderable} objA object to be tested for collision
|
|
95
95
|
* @param {me.collision.ResponseObject} [response=me.collision.response] a user defined response object that will be populated if they intersect.
|
|
96
|
-
* @
|
|
96
|
+
* @returns {boolean} in case of collision, false otherwise
|
|
97
97
|
*/
|
|
98
98
|
export function collisionCheck(objA, response = globalResponse) {
|
|
99
99
|
var collisionCounter = 0;
|
|
@@ -165,7 +165,7 @@ export function collisionCheck(objA, response = globalResponse) {
|
|
|
165
165
|
* @function
|
|
166
166
|
* @param {me.Line} line line to be tested for collision
|
|
167
167
|
* @param {Array.<me.Renderable>} [result] a user defined array that will be populated with intersecting physic objects.
|
|
168
|
-
* @
|
|
168
|
+
* @returns {Array.<me.Renderable>} an array of intersecting physic objects
|
|
169
169
|
* @example
|
|
170
170
|
* // define a line accross the viewport
|
|
171
171
|
* var ray = new me.Line(
|
package/src/physics/quadtree.js
CHANGED
|
@@ -57,9 +57,9 @@ var QT_VECTOR = new Vector2d();
|
|
|
57
57
|
* @constructor
|
|
58
58
|
* @see me.game.world.broadphase
|
|
59
59
|
* @param {me.Bounds} bounds bounds of the node
|
|
60
|
-
* @param {
|
|
61
|
-
* @param {
|
|
62
|
-
* @param {
|
|
60
|
+
* @param {number} [max_objects=4] max objects a node can hold before splitting into 4 subnodes
|
|
61
|
+
* @param {number} [max_levels=4] total max levels inside root Quadtree
|
|
62
|
+
* @param {number} [level] deepth level, required for subnodes
|
|
63
63
|
*/
|
|
64
64
|
class QuadTree {
|
|
65
65
|
|
|
@@ -120,23 +120,24 @@ class QuadTree {
|
|
|
120
120
|
/*
|
|
121
121
|
* Determine which node the object belongs to
|
|
122
122
|
* @param {me.Rect} rect bounds of the area to be checked
|
|
123
|
-
* @
|
|
123
|
+
* @returns Integer index of the subnode (0-3), or -1 if rect cannot completely fit within a subnode and is part of the parent node
|
|
124
124
|
*/
|
|
125
125
|
getIndex(item) {
|
|
126
126
|
var pos;
|
|
127
|
+
var bounds = item.getBounds();
|
|
127
128
|
|
|
128
129
|
// use game world coordinates for floating items
|
|
129
|
-
if (item.
|
|
130
|
-
pos = viewport.localToWorld(
|
|
130
|
+
if (item.isFloating === true) {
|
|
131
|
+
pos = viewport.localToWorld(bounds.left, bounds.top, QT_VECTOR);
|
|
131
132
|
} else {
|
|
132
|
-
pos = QT_VECTOR.set(
|
|
133
|
+
pos = QT_VECTOR.set(bounds.left, bounds.top);
|
|
133
134
|
}
|
|
134
135
|
|
|
135
136
|
var index = -1,
|
|
136
137
|
rx = pos.x,
|
|
137
138
|
ry = pos.y,
|
|
138
|
-
rw =
|
|
139
|
-
rh =
|
|
139
|
+
rw = bounds.width,
|
|
140
|
+
rh = bounds.height,
|
|
140
141
|
verticalMidpoint = this.bounds.left + (this.bounds.width / 2),
|
|
141
142
|
horizontalMidpoint = this.bounds.top + (this.bounds.height / 2),
|
|
142
143
|
//rect can completely fit within the top quadrants
|
|
@@ -197,7 +198,7 @@ class QuadTree {
|
|
|
197
198
|
* @name insert
|
|
198
199
|
* @memberOf me.QuadTree
|
|
199
200
|
* @function
|
|
200
|
-
* @param {
|
|
201
|
+
* @param {object} item object to be added
|
|
201
202
|
*/
|
|
202
203
|
insert(item) {
|
|
203
204
|
var index = -1;
|
|
@@ -242,9 +243,9 @@ class QuadTree {
|
|
|
242
243
|
* @name retrieve
|
|
243
244
|
* @memberOf me.QuadTree
|
|
244
245
|
* @function
|
|
245
|
-
* @param {
|
|
246
|
-
* @param {
|
|
247
|
-
* @
|
|
246
|
+
* @param {object} item object to be checked against
|
|
247
|
+
* @param {object} [fn] a sorting function for the returned array
|
|
248
|
+
* @returns {object[]} array with all detected objects
|
|
248
249
|
*/
|
|
249
250
|
retrieve(item, fn) {
|
|
250
251
|
var returnObjects = this.objects;
|
|
@@ -278,8 +279,8 @@ class QuadTree {
|
|
|
278
279
|
* @name remove
|
|
279
280
|
* @memberOf me.QuadTree
|
|
280
281
|
* @function
|
|
281
|
-
* @param {
|
|
282
|
-
* @
|
|
282
|
+
* @param {object} item object to be removed
|
|
283
|
+
* @returns {boolean} true if the item was found and removed.
|
|
283
284
|
*/
|
|
284
285
|
remove(item) {
|
|
285
286
|
var found = false;
|
|
@@ -319,7 +320,7 @@ class QuadTree {
|
|
|
319
320
|
* @name isPrunable
|
|
320
321
|
* @memberOf me.QuadTree
|
|
321
322
|
* @function
|
|
322
|
-
* @
|
|
323
|
+
* @returns {boolean} true if the node is prunable
|
|
323
324
|
*/
|
|
324
325
|
isPrunable() {
|
|
325
326
|
return !(this.hasChildren() || (this.objects.length > 0));
|
|
@@ -330,7 +331,7 @@ class QuadTree {
|
|
|
330
331
|
* @name hasChildren
|
|
331
332
|
* @memberOf me.QuadTree
|
|
332
333
|
* @function
|
|
333
|
-
* @
|
|
334
|
+
* @returns {boolean} true if the node has any children
|
|
334
335
|
*/
|
|
335
336
|
hasChildren() {
|
|
336
337
|
for (var i = 0; i < this.nodes.length; i = i + 1) {
|
|
@@ -347,6 +348,7 @@ class QuadTree {
|
|
|
347
348
|
* @name clear
|
|
348
349
|
* @memberOf me.QuadTree
|
|
349
350
|
* @function
|
|
351
|
+
* @param {me.Bounds} [bounds=this.bounds] the bounds to be cleared
|
|
350
352
|
*/
|
|
351
353
|
clear(bounds) {
|
|
352
354
|
this.objects.length = 0;
|
package/src/physics/sat.js
CHANGED
|
@@ -26,7 +26,7 @@ var RIGHT_VORNOI_REGION = 1;
|
|
|
26
26
|
|
|
27
27
|
/**
|
|
28
28
|
* A pool of `Vector` objects that are used in calculations to avoid allocating memory.
|
|
29
|
-
* @type {Array.<
|
|
29
|
+
* @type {Array.<me.Vector2d>}
|
|
30
30
|
* @ignore
|
|
31
31
|
*/
|
|
32
32
|
var T_VECTORS = [];
|
|
@@ -46,8 +46,8 @@ for (var a = 0; a < 5; a++) { T_ARRAYS.push([]); }
|
|
|
46
46
|
* resulting in a one dimensional range of the minimum and
|
|
47
47
|
* maximum value on that axis.
|
|
48
48
|
* @ignore
|
|
49
|
-
* @param {Array.<
|
|
50
|
-
* @param {
|
|
49
|
+
* @param {Array.<me.Vector2d>} points The points to flatten.
|
|
50
|
+
* @param {me.Vector2d} normal The unit vector axis to flatten on.
|
|
51
51
|
* @param {Array.<number>} result An array. After calling this function,
|
|
52
52
|
* result[0] will be the minimum value,
|
|
53
53
|
* result[1] will be the maximum value.
|
|
@@ -70,15 +70,15 @@ function flattenPointsOn(points, normal, result) {
|
|
|
70
70
|
* Check whether two convex polygons are separated by the specified
|
|
71
71
|
* axis (must be a unit vector).
|
|
72
72
|
* @ignore
|
|
73
|
-
* @param {
|
|
74
|
-
* @param {
|
|
75
|
-
* @param {Array.<
|
|
76
|
-
* @param {Array.<
|
|
77
|
-
* @param {
|
|
73
|
+
* @param {me.Vector2d} aPos The position of the first polygon.
|
|
74
|
+
* @param {me.Vector2d} bPos The position of the second polygon.
|
|
75
|
+
* @param {Array.<me.Vector2d>} aPoints The points in the first polygon.
|
|
76
|
+
* @param {Array.<me.Vector2d>} bPoints The points in the second polygon.
|
|
77
|
+
* @param {me.Vector2d} axis The axis (unit sized) to test against. The points of both polygons
|
|
78
78
|
* will be projected onto this axis.
|
|
79
79
|
* @param {Response=} response A Response object (optional) which will be populated
|
|
80
80
|
* if the axis is not a separating axis.
|
|
81
|
-
* @
|
|
81
|
+
* @returns {boolean} true if it is a separating axis, false otherwise. If false,
|
|
82
82
|
* and a response is passed in, information about how much overlap and
|
|
83
83
|
* the direction of the overlap will be populated.
|
|
84
84
|
*/
|
|
@@ -161,9 +161,9 @@ function isSeparatingAxis(aPos, bPos, aPoints, bPoints, axis, response) {
|
|
|
161
161
|
* </pre>
|
|
162
162
|
*
|
|
163
163
|
* @ignore
|
|
164
|
-
* @param {
|
|
165
|
-
* @param {
|
|
166
|
-
* @
|
|
164
|
+
* @param {me.Vector2d} line The line segment.
|
|
165
|
+
* @param {me.Vector2d} point The point.
|
|
166
|
+
* @returns {number} LEFT_VORNOI_REGION (-1) if it is the left region,
|
|
167
167
|
* MIDDLE_VORNOI_REGION (0) if it is the middle region,
|
|
168
168
|
* RIGHT_VORNOI_REGION (1) if it is the right region.
|
|
169
169
|
*/
|
|
@@ -192,7 +192,7 @@ function vornoiRegion(line, point) {
|
|
|
192
192
|
* @param {me.Renderable} b a reference to the object B.
|
|
193
193
|
* @param {me.Polygon} polyB a reference to the object B Polygon to be tested
|
|
194
194
|
* @param {Response=} response Response object (optional) that will be populated if they intersect.
|
|
195
|
-
* @
|
|
195
|
+
* @returns {boolean} true if they intersect, false if they don't.
|
|
196
196
|
*/
|
|
197
197
|
export function testPolygonPolygon(a, polyA, b, polyB, response) {
|
|
198
198
|
// specific point for
|
|
@@ -247,7 +247,7 @@ export function testPolygonPolygon(a, polyA, b, polyB, response) {
|
|
|
247
247
|
* @param {me.Ellipse} ellipseB a reference to the object B Ellipse to be tested
|
|
248
248
|
* @param {Response=} response Response object (optional) that will be populated if
|
|
249
249
|
* the circles intersect.
|
|
250
|
-
* @
|
|
250
|
+
* @returns {boolean} true if the circles intersect, false if they don't.
|
|
251
251
|
*/
|
|
252
252
|
export function testEllipseEllipse(a, ellipseA, b, ellipseB, response) {
|
|
253
253
|
// Check if the distance between the centers of the two
|
|
@@ -287,7 +287,7 @@ export function testEllipseEllipse(a, ellipseA, b, ellipseB, response) {
|
|
|
287
287
|
* @param {me.Renderable} b a reference to the object B.
|
|
288
288
|
* @param {me.Ellipse} ellipseB a reference to the object B Ellipse to be tested
|
|
289
289
|
* @param {Response=} response Response object (optional) that will be populated if they intersect.
|
|
290
|
-
* @
|
|
290
|
+
* @returns {boolean} true if they intersect, false if they don't.
|
|
291
291
|
*/
|
|
292
292
|
export function testPolygonEllipse(a, polyA, b, ellipseB, response) {
|
|
293
293
|
// Get the position of the circle relative to the polygon.
|
|
@@ -450,11 +450,11 @@ export function testPolygonEllipse(a, polyA, b, ellipseB, response) {
|
|
|
450
450
|
* @ignore
|
|
451
451
|
* @param {me.Renderable} a a reference to the object A.
|
|
452
452
|
* @param {me.Ellipse} ellipseA a reference to the object A Ellipse to be tested
|
|
453
|
-
* @param {me.Renderable}
|
|
453
|
+
* @param {me.Renderable} b a reference to the object B.
|
|
454
454
|
* @param {me.Polygon} polyB a reference to the object B Polygon to be tested
|
|
455
455
|
* @param {Response=} response Response object (optional) that will be populated if
|
|
456
456
|
* they intersect.
|
|
457
|
-
* @
|
|
457
|
+
* @returns {boolean} true if they intersect, false if they don't.
|
|
458
458
|
*/
|
|
459
459
|
export function testEllipsePolygon(a, ellipseA, b, polyB, response) {
|
|
460
460
|
// Test the polygon against the circle.
|
package/src/physics/world.js
CHANGED
|
@@ -7,16 +7,16 @@ import { collisionCheck } from "./detector.js";
|
|
|
7
7
|
import state from "./../state/state.js";
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
|
-
* @classdesc
|
|
10
|
+
* @classdesc
|
|
11
11
|
* an object representing the physic world, and responsible for managing and updating all childs and physics
|
|
12
12
|
* @class World
|
|
13
13
|
* @extends me.Container
|
|
14
14
|
* @memberOf me
|
|
15
15
|
* @constructor
|
|
16
|
-
* @param {
|
|
17
|
-
* @param {
|
|
18
|
-
* @param {
|
|
19
|
-
* @param {
|
|
16
|
+
* @param {number} [x=0] position of the container (accessible via the inherited pos.x property)
|
|
17
|
+
* @param {number} [y=0] position of the container (accessible via the inherited pos.y property)
|
|
18
|
+
* @param {number} [w=me.game.viewport.width] width of the container
|
|
19
|
+
* @param {number} [h=me.game.viewport.height] height of the container
|
|
20
20
|
*/
|
|
21
21
|
class World extends Container {
|
|
22
22
|
/**
|
|
@@ -37,7 +37,7 @@ class World extends Container {
|
|
|
37
37
|
* the rate at which the game world is updated,
|
|
38
38
|
* may be greater than or lower than the display fps
|
|
39
39
|
* @public
|
|
40
|
-
* @type me.Vector2d
|
|
40
|
+
* @type {me.Vector2d}
|
|
41
41
|
* @default 60
|
|
42
42
|
* @name fps
|
|
43
43
|
* @memberOf me.World
|
|
@@ -48,7 +48,7 @@ class World extends Container {
|
|
|
48
48
|
/**
|
|
49
49
|
* world gravity
|
|
50
50
|
* @public
|
|
51
|
-
* @type me.Vector2d
|
|
51
|
+
* @type {me.Vector2d}
|
|
52
52
|
* @default <0,0.98>
|
|
53
53
|
* @name gravity
|
|
54
54
|
* @memberOf me.World
|
|
@@ -63,7 +63,7 @@ class World extends Container {
|
|
|
63
63
|
* (amount of layer, layer size, amount of tiles per layer, etc.)<br>
|
|
64
64
|
* note : rendering method is also configurable per layer by adding this
|
|
65
65
|
* property to your layer (in Tiled).
|
|
66
|
-
* @type {
|
|
66
|
+
* @type {boolean}
|
|
67
67
|
* @default false
|
|
68
68
|
* @memberOf me.World
|
|
69
69
|
*/
|
|
@@ -125,7 +125,7 @@ class World extends Container {
|
|
|
125
125
|
* @see me.Container.addChild
|
|
126
126
|
* @function
|
|
127
127
|
* @param {me.Body} body
|
|
128
|
-
* @
|
|
128
|
+
* @returns {me.World} this game world
|
|
129
129
|
*/
|
|
130
130
|
addBody(body) {
|
|
131
131
|
//add it to the list of active body
|
|
@@ -140,7 +140,7 @@ class World extends Container {
|
|
|
140
140
|
* @see me.Container.removeChild
|
|
141
141
|
* @function
|
|
142
142
|
* @param {me.Body} body
|
|
143
|
-
* @
|
|
143
|
+
* @returns {me.World} this game world
|
|
144
144
|
*/
|
|
145
145
|
removeBody(body) {
|
|
146
146
|
//remove from the list of active body
|
|
@@ -153,6 +153,8 @@ class World extends Container {
|
|
|
153
153
|
* @name reset
|
|
154
154
|
* @memberOf me.World
|
|
155
155
|
* @function
|
|
156
|
+
* @param {number} dt the time passed since the last frame update
|
|
157
|
+
* @returns {boolean} true if the word is dirty
|
|
156
158
|
*/
|
|
157
159
|
update (dt) {
|
|
158
160
|
var isPaused = state.isPaused();
|
package/src/plugin/plugin.js
CHANGED
|
@@ -17,7 +17,7 @@ class BasePlugin {
|
|
|
17
17
|
* define the minimum required version of melonJS<br>
|
|
18
18
|
* this can be overridden by the plugin
|
|
19
19
|
* @public
|
|
20
|
-
* @type
|
|
20
|
+
* @type {string}
|
|
21
21
|
* @default "__VERSION__"
|
|
22
22
|
* @name me.plugin.Base#version
|
|
23
23
|
*/
|
|
@@ -49,8 +49,8 @@ export var plugin = {
|
|
|
49
49
|
* @memberOf me.plugin
|
|
50
50
|
* @public
|
|
51
51
|
* @function
|
|
52
|
-
* @param {
|
|
53
|
-
* @param {
|
|
52
|
+
* @param {object} proto target object
|
|
53
|
+
* @param {string} name target function
|
|
54
54
|
* @param {Function} fn replacement function
|
|
55
55
|
* @example
|
|
56
56
|
* // redefine the me.game.update function with a new one
|
|
@@ -95,9 +95,9 @@ export var plugin = {
|
|
|
95
95
|
* @see me.plugin.Base
|
|
96
96
|
* @public
|
|
97
97
|
* @function
|
|
98
|
-
* @param {me.plugin.Base}
|
|
99
|
-
* @param {
|
|
100
|
-
* @param {} [arguments
|
|
98
|
+
* @param {me.plugin.Base} pluginObj Plugin object to instantiate and register
|
|
99
|
+
* @param {string} name
|
|
100
|
+
* @param {object} [...arguments] all extra parameters will be passed to the plugin constructor
|
|
101
101
|
* @example
|
|
102
102
|
* // register a new plugin
|
|
103
103
|
* me.plugin.register(TestPlugin, "testPlugin");
|