melonjs 10.3.0 → 10.5.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/README.md +6 -6
- package/dist/melonjs.js +3147 -3293
- package/dist/melonjs.min.js +4 -4
- package/dist/melonjs.module.d.ts +3411 -3852
- package/dist/melonjs.module.js +3448 -3210
- package/package.json +18 -17
- package/src/audio/audio.js +29 -30
- package/src/camera/camera2d.js +46 -56
- package/src/entity/entity.js +30 -36
- package/src/game.js +21 -22
- package/src/geometries/ellipse.js +40 -46
- package/src/geometries/line.js +9 -11
- package/src/geometries/poly.js +53 -53
- package/src/geometries/rectangle.js +42 -44
- package/src/index.js +9 -26
- package/src/input/gamepad.js +11 -10
- package/src/input/input.js +2 -3
- package/src/input/keyboard.js +113 -113
- package/src/input/pointer.js +30 -31
- package/src/input/pointerevent.js +26 -26
- package/src/lang/deprecated.js +65 -6
- package/src/level/level.js +23 -24
- package/src/level/tiled/TMXGroup.js +7 -8
- package/src/level/tiled/TMXLayer.js +30 -32
- package/src/level/tiled/TMXObject.js +21 -21
- package/src/level/tiled/TMXTile.js +18 -18
- package/src/level/tiled/TMXTileMap.js +39 -44
- package/src/level/tiled/TMXTileset.js +12 -15
- package/src/level/tiled/TMXTilesetGroup.js +9 -9
- package/src/level/tiled/renderer/TMXHexagonalRenderer.js +7 -8
- package/src/level/tiled/renderer/TMXIsometricRenderer.js +7 -8
- package/src/level/tiled/renderer/TMXOrthogonalRenderer.js +4 -5
- package/src/level/tiled/renderer/TMXRenderer.js +24 -25
- package/src/level/tiled/renderer/TMXStaggeredRenderer.js +1 -4
- package/src/loader/loader.js +14 -15
- package/src/loader/loadingscreen.js +2 -4
- package/src/math/color.js +47 -66
- package/src/math/math.js +15 -16
- package/src/math/matrix2.js +53 -58
- package/src/math/matrix3.js +56 -62
- package/src/math/observable_vector2.js +75 -76
- package/src/math/observable_vector3.js +79 -80
- package/src/math/vector2.js +91 -92
- package/src/math/vector3.js +94 -96
- package/src/particles/emitter.js +38 -40
- package/src/particles/particle.js +4 -5
- package/src/particles/particlecontainer.js +2 -3
- package/src/physics/body.js +46 -143
- package/src/physics/bounds.js +47 -47
- package/src/physics/collision.js +13 -14
- package/src/physics/detector.js +18 -17
- package/src/physics/quadtree.js +17 -19
- package/src/physics/sat.js +26 -26
- package/src/physics/world.js +24 -28
- package/src/plugin/plugin.js +11 -14
- package/src/renderable/GUI.js +41 -46
- package/src/renderable/collectable.js +4 -8
- package/src/renderable/colorlayer.js +6 -10
- package/src/renderable/container.js +87 -72
- package/src/renderable/dragndrop.js +224 -0
- package/src/renderable/imagelayer.js +25 -31
- package/src/renderable/nineslicesprite.js +41 -41
- package/src/renderable/renderable.js +114 -125
- package/src/renderable/sprite.js +62 -68
- package/src/renderable/trigger.js +25 -30
- package/src/state/stage.js +13 -17
- package/src/state/state.js +26 -27
- package/src/system/device.js +74 -75
- package/src/system/event.js +71 -72
- package/src/system/pooling.js +11 -12
- package/src/system/save.js +3 -4
- package/src/system/timer.js +19 -20
- package/src/text/bitmaptext.js +57 -54
- package/src/text/bitmaptextdata.js +10 -10
- package/src/text/glyph.js +3 -0
- package/src/text/text.js +44 -49
- package/src/tweens/easing.js +1 -1
- package/src/tweens/interpolation.js +1 -1
- package/src/tweens/tween.js +43 -44
- package/src/utils/agent.js +3 -4
- package/src/utils/array.js +4 -5
- package/src/utils/file.js +3 -4
- package/src/utils/function.js +4 -5
- package/src/utils/string.js +7 -9
- package/src/utils/utils.js +4 -5
- package/src/video/canvas/canvas_renderer.js +58 -59
- package/src/video/renderer.js +49 -53
- package/src/video/texture.js +98 -111
- package/src/video/texture_cache.js +24 -6
- package/src/video/video.js +16 -17
- package/src/video/webgl/glshader.js +37 -38
- package/src/video/webgl/webgl_compositor.js +31 -32
- package/src/video/webgl/webgl_renderer.js +79 -80
- package/src/entity/draggable.js +0 -130
- package/src/entity/droptarget.js +0 -101
package/src/physics/bounds.js
CHANGED
|
@@ -4,18 +4,18 @@ import Polygon from "./../geometries/poly.js";
|
|
|
4
4
|
/**
|
|
5
5
|
* @classdesc
|
|
6
6
|
* a bound object contains methods for creating and manipulating axis-aligned bounding boxes (AABB).
|
|
7
|
-
* @class Bounds
|
|
8
|
-
* @memberof me
|
|
9
|
-
* @param {me.Vector2d[]} [vertices] an array of me.Vector2d points
|
|
10
|
-
* @returns {me.Bounds} A new bounds object
|
|
11
7
|
*/
|
|
12
|
-
|
|
13
8
|
class Bounds {
|
|
14
|
-
|
|
9
|
+
/**
|
|
10
|
+
* @param {Vector2d[]} [vertices] an array of me.Vector2d points
|
|
11
|
+
*/
|
|
15
12
|
constructor(vertices) {
|
|
16
13
|
this.onResetEvent(vertices);
|
|
17
14
|
}
|
|
18
15
|
|
|
16
|
+
/**
|
|
17
|
+
* @ignore
|
|
18
|
+
*/
|
|
19
19
|
onResetEvent(vertices) {
|
|
20
20
|
if (typeof this.min === "undefined") {
|
|
21
21
|
this.min = { x: Infinity, y: Infinity };
|
|
@@ -34,7 +34,7 @@ class Bounds {
|
|
|
34
34
|
/**
|
|
35
35
|
* reset the bound
|
|
36
36
|
* @name clear
|
|
37
|
-
* @memberof
|
|
37
|
+
* @memberof Bounds
|
|
38
38
|
* @function
|
|
39
39
|
*/
|
|
40
40
|
clear() {
|
|
@@ -45,7 +45,7 @@ class Bounds {
|
|
|
45
45
|
/**
|
|
46
46
|
* sets the bounds to the given min and max value
|
|
47
47
|
* @name setMinMax
|
|
48
|
-
* @memberof
|
|
48
|
+
* @memberof Bounds
|
|
49
49
|
* @function
|
|
50
50
|
* @param {number} minX
|
|
51
51
|
* @param {number} minY
|
|
@@ -65,7 +65,7 @@ class Bounds {
|
|
|
65
65
|
* @public
|
|
66
66
|
* @type {number}
|
|
67
67
|
* @name x
|
|
68
|
-
* @memberof
|
|
68
|
+
* @memberof Bounds
|
|
69
69
|
*/
|
|
70
70
|
get x() {
|
|
71
71
|
return this.min.x;
|
|
@@ -82,7 +82,7 @@ class Bounds {
|
|
|
82
82
|
* @public
|
|
83
83
|
* @type {number}
|
|
84
84
|
* @name y
|
|
85
|
-
* @memberof
|
|
85
|
+
* @memberof Bounds
|
|
86
86
|
*/
|
|
87
87
|
get y() {
|
|
88
88
|
return this.min.y;
|
|
@@ -100,7 +100,7 @@ class Bounds {
|
|
|
100
100
|
* @public
|
|
101
101
|
* @type {number}
|
|
102
102
|
* @name width
|
|
103
|
-
* @memberof
|
|
103
|
+
* @memberof Bounds
|
|
104
104
|
*/
|
|
105
105
|
get width() {
|
|
106
106
|
return this.max.x - this.min.x;
|
|
@@ -115,7 +115,7 @@ class Bounds {
|
|
|
115
115
|
* @public
|
|
116
116
|
* @type {number}
|
|
117
117
|
* @name width
|
|
118
|
-
* @memberof
|
|
118
|
+
* @memberof Bounds
|
|
119
119
|
*/
|
|
120
120
|
get height() {
|
|
121
121
|
return this.max.y - this.min.y;
|
|
@@ -130,7 +130,7 @@ class Bounds {
|
|
|
130
130
|
* @public
|
|
131
131
|
* @type {number}
|
|
132
132
|
* @name left
|
|
133
|
-
* @memberof
|
|
133
|
+
* @memberof Bounds
|
|
134
134
|
*/
|
|
135
135
|
get left() {
|
|
136
136
|
return this.min.x;
|
|
@@ -141,7 +141,7 @@ class Bounds {
|
|
|
141
141
|
* @public
|
|
142
142
|
* @type {number}
|
|
143
143
|
* @name right
|
|
144
|
-
* @memberof
|
|
144
|
+
* @memberof Bounds
|
|
145
145
|
*/
|
|
146
146
|
get right() {
|
|
147
147
|
return this.max.x;
|
|
@@ -152,7 +152,7 @@ class Bounds {
|
|
|
152
152
|
* @public
|
|
153
153
|
* @type {number}
|
|
154
154
|
* @name top
|
|
155
|
-
* @memberof
|
|
155
|
+
* @memberof Bounds
|
|
156
156
|
*/
|
|
157
157
|
get top() {
|
|
158
158
|
return this.min.y;
|
|
@@ -163,7 +163,7 @@ class Bounds {
|
|
|
163
163
|
* @public
|
|
164
164
|
* @type {number}
|
|
165
165
|
* @name bottom
|
|
166
|
-
* @memberof
|
|
166
|
+
* @memberof Bounds
|
|
167
167
|
*/
|
|
168
168
|
get bottom() {
|
|
169
169
|
return this.max.y;
|
|
@@ -174,7 +174,7 @@ class Bounds {
|
|
|
174
174
|
* @public
|
|
175
175
|
* @type {number}
|
|
176
176
|
* @name centerX
|
|
177
|
-
* @memberof
|
|
177
|
+
* @memberof Bounds
|
|
178
178
|
*/
|
|
179
179
|
get centerX() {
|
|
180
180
|
return this.min.x + (this.width / 2);
|
|
@@ -185,7 +185,7 @@ class Bounds {
|
|
|
185
185
|
* @public
|
|
186
186
|
* @type {number}
|
|
187
187
|
* @name centerY
|
|
188
|
-
* @memberof
|
|
188
|
+
* @memberof Bounds
|
|
189
189
|
*/
|
|
190
190
|
get centerY() {
|
|
191
191
|
return this.min.y + (this.height / 2);
|
|
@@ -194,9 +194,9 @@ class Bounds {
|
|
|
194
194
|
/**
|
|
195
195
|
* return the center position of the bound
|
|
196
196
|
* @public
|
|
197
|
-
* @type {
|
|
197
|
+
* @type {Vector2d}
|
|
198
198
|
* @name center
|
|
199
|
-
* @memberof
|
|
199
|
+
* @memberof Bounds
|
|
200
200
|
*/
|
|
201
201
|
get center() {
|
|
202
202
|
return this._center.set(this.centerX, this.centerY);
|
|
@@ -205,9 +205,9 @@ class Bounds {
|
|
|
205
205
|
/**
|
|
206
206
|
* Updates bounds using the given vertices
|
|
207
207
|
* @name update
|
|
208
|
-
* @memberof
|
|
208
|
+
* @memberof Bounds
|
|
209
209
|
* @function
|
|
210
|
-
* @param {
|
|
210
|
+
* @param {Vector2d[]} vertices an array of me.Vector2d points
|
|
211
211
|
*/
|
|
212
212
|
update(vertices) {
|
|
213
213
|
this.add(vertices, true);
|
|
@@ -216,9 +216,9 @@ class Bounds {
|
|
|
216
216
|
/**
|
|
217
217
|
* add the given vertices to the bounds definition.
|
|
218
218
|
* @name add
|
|
219
|
-
* @memberof
|
|
219
|
+
* @memberof Bounds
|
|
220
220
|
* @function
|
|
221
|
-
* @param {
|
|
221
|
+
* @param {Vector2d[]} vertices an array of me.Vector2d points
|
|
222
222
|
* @param {boolean} [clear=false] either to reset the bounds before adding the new vertices
|
|
223
223
|
*/
|
|
224
224
|
add(vertices, clear = false) {
|
|
@@ -237,9 +237,9 @@ class Bounds {
|
|
|
237
237
|
/**
|
|
238
238
|
* add the given bounds to the bounds definition.
|
|
239
239
|
* @name addBounds
|
|
240
|
-
* @memberof
|
|
240
|
+
* @memberof Bounds
|
|
241
241
|
* @function
|
|
242
|
-
* @param {
|
|
242
|
+
* @param {Bounds} bounds
|
|
243
243
|
* @param {boolean} [clear=false] either to reset the bounds before adding the new vertices
|
|
244
244
|
*/
|
|
245
245
|
addBounds(bounds, clear = false) {
|
|
@@ -256,10 +256,10 @@ class Bounds {
|
|
|
256
256
|
/**
|
|
257
257
|
* add the given point to the bounds definition.
|
|
258
258
|
* @name addPoint
|
|
259
|
-
* @memberof
|
|
259
|
+
* @memberof Bounds
|
|
260
260
|
* @function
|
|
261
|
-
* @param {
|
|
262
|
-
* @param {
|
|
261
|
+
* @param {Vector2d} v
|
|
262
|
+
* @param {Matrix2d} [m] an optional transform to apply to the given point
|
|
263
263
|
*/
|
|
264
264
|
addPoint(v, m) {
|
|
265
265
|
if (typeof m !== "undefined") {
|
|
@@ -274,13 +274,13 @@ class Bounds {
|
|
|
274
274
|
/**
|
|
275
275
|
* add the given quad coordinates to this bound definition, multiplied by the given matrix
|
|
276
276
|
* @name addFrame
|
|
277
|
-
* @memberof
|
|
277
|
+
* @memberof Bounds
|
|
278
278
|
* @function
|
|
279
279
|
* @param {number} x0 - left X coordinates of the quad
|
|
280
280
|
* @param {number} y0 - top Y coordinates of the quad
|
|
281
281
|
* @param {number} x1 - right X coordinates of the quad
|
|
282
282
|
* @param {number} y1 - bottom y coordinates of the quad
|
|
283
|
-
* @param {
|
|
283
|
+
* @param {Matrix2d} [m] an optional transform to apply to the given frame coordinates
|
|
284
284
|
*/
|
|
285
285
|
addFrame(x0, y0, x1, y1, m) {
|
|
286
286
|
var v = me.pool.pull("Vector2d");
|
|
@@ -297,15 +297,15 @@ class Bounds {
|
|
|
297
297
|
/**
|
|
298
298
|
* Returns true if the bounds contains the given point.
|
|
299
299
|
* @name contains
|
|
300
|
-
* @memberof
|
|
300
|
+
* @memberof Bounds
|
|
301
301
|
* @function
|
|
302
|
-
* @param {
|
|
302
|
+
* @param {Vector2d} point
|
|
303
303
|
* @returns {boolean} True if the bounds contain the point, otherwise false
|
|
304
304
|
*/
|
|
305
305
|
/**
|
|
306
306
|
* Returns true if the bounds contains the given point.
|
|
307
307
|
* @name contains
|
|
308
|
-
* @memberof
|
|
308
|
+
* @memberof Bounds
|
|
309
309
|
* @function
|
|
310
310
|
* @param {number} x
|
|
311
311
|
* @param {number} y
|
|
@@ -339,9 +339,9 @@ class Bounds {
|
|
|
339
339
|
/**
|
|
340
340
|
* Returns true if the two bounds intersect.
|
|
341
341
|
* @name overlaps
|
|
342
|
-
* @memberof
|
|
342
|
+
* @memberof Bounds
|
|
343
343
|
* @function
|
|
344
|
-
* @param {
|
|
344
|
+
* @param {Bounds|Rect} bounds
|
|
345
345
|
* @returns {boolean} True if the bounds overlap, otherwise false
|
|
346
346
|
*/
|
|
347
347
|
overlaps(bounds) {
|
|
@@ -352,7 +352,7 @@ class Bounds {
|
|
|
352
352
|
/**
|
|
353
353
|
* determines whether all coordinates of this bounds are finite numbers.
|
|
354
354
|
* @name isFinite
|
|
355
|
-
* @memberof
|
|
355
|
+
* @memberof Bounds
|
|
356
356
|
* @function
|
|
357
357
|
* @returns {boolean} false if all coordinates are positive or negative Infinity or NaN; otherwise, true.
|
|
358
358
|
*/
|
|
@@ -363,14 +363,14 @@ class Bounds {
|
|
|
363
363
|
/**
|
|
364
364
|
* Translates the bounds by the given vector.
|
|
365
365
|
* @name translate
|
|
366
|
-
* @memberof
|
|
366
|
+
* @memberof Bounds
|
|
367
367
|
* @function
|
|
368
|
-
* @param {
|
|
368
|
+
* @param {Vector2d} vector
|
|
369
369
|
*/
|
|
370
370
|
/**
|
|
371
371
|
* Translates the bounds by x on the x axis, and y on the y axis
|
|
372
372
|
* @name translate
|
|
373
|
-
* @memberof
|
|
373
|
+
* @memberof Bounds
|
|
374
374
|
* @function
|
|
375
375
|
* @param {number} x
|
|
376
376
|
* @param {number} y
|
|
@@ -395,14 +395,14 @@ class Bounds {
|
|
|
395
395
|
/**
|
|
396
396
|
* Shifts the bounds to the given position vector.
|
|
397
397
|
* @name shift
|
|
398
|
-
* @memberof
|
|
398
|
+
* @memberof Bounds
|
|
399
399
|
* @function
|
|
400
|
-
* @param {
|
|
400
|
+
* @param {Vector2d} position
|
|
401
401
|
*/
|
|
402
402
|
/**
|
|
403
403
|
* Shifts the bounds to the given x, y position.
|
|
404
404
|
* @name shift
|
|
405
|
-
* @memberof
|
|
405
|
+
* @memberof Bounds
|
|
406
406
|
* @function
|
|
407
407
|
* @param {number} x
|
|
408
408
|
* @param {number} y
|
|
@@ -432,9 +432,9 @@ class Bounds {
|
|
|
432
432
|
/**
|
|
433
433
|
* clone this bounds
|
|
434
434
|
* @name clone
|
|
435
|
-
* @memberof
|
|
435
|
+
* @memberof Bounds
|
|
436
436
|
* @function
|
|
437
|
-
* @returns {
|
|
437
|
+
* @returns {Bounds}
|
|
438
438
|
*/
|
|
439
439
|
clone() {
|
|
440
440
|
var bounds = new Bounds();
|
|
@@ -445,9 +445,9 @@ class Bounds {
|
|
|
445
445
|
/**
|
|
446
446
|
* Returns a polygon whose edges are the same as this bounds.
|
|
447
447
|
* @name toPolygon
|
|
448
|
-
* @memberof
|
|
448
|
+
* @memberof Bounds
|
|
449
449
|
* @function
|
|
450
|
-
* @returns {
|
|
450
|
+
* @returns {Polygon} a new Polygon that represents this bounds.
|
|
451
451
|
*/
|
|
452
452
|
toPolygon () {
|
|
453
453
|
return new Polygon(this.x, this.y, [
|
package/src/physics/collision.js
CHANGED
|
@@ -4,7 +4,6 @@ import { rayCast, globalResponse } from "./detector.js";
|
|
|
4
4
|
* Collision detection (and projection-based collision response) of 2D shapes.<br>
|
|
5
5
|
* Based on the Separating Axis Theorem and supports detecting collisions between simple Axis-Aligned Boxes, convex polygons and circles based shapes.
|
|
6
6
|
* @namespace collision
|
|
7
|
-
* @memberof me
|
|
8
7
|
*/
|
|
9
8
|
|
|
10
9
|
var collision = {
|
|
@@ -12,22 +11,22 @@ var collision = {
|
|
|
12
11
|
/**
|
|
13
12
|
* The maximum number of children that a quadtree node can contain before it is split into sub-nodes.
|
|
14
13
|
* @name maxChildren
|
|
15
|
-
* @memberof
|
|
14
|
+
* @memberof collision
|
|
16
15
|
* @public
|
|
17
16
|
* @type {number}
|
|
18
17
|
* @default 8
|
|
19
|
-
* @see
|
|
18
|
+
* @see game.world.broadphase
|
|
20
19
|
*/
|
|
21
20
|
maxChildren : 8,
|
|
22
21
|
|
|
23
22
|
/**
|
|
24
23
|
* The maximum number of levels that the quadtree will create.
|
|
25
24
|
* @name maxDepth
|
|
26
|
-
* @memberof
|
|
25
|
+
* @memberof collision
|
|
27
26
|
* @public
|
|
28
27
|
* @type {number}
|
|
29
28
|
* @default 4
|
|
30
|
-
* @see
|
|
29
|
+
* @see game.world.broadphase
|
|
31
30
|
*/
|
|
32
31
|
maxDepth : 4,
|
|
33
32
|
|
|
@@ -46,9 +45,9 @@ var collision = {
|
|
|
46
45
|
* @readonly
|
|
47
46
|
* @enum {number}
|
|
48
47
|
* @name types
|
|
49
|
-
* @memberof
|
|
50
|
-
* @see
|
|
51
|
-
* @see
|
|
48
|
+
* @memberof collision
|
|
49
|
+
* @see Body.setCollisionMask
|
|
50
|
+
* @see Body.collisionType
|
|
52
51
|
* @example
|
|
53
52
|
* // set the body collision type
|
|
54
53
|
* myEntity.body.collisionType = me.collision.types.PLAYER_OBJECT;
|
|
@@ -97,21 +96,21 @@ var collision = {
|
|
|
97
96
|
* a global instance of a response object used for collision detection <br>
|
|
98
97
|
* this object will be reused amongst collision detection call if not user-defined response is specified
|
|
99
98
|
* @name response
|
|
100
|
-
* @memberof
|
|
99
|
+
* @memberof collision
|
|
101
100
|
* @public
|
|
102
|
-
* @type {
|
|
101
|
+
* @type {collision.ResponseObject}
|
|
103
102
|
*/
|
|
104
103
|
response : globalResponse,
|
|
105
104
|
|
|
106
105
|
/**
|
|
107
106
|
* Checks for object colliding with the given line
|
|
108
107
|
* @name rayCast
|
|
109
|
-
* @memberof
|
|
108
|
+
* @memberof collision
|
|
110
109
|
* @public
|
|
111
110
|
* @function
|
|
112
|
-
* @param {
|
|
113
|
-
* @param {Array.<
|
|
114
|
-
* @returns {Array.<
|
|
111
|
+
* @param {Line} line line to be tested for collision
|
|
112
|
+
* @param {Array.<Renderable>} [result] a user defined array that will be populated with intersecting physic objects.
|
|
113
|
+
* @returns {Array.<Renderable>} an array of intersecting physic objects
|
|
115
114
|
* @example
|
|
116
115
|
* // define a line accross the viewport
|
|
117
116
|
* var ray = new me.Line(
|
package/src/physics/detector.js
CHANGED
|
@@ -17,17 +17,18 @@ var dummyObj = {
|
|
|
17
17
|
* a function used to determine if two objects should collide (based on both respective objects collision mask and type).<br>
|
|
18
18
|
* you can redefine this function if you need any specific rules over what should collide with what.
|
|
19
19
|
* @name shouldCollide
|
|
20
|
-
* @memberof
|
|
20
|
+
* @memberof collision
|
|
21
21
|
* @ignore
|
|
22
22
|
* @function
|
|
23
|
-
* @param {
|
|
24
|
-
* @param {
|
|
23
|
+
* @param {Renderable} a a reference to the object A.
|
|
24
|
+
* @param {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 (
|
|
29
29
|
a.isKinematic !== true && b.isKinematic !== true &&
|
|
30
|
-
a.body && b.body &&
|
|
30
|
+
typeof a.body === "object" && typeof b.body === "object" &&
|
|
31
|
+
!(a.body.isStatic === true && b.body.isStatic === true) &&
|
|
31
32
|
(a.body.collisionMask & b.body.collisionType) !== 0 &&
|
|
32
33
|
(a.body.collisionType & b.body.collisionMask) !== 0
|
|
33
34
|
);
|
|
@@ -36,17 +37,17 @@ function shouldCollide(a, b) {
|
|
|
36
37
|
/**
|
|
37
38
|
* @classdesc
|
|
38
39
|
* An object representing the result of an intersection.
|
|
39
|
-
* @property {
|
|
40
|
-
* @property {
|
|
40
|
+
* @property {Renderable} a The first object participating in the intersection
|
|
41
|
+
* @property {Renderable} b The second object participating in the intersection
|
|
41
42
|
* @property {number} overlap Magnitude of the overlap on the shortest colliding axis
|
|
42
|
-
* @property {
|
|
43
|
-
* @property {
|
|
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)
|
|
44
45
|
* @property {boolean} aInB Whether the first object is entirely inside the second
|
|
45
46
|
* @property {boolean} bInA Whether the second object is entirely inside the first
|
|
46
47
|
* @property {number} indexShapeA The index of the colliding shape for the object a body
|
|
47
48
|
* @property {number} indexShapeB The index of the colliding shape for the object b body
|
|
48
49
|
* @name ResponseObject
|
|
49
|
-
* @memberof
|
|
50
|
+
* @memberof collision
|
|
50
51
|
* @public
|
|
51
52
|
*/
|
|
52
53
|
class ResponseObject {
|
|
@@ -68,7 +69,7 @@ class ResponseObject {
|
|
|
68
69
|
* Response object for multiple intersection tests <br>
|
|
69
70
|
* (recommended as it will avoid allocating extra memory) <br>
|
|
70
71
|
* @name clear
|
|
71
|
-
* @memberof
|
|
72
|
+
* @memberof collision.ResponseObject
|
|
72
73
|
* @public
|
|
73
74
|
* @function
|
|
74
75
|
* @returns {object} this object for chaining
|
|
@@ -91,8 +92,8 @@ export var globalResponse = new ResponseObject();
|
|
|
91
92
|
* @name collisionCheck
|
|
92
93
|
* @ignore
|
|
93
94
|
* @function
|
|
94
|
-
* @param {
|
|
95
|
-
* @param {
|
|
95
|
+
* @param {Renderable} objA object to be tested for collision
|
|
96
|
+
* @param {collision.ResponseObject} [response=collision.response] a user defined response object that will be populated if they intersect.
|
|
96
97
|
* @returns {boolean} in case of collision, false otherwise
|
|
97
98
|
*/
|
|
98
99
|
export function collisionCheck(objA, response = globalResponse) {
|
|
@@ -141,10 +142,10 @@ export function collisionCheck(objA, response = globalResponse) {
|
|
|
141
142
|
response.indexShapeB = indexB;
|
|
142
143
|
|
|
143
144
|
// execute the onCollision callback
|
|
144
|
-
if (objA.onCollision && objA.onCollision(response, objB) !== false) {
|
|
145
|
+
if (objA.onCollision && objA.onCollision(response, objB) !== false && objA.body.isStatic === false) {
|
|
145
146
|
objA.body.respondToCollision.call(objA.body, response);
|
|
146
147
|
}
|
|
147
|
-
if (objB.onCollision && objB.onCollision(response, objA) !== false) {
|
|
148
|
+
if (objB.onCollision && objB.onCollision(response, objA) !== false && objB.body.isStatic === false) {
|
|
148
149
|
objB.body.respondToCollision.call(objB.body, response);
|
|
149
150
|
}
|
|
150
151
|
}
|
|
@@ -163,9 +164,9 @@ export function collisionCheck(objA, response = globalResponse) {
|
|
|
163
164
|
* @name rayCast
|
|
164
165
|
* @ignore
|
|
165
166
|
* @function
|
|
166
|
-
* @param {
|
|
167
|
-
* @param {Array.<
|
|
168
|
-
* @returns {Array.<
|
|
167
|
+
* @param {Line} line line to be tested for collision
|
|
168
|
+
* @param {Array.<Renderable>} [result] a user defined array that will be populated with intersecting physic objects.
|
|
169
|
+
* @returns {Array.<Renderable>} an array of intersecting physic objects
|
|
169
170
|
* @example
|
|
170
171
|
* // define a line accross the viewport
|
|
171
172
|
* var ray = new me.Line(
|
package/src/physics/quadtree.js
CHANGED
|
@@ -51,17 +51,15 @@ var QT_VECTOR = new Vector2d();
|
|
|
51
51
|
/**
|
|
52
52
|
* @classdesc
|
|
53
53
|
* a QuadTree implementation in JavaScript, a 2d spatial subdivision algorithm.
|
|
54
|
-
* @
|
|
55
|
-
* @name QuadTree
|
|
56
|
-
* @memberof me
|
|
57
|
-
* @see me.game.world.broadphase
|
|
58
|
-
* @param {me.Bounds} bounds bounds of the node
|
|
59
|
-
* @param {number} [max_objects=4] max objects a node can hold before splitting into 4 subnodes
|
|
60
|
-
* @param {number} [max_levels=4] total max levels inside root Quadtree
|
|
61
|
-
* @param {number} [level] deepth level, required for subnodes
|
|
54
|
+
* @see game.world.broadphase
|
|
62
55
|
*/
|
|
63
56
|
class QuadTree {
|
|
64
|
-
|
|
57
|
+
/**
|
|
58
|
+
* @param {Bounds} bounds bounds of the node
|
|
59
|
+
* @param {number} [max_objects=4] max objects a node can hold before splitting into 4 subnodes
|
|
60
|
+
* @param {number} [max_levels=4] total max levels inside root Quadtree
|
|
61
|
+
* @param {number} [level] deepth level, required for subnodes
|
|
62
|
+
*/
|
|
65
63
|
constructor(bounds, max_objects = 4, max_levels = 4, level = 0) {
|
|
66
64
|
this.max_objects = max_objects;
|
|
67
65
|
this.max_levels = max_levels;
|
|
@@ -118,7 +116,7 @@ class QuadTree {
|
|
|
118
116
|
|
|
119
117
|
/*
|
|
120
118
|
* Determine which node the object belongs to
|
|
121
|
-
* @param {
|
|
119
|
+
* @param {Rect} rect bounds of the area to be checked
|
|
122
120
|
* @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
|
|
123
121
|
*/
|
|
124
122
|
getIndex(item) {
|
|
@@ -166,9 +164,9 @@ class QuadTree {
|
|
|
166
164
|
/**
|
|
167
165
|
* Insert the given object container into the node.
|
|
168
166
|
* @name insertContainer
|
|
169
|
-
* @memberof
|
|
167
|
+
* @memberof QuadTree
|
|
170
168
|
* @function
|
|
171
|
-
* @param {
|
|
169
|
+
* @param {Container} container group of objects to be added
|
|
172
170
|
*/
|
|
173
171
|
insertContainer(container) {
|
|
174
172
|
for (var i = container.children.length, child; i--, (child = container.children[i]);) {
|
|
@@ -195,7 +193,7 @@ class QuadTree {
|
|
|
195
193
|
* exceeds the capacity, it will split and add all
|
|
196
194
|
* objects to their corresponding subnodes.
|
|
197
195
|
* @name insert
|
|
198
|
-
* @memberof
|
|
196
|
+
* @memberof QuadTree
|
|
199
197
|
* @function
|
|
200
198
|
* @param {object} item object to be added
|
|
201
199
|
*/
|
|
@@ -240,7 +238,7 @@ class QuadTree {
|
|
|
240
238
|
/**
|
|
241
239
|
* Return all objects that could collide with the given object
|
|
242
240
|
* @name retrieve
|
|
243
|
-
* @memberof
|
|
241
|
+
* @memberof QuadTree
|
|
244
242
|
* @function
|
|
245
243
|
* @param {object} item object to be checked against
|
|
246
244
|
* @param {object} [fn] a sorting function for the returned array
|
|
@@ -276,7 +274,7 @@ class QuadTree {
|
|
|
276
274
|
* Remove the given item from the quadtree.
|
|
277
275
|
* (this function won't recalculate the impacted node)
|
|
278
276
|
* @name remove
|
|
279
|
-
* @memberof
|
|
277
|
+
* @memberof QuadTree
|
|
280
278
|
* @function
|
|
281
279
|
* @param {object} item object to be removed
|
|
282
280
|
* @returns {boolean} true if the item was found and removed.
|
|
@@ -317,7 +315,7 @@ class QuadTree {
|
|
|
317
315
|
/**
|
|
318
316
|
* return true if the node is prunable
|
|
319
317
|
* @name isPrunable
|
|
320
|
-
* @memberof
|
|
318
|
+
* @memberof QuadTree
|
|
321
319
|
* @function
|
|
322
320
|
* @returns {boolean} true if the node is prunable
|
|
323
321
|
*/
|
|
@@ -328,7 +326,7 @@ class QuadTree {
|
|
|
328
326
|
/**
|
|
329
327
|
* return true if the node has any children
|
|
330
328
|
* @name hasChildren
|
|
331
|
-
* @memberof
|
|
329
|
+
* @memberof QuadTree
|
|
332
330
|
* @function
|
|
333
331
|
* @returns {boolean} true if the node has any children
|
|
334
332
|
*/
|
|
@@ -345,9 +343,9 @@ class QuadTree {
|
|
|
345
343
|
/**
|
|
346
344
|
* clear the quadtree
|
|
347
345
|
* @name clear
|
|
348
|
-
* @memberof
|
|
346
|
+
* @memberof QuadTree
|
|
349
347
|
* @function
|
|
350
|
-
* @param {
|
|
348
|
+
* @param {Bounds} [bounds=this.bounds] the bounds to be cleared
|
|
351
349
|
*/
|
|
352
350
|
clear(bounds) {
|
|
353
351
|
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.<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.<Vector2d>} points The points to flatten.
|
|
50
|
+
* @param {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,11 +70,11 @@ 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 {Vector2d} aPos The position of the first polygon.
|
|
74
|
+
* @param {Vector2d} bPos The position of the second polygon.
|
|
75
|
+
* @param {Array.<Vector2d>} aPoints The points in the first polygon.
|
|
76
|
+
* @param {Array.<Vector2d>} bPoints The points in the second polygon.
|
|
77
|
+
* @param {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.
|
|
@@ -161,8 +161,8 @@ function isSeparatingAxis(aPos, bPos, aPoints, bPoints, axis, response) {
|
|
|
161
161
|
* </pre>
|
|
162
162
|
*
|
|
163
163
|
* @ignore
|
|
164
|
-
* @param {
|
|
165
|
-
* @param {
|
|
164
|
+
* @param {Vector2d} line The line segment.
|
|
165
|
+
* @param {Vector2d} point The point.
|
|
166
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.
|
|
@@ -187,10 +187,10 @@ function vornoiRegion(line, point) {
|
|
|
187
187
|
/**
|
|
188
188
|
* Checks whether polygons collide.
|
|
189
189
|
* @ignore
|
|
190
|
-
* @param {
|
|
191
|
-
* @param {
|
|
192
|
-
* @param {
|
|
193
|
-
* @param {
|
|
190
|
+
* @param {Renderable} a a reference to the object A.
|
|
191
|
+
* @param {Polygon} polyA a reference to the object A Polygon to be tested
|
|
192
|
+
* @param {Renderable} b a reference to the object B.
|
|
193
|
+
* @param {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
|
*/
|
|
@@ -241,10 +241,10 @@ export function testPolygonPolygon(a, polyA, b, polyB, response) {
|
|
|
241
241
|
/**
|
|
242
242
|
* Check if two Ellipse collide.
|
|
243
243
|
* @ignore
|
|
244
|
-
* @param {
|
|
245
|
-
* @param {
|
|
246
|
-
* @param {
|
|
247
|
-
* @param {
|
|
244
|
+
* @param {Renderable} a a reference to the object A.
|
|
245
|
+
* @param {Ellipse} ellipseA a reference to the object A Ellipse to be tested
|
|
246
|
+
* @param {Renderable} b a reference to the object B.
|
|
247
|
+
* @param {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.
|
|
@@ -282,10 +282,10 @@ export function testEllipseEllipse(a, ellipseA, b, ellipseB, response) {
|
|
|
282
282
|
/**
|
|
283
283
|
* Check if a polygon and an ellipse collide.
|
|
284
284
|
* @ignore
|
|
285
|
-
* @param {
|
|
286
|
-
* @param {
|
|
287
|
-
* @param {
|
|
288
|
-
* @param {
|
|
285
|
+
* @param {Renderable} a a reference to the object A.
|
|
286
|
+
* @param {Polygon} polyA a reference to the object A Polygon to be tested
|
|
287
|
+
* @param {Renderable} b a reference to the object B.
|
|
288
|
+
* @param {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
|
*/
|
|
@@ -448,10 +448,10 @@ export function testPolygonEllipse(a, polyA, b, ellipseB, response) {
|
|
|
448
448
|
* **NOTE:** This is slightly less efficient than testPolygonEllipse as it just
|
|
449
449
|
* runs testPolygonEllipse and reverses the response at the end.
|
|
450
450
|
* @ignore
|
|
451
|
-
* @param {
|
|
452
|
-
* @param {
|
|
453
|
-
* @param {
|
|
454
|
-
* @param {
|
|
451
|
+
* @param {Renderable} a a reference to the object A.
|
|
452
|
+
* @param {Ellipse} ellipseA a reference to the object A Ellipse to be tested
|
|
453
|
+
* @param {Renderable} b a reference to the object B.
|
|
454
|
+
* @param {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.
|