melonjs 10.2.3 → 10.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -6
- package/dist/melonjs.js +3620 -3582
- package/dist/melonjs.min.js +5 -5
- package/dist/melonjs.module.d.ts +3646 -4545
- package/dist/melonjs.module.js +3912 -3521
- package/package.json +21 -20
- package/src/audio/audio.js +30 -31
- package/src/camera/camera2d.js +47 -58
- package/src/entity/entity.js +32 -38
- package/src/game.js +21 -22
- package/src/{shapes → geometries}/ellipse.js +40 -47
- package/src/{shapes → geometries}/line.js +9 -12
- package/src/{shapes → geometries}/poly.js +100 -53
- package/src/{shapes → geometries}/rectangle.js +42 -45
- package/src/index.js +14 -32
- 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 +61 -29
- package/src/input/pointerevent.js +92 -29
- package/src/lang/deprecated.js +83 -13
- package/src/level/level.js +23 -24
- package/src/level/tiled/TMXGroup.js +7 -9
- package/src/level/tiled/TMXLayer.js +30 -33
- package/src/level/tiled/TMXObject.js +59 -53
- package/src/level/tiled/TMXTile.js +18 -19
- package/src/level/tiled/TMXTileMap.js +40 -46
- package/src/level/tiled/TMXTileset.js +12 -16
- package/src/level/tiled/TMXTilesetGroup.js +9 -10
- package/src/level/tiled/renderer/TMXHexagonalRenderer.js +7 -9
- package/src/level/tiled/renderer/TMXIsometricRenderer.js +7 -9
- package/src/level/tiled/renderer/TMXOrthogonalRenderer.js +4 -6
- package/src/level/tiled/renderer/TMXRenderer.js +24 -26
- package/src/level/tiled/renderer/TMXStaggeredRenderer.js +1 -5
- package/src/loader/loader.js +17 -16
- package/src/loader/loadingscreen.js +2 -5
- package/src/math/color.js +47 -67
- package/src/math/math.js +15 -16
- package/src/math/matrix2.js +53 -59
- package/src/math/matrix3.js +56 -63
- package/src/math/observable_vector2.js +87 -77
- package/src/math/observable_vector3.js +97 -80
- package/src/math/vector2.js +107 -97
- package/src/math/vector3.js +116 -100
- package/src/particles/emitter.js +66 -76
- package/src/particles/particle.js +4 -6
- package/src/particles/particlecontainer.js +2 -4
- package/src/physics/body.js +49 -147
- package/src/physics/bounds.js +48 -50
- package/src/physics/collision.js +13 -14
- package/src/physics/detector.js +18 -17
- package/src/physics/quadtree.js +17 -20
- package/src/physics/sat.js +30 -30
- package/src/physics/world.js +24 -29
- package/src/plugin/plugin.js +11 -15
- package/src/renderable/GUI.js +41 -47
- package/src/renderable/collectable.js +5 -10
- package/src/renderable/colorlayer.js +10 -15
- package/src/renderable/container.js +87 -73
- package/src/renderable/dragndrop.js +224 -0
- package/src/renderable/imagelayer.js +25 -32
- package/src/renderable/nineslicesprite.js +41 -42
- package/src/renderable/renderable.js +113 -124
- package/src/renderable/sprite.js +62 -69
- package/src/renderable/trigger.js +26 -32
- package/src/state/stage.js +13 -18
- package/src/state/state.js +26 -27
- package/src/system/device.js +76 -133
- package/src/system/event.js +81 -70
- 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 -55
- package/src/text/bitmaptextdata.js +10 -11
- package/src/text/glyph.js +3 -0
- package/src/text/text.js +49 -55
- package/src/tweens/easing.js +1 -1
- package/src/tweens/interpolation.js +1 -1
- package/src/tweens/tween.js +44 -46
- 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 +60 -62
- package/src/video/renderer.js +53 -58
- package/src/video/texture.js +98 -112
- package/src/video/texture_cache.js +26 -10
- package/src/video/video.js +15 -16
- package/src/video/webgl/buffer/vertex.js +2 -2
- package/src/video/webgl/glshader.js +37 -39
- package/src/video/webgl/webgl_compositor.js +128 -101
- package/src/video/webgl/webgl_renderer.js +126 -106
- package/src/entity/draggable.js +0 -139
- package/src/entity/droptarget.js +0 -109
package/src/physics/bounds.js
CHANGED
|
@@ -1,23 +1,21 @@
|
|
|
1
1
|
import Vector2d from "./../math/vector2.js";
|
|
2
|
-
import Polygon from "./../
|
|
2
|
+
import Polygon from "./../geometries/poly.js";
|
|
3
3
|
|
|
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
|
-
* @constructor
|
|
10
|
-
* @memberOf me
|
|
11
|
-
* @param {me.Vector2d[]} [vertices] an array of me.Vector2d points
|
|
12
|
-
* @returns {me.Bounds} A new bounds object
|
|
13
7
|
*/
|
|
14
|
-
|
|
15
8
|
class Bounds {
|
|
16
|
-
|
|
9
|
+
/**
|
|
10
|
+
* @param {Vector2d[]} [vertices] an array of me.Vector2d points
|
|
11
|
+
*/
|
|
17
12
|
constructor(vertices) {
|
|
18
13
|
this.onResetEvent(vertices);
|
|
19
14
|
}
|
|
20
15
|
|
|
16
|
+
/**
|
|
17
|
+
* @ignore
|
|
18
|
+
*/
|
|
21
19
|
onResetEvent(vertices) {
|
|
22
20
|
if (typeof this.min === "undefined") {
|
|
23
21
|
this.min = { x: Infinity, y: Infinity };
|
|
@@ -36,7 +34,7 @@ class Bounds {
|
|
|
36
34
|
/**
|
|
37
35
|
* reset the bound
|
|
38
36
|
* @name clear
|
|
39
|
-
* @
|
|
37
|
+
* @memberof Bounds
|
|
40
38
|
* @function
|
|
41
39
|
*/
|
|
42
40
|
clear() {
|
|
@@ -47,7 +45,7 @@ class Bounds {
|
|
|
47
45
|
/**
|
|
48
46
|
* sets the bounds to the given min and max value
|
|
49
47
|
* @name setMinMax
|
|
50
|
-
* @
|
|
48
|
+
* @memberof Bounds
|
|
51
49
|
* @function
|
|
52
50
|
* @param {number} minX
|
|
53
51
|
* @param {number} minY
|
|
@@ -67,7 +65,7 @@ class Bounds {
|
|
|
67
65
|
* @public
|
|
68
66
|
* @type {number}
|
|
69
67
|
* @name x
|
|
70
|
-
* @
|
|
68
|
+
* @memberof Bounds
|
|
71
69
|
*/
|
|
72
70
|
get x() {
|
|
73
71
|
return this.min.x;
|
|
@@ -84,7 +82,7 @@ class Bounds {
|
|
|
84
82
|
* @public
|
|
85
83
|
* @type {number}
|
|
86
84
|
* @name y
|
|
87
|
-
* @
|
|
85
|
+
* @memberof Bounds
|
|
88
86
|
*/
|
|
89
87
|
get y() {
|
|
90
88
|
return this.min.y;
|
|
@@ -102,7 +100,7 @@ class Bounds {
|
|
|
102
100
|
* @public
|
|
103
101
|
* @type {number}
|
|
104
102
|
* @name width
|
|
105
|
-
* @
|
|
103
|
+
* @memberof Bounds
|
|
106
104
|
*/
|
|
107
105
|
get width() {
|
|
108
106
|
return this.max.x - this.min.x;
|
|
@@ -117,7 +115,7 @@ class Bounds {
|
|
|
117
115
|
* @public
|
|
118
116
|
* @type {number}
|
|
119
117
|
* @name width
|
|
120
|
-
* @
|
|
118
|
+
* @memberof Bounds
|
|
121
119
|
*/
|
|
122
120
|
get height() {
|
|
123
121
|
return this.max.y - this.min.y;
|
|
@@ -132,7 +130,7 @@ class Bounds {
|
|
|
132
130
|
* @public
|
|
133
131
|
* @type {number}
|
|
134
132
|
* @name left
|
|
135
|
-
* @
|
|
133
|
+
* @memberof Bounds
|
|
136
134
|
*/
|
|
137
135
|
get left() {
|
|
138
136
|
return this.min.x;
|
|
@@ -143,7 +141,7 @@ class Bounds {
|
|
|
143
141
|
* @public
|
|
144
142
|
* @type {number}
|
|
145
143
|
* @name right
|
|
146
|
-
* @
|
|
144
|
+
* @memberof Bounds
|
|
147
145
|
*/
|
|
148
146
|
get right() {
|
|
149
147
|
return this.max.x;
|
|
@@ -154,7 +152,7 @@ class Bounds {
|
|
|
154
152
|
* @public
|
|
155
153
|
* @type {number}
|
|
156
154
|
* @name top
|
|
157
|
-
* @
|
|
155
|
+
* @memberof Bounds
|
|
158
156
|
*/
|
|
159
157
|
get top() {
|
|
160
158
|
return this.min.y;
|
|
@@ -165,7 +163,7 @@ class Bounds {
|
|
|
165
163
|
* @public
|
|
166
164
|
* @type {number}
|
|
167
165
|
* @name bottom
|
|
168
|
-
* @
|
|
166
|
+
* @memberof Bounds
|
|
169
167
|
*/
|
|
170
168
|
get bottom() {
|
|
171
169
|
return this.max.y;
|
|
@@ -176,7 +174,7 @@ class Bounds {
|
|
|
176
174
|
* @public
|
|
177
175
|
* @type {number}
|
|
178
176
|
* @name centerX
|
|
179
|
-
* @
|
|
177
|
+
* @memberof Bounds
|
|
180
178
|
*/
|
|
181
179
|
get centerX() {
|
|
182
180
|
return this.min.x + (this.width / 2);
|
|
@@ -187,7 +185,7 @@ class Bounds {
|
|
|
187
185
|
* @public
|
|
188
186
|
* @type {number}
|
|
189
187
|
* @name centerY
|
|
190
|
-
* @
|
|
188
|
+
* @memberof Bounds
|
|
191
189
|
*/
|
|
192
190
|
get centerY() {
|
|
193
191
|
return this.min.y + (this.height / 2);
|
|
@@ -196,9 +194,9 @@ class Bounds {
|
|
|
196
194
|
/**
|
|
197
195
|
* return the center position of the bound
|
|
198
196
|
* @public
|
|
199
|
-
* @type {
|
|
197
|
+
* @type {Vector2d}
|
|
200
198
|
* @name center
|
|
201
|
-
* @
|
|
199
|
+
* @memberof Bounds
|
|
202
200
|
*/
|
|
203
201
|
get center() {
|
|
204
202
|
return this._center.set(this.centerX, this.centerY);
|
|
@@ -207,9 +205,9 @@ class Bounds {
|
|
|
207
205
|
/**
|
|
208
206
|
* Updates bounds using the given vertices
|
|
209
207
|
* @name update
|
|
210
|
-
* @
|
|
208
|
+
* @memberof Bounds
|
|
211
209
|
* @function
|
|
212
|
-
* @param {
|
|
210
|
+
* @param {Vector2d[]} vertices an array of me.Vector2d points
|
|
213
211
|
*/
|
|
214
212
|
update(vertices) {
|
|
215
213
|
this.add(vertices, true);
|
|
@@ -218,9 +216,9 @@ class Bounds {
|
|
|
218
216
|
/**
|
|
219
217
|
* add the given vertices to the bounds definition.
|
|
220
218
|
* @name add
|
|
221
|
-
* @
|
|
219
|
+
* @memberof Bounds
|
|
222
220
|
* @function
|
|
223
|
-
* @param {
|
|
221
|
+
* @param {Vector2d[]} vertices an array of me.Vector2d points
|
|
224
222
|
* @param {boolean} [clear=false] either to reset the bounds before adding the new vertices
|
|
225
223
|
*/
|
|
226
224
|
add(vertices, clear = false) {
|
|
@@ -239,9 +237,9 @@ class Bounds {
|
|
|
239
237
|
/**
|
|
240
238
|
* add the given bounds to the bounds definition.
|
|
241
239
|
* @name addBounds
|
|
242
|
-
* @
|
|
240
|
+
* @memberof Bounds
|
|
243
241
|
* @function
|
|
244
|
-
* @param {
|
|
242
|
+
* @param {Bounds} bounds
|
|
245
243
|
* @param {boolean} [clear=false] either to reset the bounds before adding the new vertices
|
|
246
244
|
*/
|
|
247
245
|
addBounds(bounds, clear = false) {
|
|
@@ -258,10 +256,10 @@ class Bounds {
|
|
|
258
256
|
/**
|
|
259
257
|
* add the given point to the bounds definition.
|
|
260
258
|
* @name addPoint
|
|
261
|
-
* @
|
|
259
|
+
* @memberof Bounds
|
|
262
260
|
* @function
|
|
263
|
-
* @param {
|
|
264
|
-
* @param {
|
|
261
|
+
* @param {Vector2d} v
|
|
262
|
+
* @param {Matrix2d} [m] an optional transform to apply to the given point
|
|
265
263
|
*/
|
|
266
264
|
addPoint(v, m) {
|
|
267
265
|
if (typeof m !== "undefined") {
|
|
@@ -276,13 +274,13 @@ class Bounds {
|
|
|
276
274
|
/**
|
|
277
275
|
* add the given quad coordinates to this bound definition, multiplied by the given matrix
|
|
278
276
|
* @name addFrame
|
|
279
|
-
* @
|
|
277
|
+
* @memberof Bounds
|
|
280
278
|
* @function
|
|
281
279
|
* @param {number} x0 - left X coordinates of the quad
|
|
282
280
|
* @param {number} y0 - top Y coordinates of the quad
|
|
283
281
|
* @param {number} x1 - right X coordinates of the quad
|
|
284
282
|
* @param {number} y1 - bottom y coordinates of the quad
|
|
285
|
-
* @param {
|
|
283
|
+
* @param {Matrix2d} [m] an optional transform to apply to the given frame coordinates
|
|
286
284
|
*/
|
|
287
285
|
addFrame(x0, y0, x1, y1, m) {
|
|
288
286
|
var v = me.pool.pull("Vector2d");
|
|
@@ -299,15 +297,15 @@ class Bounds {
|
|
|
299
297
|
/**
|
|
300
298
|
* Returns true if the bounds contains the given point.
|
|
301
299
|
* @name contains
|
|
302
|
-
* @
|
|
300
|
+
* @memberof Bounds
|
|
303
301
|
* @function
|
|
304
|
-
* @param {
|
|
302
|
+
* @param {Vector2d} point
|
|
305
303
|
* @returns {boolean} True if the bounds contain the point, otherwise false
|
|
306
304
|
*/
|
|
307
305
|
/**
|
|
308
306
|
* Returns true if the bounds contains the given point.
|
|
309
307
|
* @name contains
|
|
310
|
-
* @
|
|
308
|
+
* @memberof Bounds
|
|
311
309
|
* @function
|
|
312
310
|
* @param {number} x
|
|
313
311
|
* @param {number} y
|
|
@@ -341,9 +339,9 @@ class Bounds {
|
|
|
341
339
|
/**
|
|
342
340
|
* Returns true if the two bounds intersect.
|
|
343
341
|
* @name overlaps
|
|
344
|
-
* @
|
|
342
|
+
* @memberof Bounds
|
|
345
343
|
* @function
|
|
346
|
-
* @param {
|
|
344
|
+
* @param {Bounds|Rect} bounds
|
|
347
345
|
* @returns {boolean} True if the bounds overlap, otherwise false
|
|
348
346
|
*/
|
|
349
347
|
overlaps(bounds) {
|
|
@@ -354,7 +352,7 @@ class Bounds {
|
|
|
354
352
|
/**
|
|
355
353
|
* determines whether all coordinates of this bounds are finite numbers.
|
|
356
354
|
* @name isFinite
|
|
357
|
-
* @
|
|
355
|
+
* @memberof Bounds
|
|
358
356
|
* @function
|
|
359
357
|
* @returns {boolean} false if all coordinates are positive or negative Infinity or NaN; otherwise, true.
|
|
360
358
|
*/
|
|
@@ -365,14 +363,14 @@ class Bounds {
|
|
|
365
363
|
/**
|
|
366
364
|
* Translates the bounds by the given vector.
|
|
367
365
|
* @name translate
|
|
368
|
-
* @
|
|
366
|
+
* @memberof Bounds
|
|
369
367
|
* @function
|
|
370
|
-
* @param {
|
|
368
|
+
* @param {Vector2d} vector
|
|
371
369
|
*/
|
|
372
370
|
/**
|
|
373
371
|
* Translates the bounds by x on the x axis, and y on the y axis
|
|
374
372
|
* @name translate
|
|
375
|
-
* @
|
|
373
|
+
* @memberof Bounds
|
|
376
374
|
* @function
|
|
377
375
|
* @param {number} x
|
|
378
376
|
* @param {number} y
|
|
@@ -397,14 +395,14 @@ class Bounds {
|
|
|
397
395
|
/**
|
|
398
396
|
* Shifts the bounds to the given position vector.
|
|
399
397
|
* @name shift
|
|
400
|
-
* @
|
|
398
|
+
* @memberof Bounds
|
|
401
399
|
* @function
|
|
402
|
-
* @param {
|
|
400
|
+
* @param {Vector2d} position
|
|
403
401
|
*/
|
|
404
402
|
/**
|
|
405
403
|
* Shifts the bounds to the given x, y position.
|
|
406
404
|
* @name shift
|
|
407
|
-
* @
|
|
405
|
+
* @memberof Bounds
|
|
408
406
|
* @function
|
|
409
407
|
* @param {number} x
|
|
410
408
|
* @param {number} y
|
|
@@ -434,9 +432,9 @@ class Bounds {
|
|
|
434
432
|
/**
|
|
435
433
|
* clone this bounds
|
|
436
434
|
* @name clone
|
|
437
|
-
* @
|
|
435
|
+
* @memberof Bounds
|
|
438
436
|
* @function
|
|
439
|
-
* @returns {
|
|
437
|
+
* @returns {Bounds}
|
|
440
438
|
*/
|
|
441
439
|
clone() {
|
|
442
440
|
var bounds = new Bounds();
|
|
@@ -447,9 +445,9 @@ class Bounds {
|
|
|
447
445
|
/**
|
|
448
446
|
* Returns a polygon whose edges are the same as this bounds.
|
|
449
447
|
* @name toPolygon
|
|
450
|
-
* @
|
|
448
|
+
* @memberof Bounds
|
|
451
449
|
* @function
|
|
452
|
-
* @returns {
|
|
450
|
+
* @returns {Polygon} a new Polygon that represents this bounds.
|
|
453
451
|
*/
|
|
454
452
|
toPolygon () {
|
|
455
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
|
-
* @
|
|
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
|
-
* @
|
|
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
|
-
* @
|
|
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
|
-
* @
|
|
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
|
-
* @
|
|
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
|
-
* @
|
|
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
|
-
* @
|
|
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
|
-
* @
|
|
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,18 +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
|
-
* @constructor
|
|
58
|
-
* @see me.game.world.broadphase
|
|
59
|
-
* @param {me.Bounds} bounds bounds of the node
|
|
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
|
|
54
|
+
* @see game.world.broadphase
|
|
63
55
|
*/
|
|
64
56
|
class QuadTree {
|
|
65
|
-
|
|
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
|
+
*/
|
|
66
63
|
constructor(bounds, max_objects = 4, max_levels = 4, level = 0) {
|
|
67
64
|
this.max_objects = max_objects;
|
|
68
65
|
this.max_levels = max_levels;
|
|
@@ -119,7 +116,7 @@ class QuadTree {
|
|
|
119
116
|
|
|
120
117
|
/*
|
|
121
118
|
* Determine which node the object belongs to
|
|
122
|
-
* @param {
|
|
119
|
+
* @param {Rect} rect bounds of the area to be checked
|
|
123
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
|
|
124
121
|
*/
|
|
125
122
|
getIndex(item) {
|
|
@@ -167,9 +164,9 @@ class QuadTree {
|
|
|
167
164
|
/**
|
|
168
165
|
* Insert the given object container into the node.
|
|
169
166
|
* @name insertContainer
|
|
170
|
-
* @
|
|
167
|
+
* @memberof QuadTree
|
|
171
168
|
* @function
|
|
172
|
-
* @param {
|
|
169
|
+
* @param {Container} container group of objects to be added
|
|
173
170
|
*/
|
|
174
171
|
insertContainer(container) {
|
|
175
172
|
for (var i = container.children.length, child; i--, (child = container.children[i]);) {
|
|
@@ -196,7 +193,7 @@ class QuadTree {
|
|
|
196
193
|
* exceeds the capacity, it will split and add all
|
|
197
194
|
* objects to their corresponding subnodes.
|
|
198
195
|
* @name insert
|
|
199
|
-
* @
|
|
196
|
+
* @memberof QuadTree
|
|
200
197
|
* @function
|
|
201
198
|
* @param {object} item object to be added
|
|
202
199
|
*/
|
|
@@ -241,7 +238,7 @@ class QuadTree {
|
|
|
241
238
|
/**
|
|
242
239
|
* Return all objects that could collide with the given object
|
|
243
240
|
* @name retrieve
|
|
244
|
-
* @
|
|
241
|
+
* @memberof QuadTree
|
|
245
242
|
* @function
|
|
246
243
|
* @param {object} item object to be checked against
|
|
247
244
|
* @param {object} [fn] a sorting function for the returned array
|
|
@@ -277,7 +274,7 @@ class QuadTree {
|
|
|
277
274
|
* Remove the given item from the quadtree.
|
|
278
275
|
* (this function won't recalculate the impacted node)
|
|
279
276
|
* @name remove
|
|
280
|
-
* @
|
|
277
|
+
* @memberof QuadTree
|
|
281
278
|
* @function
|
|
282
279
|
* @param {object} item object to be removed
|
|
283
280
|
* @returns {boolean} true if the item was found and removed.
|
|
@@ -318,7 +315,7 @@ class QuadTree {
|
|
|
318
315
|
/**
|
|
319
316
|
* return true if the node is prunable
|
|
320
317
|
* @name isPrunable
|
|
321
|
-
* @
|
|
318
|
+
* @memberof QuadTree
|
|
322
319
|
* @function
|
|
323
320
|
* @returns {boolean} true if the node is prunable
|
|
324
321
|
*/
|
|
@@ -329,7 +326,7 @@ class QuadTree {
|
|
|
329
326
|
/**
|
|
330
327
|
* return true if the node has any children
|
|
331
328
|
* @name hasChildren
|
|
332
|
-
* @
|
|
329
|
+
* @memberof QuadTree
|
|
333
330
|
* @function
|
|
334
331
|
* @returns {boolean} true if the node has any children
|
|
335
332
|
*/
|
|
@@ -346,9 +343,9 @@ class QuadTree {
|
|
|
346
343
|
/**
|
|
347
344
|
* clear the quadtree
|
|
348
345
|
* @name clear
|
|
349
|
-
* @
|
|
346
|
+
* @memberof QuadTree
|
|
350
347
|
* @function
|
|
351
|
-
* @param {
|
|
348
|
+
* @param {Bounds} [bounds=this.bounds] the bounds to be cleared
|
|
352
349
|
*/
|
|
353
350
|
clear(bounds) {
|
|
354
351
|
this.objects.length = 0;
|