melonjs 10.2.0 → 10.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/melonjs.js +4435 -4283
- package/dist/melonjs.min.js +4 -4
- package/dist/melonjs.module.d.ts +3348 -3833
- package/dist/melonjs.module.js +4025 -3920
- package/package.json +13 -14
- package/src/audio/audio.js +45 -45
- package/src/camera/camera2d.js +78 -101
- package/src/entity/draggable.js +21 -29
- package/src/entity/droptarget.js +24 -31
- package/src/entity/entity.js +34 -38
- package/src/game.js +8 -8
- package/src/{shapes → geometries}/ellipse.js +46 -46
- package/src/{shapes → geometries}/line.js +14 -14
- package/src/{shapes → geometries}/poly.js +103 -54
- package/src/{shapes → geometries}/rectangle.js +73 -120
- package/src/index.js +18 -19
- package/src/input/gamepad.js +20 -20
- package/src/input/input.js +3 -3
- package/src/input/keyboard.js +122 -124
- package/src/input/pointer.js +102 -62
- package/src/input/pointerevent.js +97 -42
- package/src/lang/deprecated.js +29 -18
- package/src/level/level.js +34 -26
- package/src/level/tiled/TMXGroup.js +12 -13
- package/src/level/tiled/TMXLayer.js +41 -42
- package/src/level/tiled/TMXObject.js +76 -70
- package/src/level/tiled/TMXTile.js +13 -15
- package/src/level/tiled/TMXTileMap.js +26 -25
- package/src/level/tiled/TMXTileset.js +14 -15
- package/src/level/tiled/TMXTilesetGroup.js +5 -6
- package/src/level/tiled/TMXUtils.js +13 -11
- package/src/level/tiled/renderer/TMXHexagonalRenderer.js +3 -4
- package/src/level/tiled/renderer/TMXIsometricRenderer.js +3 -4
- package/src/level/tiled/renderer/TMXOrthogonalRenderer.js +2 -3
- package/src/level/tiled/renderer/TMXRenderer.js +18 -19
- package/src/level/tiled/renderer/TMXStaggeredRenderer.js +2 -3
- package/src/loader/loader.js +46 -40
- package/src/loader/loadingscreen.js +7 -7
- package/src/math/color.js +68 -88
- package/src/math/math.js +33 -33
- package/src/math/matrix2.js +70 -71
- package/src/math/matrix3.js +90 -91
- package/src/math/observable_vector2.js +91 -92
- package/src/math/observable_vector3.js +110 -106
- package/src/math/vector2.js +116 -104
- package/src/math/vector3.js +129 -110
- package/src/particles/emitter.js +116 -126
- package/src/particles/particle.js +4 -5
- package/src/particles/particlecontainer.js +2 -3
- package/src/physics/body.js +82 -83
- package/src/physics/bounds.js +64 -66
- package/src/physics/collision.js +21 -22
- package/src/physics/detector.js +13 -13
- package/src/physics/quadtree.js +26 -25
- package/src/physics/sat.js +21 -21
- package/src/physics/world.js +23 -22
- package/src/plugin/plugin.js +12 -13
- package/src/renderable/GUI.js +20 -26
- package/src/renderable/collectable.js +6 -7
- package/src/renderable/colorlayer.js +11 -12
- package/src/renderable/container.js +98 -81
- package/src/renderable/imagelayer.js +33 -35
- package/src/renderable/nineslicesprite.js +15 -16
- package/src/renderable/renderable.js +112 -111
- package/src/renderable/sprite.js +71 -58
- package/src/renderable/trigger.js +17 -19
- package/src/state/stage.js +14 -15
- package/src/state/state.js +78 -78
- package/src/system/device.js +137 -180
- package/src/system/event.js +116 -104
- package/src/system/pooling.js +15 -15
- package/src/system/save.js +9 -6
- package/src/system/timer.js +33 -33
- package/src/text/bitmaptext.js +39 -46
- package/src/text/bitmaptextdata.js +14 -15
- package/src/text/text.js +55 -58
- package/src/tweens/easing.js +5 -5
- package/src/tweens/interpolation.js +5 -5
- package/src/tweens/tween.js +49 -40
- package/src/utils/agent.js +12 -11
- package/src/utils/array.js +8 -8
- package/src/utils/file.js +7 -7
- package/src/utils/function.js +8 -8
- package/src/utils/string.js +19 -19
- package/src/utils/utils.js +23 -23
- package/src/video/canvas/canvas_renderer.js +127 -128
- package/src/video/renderer.js +69 -69
- package/src/video/texture.js +80 -82
- package/src/video/texture_cache.js +2 -4
- package/src/video/video.js +38 -38
- package/src/video/webgl/buffer/vertex.js +11 -3
- package/src/video/webgl/glshader.js +31 -32
- package/src/video/webgl/webgl_compositor.js +145 -127
- package/src/video/webgl/webgl_renderer.js +196 -175
package/src/physics/bounds.js
CHANGED
|
@@ -1,15 +1,13 @@
|
|
|
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
7
|
* @class Bounds
|
|
8
|
-
* @
|
|
9
|
-
* @constructor
|
|
10
|
-
* @memberOf me
|
|
8
|
+
* @memberof me
|
|
11
9
|
* @param {me.Vector2d[]} [vertices] an array of me.Vector2d points
|
|
12
|
-
* @
|
|
10
|
+
* @returns {me.Bounds} A new bounds object
|
|
13
11
|
*/
|
|
14
12
|
|
|
15
13
|
class Bounds {
|
|
@@ -36,7 +34,7 @@ class Bounds {
|
|
|
36
34
|
/**
|
|
37
35
|
* reset the bound
|
|
38
36
|
* @name clear
|
|
39
|
-
* @
|
|
37
|
+
* @memberof me.Bounds
|
|
40
38
|
* @function
|
|
41
39
|
*/
|
|
42
40
|
clear() {
|
|
@@ -47,12 +45,12 @@ class Bounds {
|
|
|
47
45
|
/**
|
|
48
46
|
* sets the bounds to the given min and max value
|
|
49
47
|
* @name setMinMax
|
|
50
|
-
* @
|
|
48
|
+
* @memberof me.Bounds
|
|
51
49
|
* @function
|
|
52
|
-
* @param {
|
|
53
|
-
* @param {
|
|
54
|
-
* @param {
|
|
55
|
-
* @param {
|
|
50
|
+
* @param {number} minX
|
|
51
|
+
* @param {number} minY
|
|
52
|
+
* @param {number} maxX
|
|
53
|
+
* @param {number} maxY
|
|
56
54
|
*/
|
|
57
55
|
setMinMax(minX, minY, maxX, maxY) {
|
|
58
56
|
this.min.x = minX;
|
|
@@ -65,9 +63,9 @@ class Bounds {
|
|
|
65
63
|
/**
|
|
66
64
|
* x position of the bound
|
|
67
65
|
* @public
|
|
68
|
-
* @type {
|
|
66
|
+
* @type {number}
|
|
69
67
|
* @name x
|
|
70
|
-
* @
|
|
68
|
+
* @memberof me.Bounds
|
|
71
69
|
*/
|
|
72
70
|
get x() {
|
|
73
71
|
return this.min.x;
|
|
@@ -82,9 +80,9 @@ class Bounds {
|
|
|
82
80
|
/**
|
|
83
81
|
* y position of the bounds
|
|
84
82
|
* @public
|
|
85
|
-
* @type {
|
|
83
|
+
* @type {number}
|
|
86
84
|
* @name y
|
|
87
|
-
* @
|
|
85
|
+
* @memberof me.Bounds
|
|
88
86
|
*/
|
|
89
87
|
get y() {
|
|
90
88
|
return this.min.y;
|
|
@@ -100,9 +98,9 @@ class Bounds {
|
|
|
100
98
|
/**
|
|
101
99
|
* width of the bounds
|
|
102
100
|
* @public
|
|
103
|
-
* @type {
|
|
101
|
+
* @type {number}
|
|
104
102
|
* @name width
|
|
105
|
-
* @
|
|
103
|
+
* @memberof me.Bounds
|
|
106
104
|
*/
|
|
107
105
|
get width() {
|
|
108
106
|
return this.max.x - this.min.x;
|
|
@@ -115,9 +113,9 @@ class Bounds {
|
|
|
115
113
|
/**
|
|
116
114
|
* width of the bounds
|
|
117
115
|
* @public
|
|
118
|
-
* @type {
|
|
116
|
+
* @type {number}
|
|
119
117
|
* @name width
|
|
120
|
-
* @
|
|
118
|
+
* @memberof me.Bounds
|
|
121
119
|
*/
|
|
122
120
|
get height() {
|
|
123
121
|
return this.max.y - this.min.y;
|
|
@@ -130,9 +128,9 @@ class Bounds {
|
|
|
130
128
|
/**
|
|
131
129
|
* left coordinate of the bound
|
|
132
130
|
* @public
|
|
133
|
-
* @type {
|
|
131
|
+
* @type {number}
|
|
134
132
|
* @name left
|
|
135
|
-
* @
|
|
133
|
+
* @memberof me.Bounds
|
|
136
134
|
*/
|
|
137
135
|
get left() {
|
|
138
136
|
return this.min.x;
|
|
@@ -141,9 +139,9 @@ class Bounds {
|
|
|
141
139
|
/**
|
|
142
140
|
* right coordinate of the bound
|
|
143
141
|
* @public
|
|
144
|
-
* @type {
|
|
142
|
+
* @type {number}
|
|
145
143
|
* @name right
|
|
146
|
-
* @
|
|
144
|
+
* @memberof me.Bounds
|
|
147
145
|
*/
|
|
148
146
|
get right() {
|
|
149
147
|
return this.max.x;
|
|
@@ -152,9 +150,9 @@ class Bounds {
|
|
|
152
150
|
/**
|
|
153
151
|
* top coordinate of the bound
|
|
154
152
|
* @public
|
|
155
|
-
* @type {
|
|
153
|
+
* @type {number}
|
|
156
154
|
* @name top
|
|
157
|
-
* @
|
|
155
|
+
* @memberof me.Bounds
|
|
158
156
|
*/
|
|
159
157
|
get top() {
|
|
160
158
|
return this.min.y;
|
|
@@ -163,9 +161,9 @@ class Bounds {
|
|
|
163
161
|
/**
|
|
164
162
|
* bottom coordinate of the bound
|
|
165
163
|
* @public
|
|
166
|
-
* @type {
|
|
164
|
+
* @type {number}
|
|
167
165
|
* @name bottom
|
|
168
|
-
* @
|
|
166
|
+
* @memberof me.Bounds
|
|
169
167
|
*/
|
|
170
168
|
get bottom() {
|
|
171
169
|
return this.max.y;
|
|
@@ -174,9 +172,9 @@ class Bounds {
|
|
|
174
172
|
/**
|
|
175
173
|
* center position of the bound on the x axis
|
|
176
174
|
* @public
|
|
177
|
-
* @type {
|
|
175
|
+
* @type {number}
|
|
178
176
|
* @name centerX
|
|
179
|
-
* @
|
|
177
|
+
* @memberof me.Bounds
|
|
180
178
|
*/
|
|
181
179
|
get centerX() {
|
|
182
180
|
return this.min.x + (this.width / 2);
|
|
@@ -185,9 +183,9 @@ class Bounds {
|
|
|
185
183
|
/**
|
|
186
184
|
* center position of the bound on the y axis
|
|
187
185
|
* @public
|
|
188
|
-
* @type {
|
|
186
|
+
* @type {number}
|
|
189
187
|
* @name centerY
|
|
190
|
-
* @
|
|
188
|
+
* @memberof me.Bounds
|
|
191
189
|
*/
|
|
192
190
|
get centerY() {
|
|
193
191
|
return this.min.y + (this.height / 2);
|
|
@@ -198,7 +196,7 @@ class Bounds {
|
|
|
198
196
|
* @public
|
|
199
197
|
* @type {me.Vector2d}
|
|
200
198
|
* @name center
|
|
201
|
-
* @
|
|
199
|
+
* @memberof me.Bounds
|
|
202
200
|
*/
|
|
203
201
|
get center() {
|
|
204
202
|
return this._center.set(this.centerX, this.centerY);
|
|
@@ -207,7 +205,7 @@ class Bounds {
|
|
|
207
205
|
/**
|
|
208
206
|
* Updates bounds using the given vertices
|
|
209
207
|
* @name update
|
|
210
|
-
* @
|
|
208
|
+
* @memberof me.Bounds
|
|
211
209
|
* @function
|
|
212
210
|
* @param {me.Vector2d[]} vertices an array of me.Vector2d points
|
|
213
211
|
*/
|
|
@@ -218,7 +216,7 @@ class Bounds {
|
|
|
218
216
|
/**
|
|
219
217
|
* add the given vertices to the bounds definition.
|
|
220
218
|
* @name add
|
|
221
|
-
* @
|
|
219
|
+
* @memberof me.Bounds
|
|
222
220
|
* @function
|
|
223
221
|
* @param {me.Vector2d[]} vertices an array of me.Vector2d points
|
|
224
222
|
* @param {boolean} [clear=false] either to reset the bounds before adding the new vertices
|
|
@@ -239,7 +237,7 @@ class Bounds {
|
|
|
239
237
|
/**
|
|
240
238
|
* add the given bounds to the bounds definition.
|
|
241
239
|
* @name addBounds
|
|
242
|
-
* @
|
|
240
|
+
* @memberof me.Bounds
|
|
243
241
|
* @function
|
|
244
242
|
* @param {me.Bounds} bounds
|
|
245
243
|
* @param {boolean} [clear=false] either to reset the bounds before adding the new vertices
|
|
@@ -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 me.Bounds
|
|
262
260
|
* @function
|
|
263
|
-
* @param {me.Vector2d}
|
|
264
|
-
* @param {me.Matrix2d} [
|
|
261
|
+
* @param {me.Vector2d} v
|
|
262
|
+
* @param {me.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 me.Bounds
|
|
280
278
|
* @function
|
|
281
|
-
* @param {
|
|
282
|
-
* @param {
|
|
283
|
-
* @param {
|
|
284
|
-
* @param {
|
|
285
|
-
* @param {me.Matrix2d} [
|
|
279
|
+
* @param {number} x0 - left X coordinates of the quad
|
|
280
|
+
* @param {number} y0 - top Y coordinates of the quad
|
|
281
|
+
* @param {number} x1 - right X coordinates of the quad
|
|
282
|
+
* @param {number} y1 - bottom y coordinates of the quad
|
|
283
|
+
* @param {me.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,19 +297,19 @@ class Bounds {
|
|
|
299
297
|
/**
|
|
300
298
|
* Returns true if the bounds contains the given point.
|
|
301
299
|
* @name contains
|
|
302
|
-
* @
|
|
300
|
+
* @memberof me.Bounds
|
|
303
301
|
* @function
|
|
304
302
|
* @param {me.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 me.Bounds
|
|
311
309
|
* @function
|
|
312
|
-
* @param {
|
|
313
|
-
* @param {
|
|
314
|
-
* @
|
|
310
|
+
* @param {number} x
|
|
311
|
+
* @param {number} y
|
|
312
|
+
* @returns {boolean} True if the bounds contain the point, otherwise false
|
|
315
313
|
*/
|
|
316
314
|
contains() {
|
|
317
315
|
var arg0 = arguments[0];
|
|
@@ -341,10 +339,10 @@ class Bounds {
|
|
|
341
339
|
/**
|
|
342
340
|
* Returns true if the two bounds intersect.
|
|
343
341
|
* @name overlaps
|
|
344
|
-
* @
|
|
342
|
+
* @memberof me.Bounds
|
|
345
343
|
* @function
|
|
346
344
|
* @param {me.Bounds|me.Rect} bounds
|
|
347
|
-
* @
|
|
345
|
+
* @returns {boolean} True if the bounds overlap, otherwise false
|
|
348
346
|
*/
|
|
349
347
|
overlaps(bounds) {
|
|
350
348
|
return !(this.right < bounds.left || this.left > bounds.right ||
|
|
@@ -354,9 +352,9 @@ class Bounds {
|
|
|
354
352
|
/**
|
|
355
353
|
* determines whether all coordinates of this bounds are finite numbers.
|
|
356
354
|
* @name isFinite
|
|
357
|
-
* @
|
|
355
|
+
* @memberof me.Bounds
|
|
358
356
|
* @function
|
|
359
|
-
* @
|
|
357
|
+
* @returns {boolean} false if all coordinates are positive or negative Infinity or NaN; otherwise, true.
|
|
360
358
|
*/
|
|
361
359
|
isFinite() {
|
|
362
360
|
return (isFinite(this.min.x) && isFinite(this.max.x) && isFinite(this.min.y) && isFinite(this.max.y));
|
|
@@ -365,17 +363,17 @@ class Bounds {
|
|
|
365
363
|
/**
|
|
366
364
|
* Translates the bounds by the given vector.
|
|
367
365
|
* @name translate
|
|
368
|
-
* @
|
|
366
|
+
* @memberof me.Bounds
|
|
369
367
|
* @function
|
|
370
368
|
* @param {me.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 me.Bounds
|
|
376
374
|
* @function
|
|
377
|
-
* @param {
|
|
378
|
-
* @param {
|
|
375
|
+
* @param {number} x
|
|
376
|
+
* @param {number} y
|
|
379
377
|
*/
|
|
380
378
|
translate() {
|
|
381
379
|
var _x, _y;
|
|
@@ -397,17 +395,17 @@ class Bounds {
|
|
|
397
395
|
/**
|
|
398
396
|
* Shifts the bounds to the given position vector.
|
|
399
397
|
* @name shift
|
|
400
|
-
* @
|
|
398
|
+
* @memberof me.Bounds
|
|
401
399
|
* @function
|
|
402
400
|
* @param {me.Vector2d} position
|
|
403
401
|
*/
|
|
404
402
|
/**
|
|
405
403
|
* Shifts the bounds to the given x, y position.
|
|
406
404
|
* @name shift
|
|
407
|
-
* @
|
|
405
|
+
* @memberof me.Bounds
|
|
408
406
|
* @function
|
|
409
|
-
* @param {
|
|
410
|
-
* @param {
|
|
407
|
+
* @param {number} x
|
|
408
|
+
* @param {number} y
|
|
411
409
|
*/
|
|
412
410
|
shift() {
|
|
413
411
|
var _x, _y;
|
|
@@ -434,9 +432,9 @@ class Bounds {
|
|
|
434
432
|
/**
|
|
435
433
|
* clone this bounds
|
|
436
434
|
* @name clone
|
|
437
|
-
* @
|
|
435
|
+
* @memberof me.Bounds
|
|
438
436
|
* @function
|
|
439
|
-
* @
|
|
437
|
+
* @returns {me.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 me.Bounds
|
|
451
449
|
* @function
|
|
452
|
-
* @
|
|
450
|
+
* @returns {me.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,7 @@ 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
|
-
* @
|
|
7
|
+
* @memberof me
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
var collision = {
|
|
@@ -12,9 +12,9 @@ var collision = {
|
|
|
12
12
|
/**
|
|
13
13
|
* The maximum number of children that a quadtree node can contain before it is split into sub-nodes.
|
|
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
|
*/
|
|
@@ -23,31 +23,30 @@ var collision = {
|
|
|
23
23
|
/**
|
|
24
24
|
* The maximum number of levels that the quadtree will create.
|
|
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
|
|
52
51
|
* @see me.body.collisionType
|
|
53
52
|
* @example
|
|
@@ -98,7 +97,7 @@ var collision = {
|
|
|
98
97
|
* a global instance of a response object used for collision detection <br>
|
|
99
98
|
* this object will be reused amongst collision detection call if not user-defined response is specified
|
|
100
99
|
* @name response
|
|
101
|
-
* @
|
|
100
|
+
* @memberof me.collision
|
|
102
101
|
* @public
|
|
103
102
|
* @type {me.collision.ResponseObject}
|
|
104
103
|
*/
|
|
@@ -107,12 +106,12 @@ var collision = {
|
|
|
107
106
|
/**
|
|
108
107
|
* Checks for object colliding with the given line
|
|
109
108
|
* @name rayCast
|
|
110
|
-
* @
|
|
109
|
+
* @memberof me.collision
|
|
111
110
|
* @public
|
|
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
|
@@ -17,12 +17,12 @@ 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 me.collision
|
|
21
21
|
* @ignore
|
|
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,15 +38,15 @@ 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
|
|
51
51
|
*/
|
|
52
52
|
class ResponseObject {
|
|
@@ -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
|
/**
|
|
@@ -69,9 +68,10 @@ class ResponseObject {
|
|
|
69
68
|
* Response object for multiple intersection tests <br>
|
|
70
69
|
* (recommended as it will avoid allocating extra memory) <br>
|
|
71
70
|
* @name clear
|
|
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
|
@@ -53,13 +53,12 @@ var QT_VECTOR = new Vector2d();
|
|
|
53
53
|
* a QuadTree implementation in JavaScript, a 2d spatial subdivision algorithm.
|
|
54
54
|
* @class
|
|
55
55
|
* @name QuadTree
|
|
56
|
-
* @
|
|
57
|
-
* @constructor
|
|
56
|
+
* @memberof me
|
|
58
57
|
* @see me.game.world.broadphase
|
|
59
58
|
* @param {me.Bounds} bounds bounds of the node
|
|
60
|
-
* @param {
|
|
61
|
-
* @param {
|
|
62
|
-
* @param {
|
|
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
|
|
63
62
|
*/
|
|
64
63
|
class QuadTree {
|
|
65
64
|
|
|
@@ -120,14 +119,15 @@ class QuadTree {
|
|
|
120
119
|
/*
|
|
121
120
|
* Determine which node the object belongs to
|
|
122
121
|
* @param {me.Rect} rect bounds of the area to be checked
|
|
123
|
-
* @
|
|
122
|
+
* @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
123
|
*/
|
|
125
124
|
getIndex(item) {
|
|
126
125
|
var pos;
|
|
126
|
+
var bounds = item.getBounds();
|
|
127
127
|
|
|
128
128
|
// use game world coordinates for floating items
|
|
129
|
-
if (item.
|
|
130
|
-
pos = viewport.localToWorld(
|
|
129
|
+
if (item.isFloating === true) {
|
|
130
|
+
pos = viewport.localToWorld(bounds.left, bounds.top, QT_VECTOR);
|
|
131
131
|
} else {
|
|
132
132
|
pos = QT_VECTOR.set(item.left, item.top);
|
|
133
133
|
}
|
|
@@ -135,8 +135,8 @@ class QuadTree {
|
|
|
135
135
|
var index = -1,
|
|
136
136
|
rx = pos.x,
|
|
137
137
|
ry = pos.y,
|
|
138
|
-
rw =
|
|
139
|
-
rh =
|
|
138
|
+
rw = bounds.width,
|
|
139
|
+
rh = bounds.height,
|
|
140
140
|
verticalMidpoint = this.bounds.left + (this.bounds.width / 2),
|
|
141
141
|
horizontalMidpoint = this.bounds.top + (this.bounds.height / 2),
|
|
142
142
|
//rect can completely fit within the top quadrants
|
|
@@ -166,7 +166,7 @@ class QuadTree {
|
|
|
166
166
|
/**
|
|
167
167
|
* Insert the given object container into the node.
|
|
168
168
|
* @name insertContainer
|
|
169
|
-
* @
|
|
169
|
+
* @memberof me.QuadTree
|
|
170
170
|
* @function
|
|
171
171
|
* @param {me.Container} container group of objects to be added
|
|
172
172
|
*/
|
|
@@ -195,9 +195,9 @@ class QuadTree {
|
|
|
195
195
|
* exceeds the capacity, it will split and add all
|
|
196
196
|
* objects to their corresponding subnodes.
|
|
197
197
|
* @name insert
|
|
198
|
-
* @
|
|
198
|
+
* @memberof me.QuadTree
|
|
199
199
|
* @function
|
|
200
|
-
* @param {
|
|
200
|
+
* @param {object} item object to be added
|
|
201
201
|
*/
|
|
202
202
|
insert(item) {
|
|
203
203
|
var index = -1;
|
|
@@ -240,11 +240,11 @@ class QuadTree {
|
|
|
240
240
|
/**
|
|
241
241
|
* Return all objects that could collide with the given object
|
|
242
242
|
* @name retrieve
|
|
243
|
-
* @
|
|
243
|
+
* @memberof me.QuadTree
|
|
244
244
|
* @function
|
|
245
|
-
* @param {
|
|
246
|
-
* @param {
|
|
247
|
-
* @
|
|
245
|
+
* @param {object} item object to be checked against
|
|
246
|
+
* @param {object} [fn] a sorting function for the returned array
|
|
247
|
+
* @returns {object[]} array with all detected objects
|
|
248
248
|
*/
|
|
249
249
|
retrieve(item, fn) {
|
|
250
250
|
var returnObjects = this.objects;
|
|
@@ -276,10 +276,10 @@ class QuadTree {
|
|
|
276
276
|
* Remove the given item from the quadtree.
|
|
277
277
|
* (this function won't recalculate the impacted node)
|
|
278
278
|
* @name remove
|
|
279
|
-
* @
|
|
279
|
+
* @memberof me.QuadTree
|
|
280
280
|
* @function
|
|
281
|
-
* @param {
|
|
282
|
-
* @
|
|
281
|
+
* @param {object} item object to be removed
|
|
282
|
+
* @returns {boolean} true if the item was found and removed.
|
|
283
283
|
*/
|
|
284
284
|
remove(item) {
|
|
285
285
|
var found = false;
|
|
@@ -317,9 +317,9 @@ class QuadTree {
|
|
|
317
317
|
/**
|
|
318
318
|
* return true if the node is prunable
|
|
319
319
|
* @name isPrunable
|
|
320
|
-
* @
|
|
320
|
+
* @memberof me.QuadTree
|
|
321
321
|
* @function
|
|
322
|
-
* @
|
|
322
|
+
* @returns {boolean} true if the node is prunable
|
|
323
323
|
*/
|
|
324
324
|
isPrunable() {
|
|
325
325
|
return !(this.hasChildren() || (this.objects.length > 0));
|
|
@@ -328,9 +328,9 @@ class QuadTree {
|
|
|
328
328
|
/**
|
|
329
329
|
* return true if the node has any children
|
|
330
330
|
* @name hasChildren
|
|
331
|
-
* @
|
|
331
|
+
* @memberof me.QuadTree
|
|
332
332
|
* @function
|
|
333
|
-
* @
|
|
333
|
+
* @returns {boolean} true if the node has any children
|
|
334
334
|
*/
|
|
335
335
|
hasChildren() {
|
|
336
336
|
for (var i = 0; i < this.nodes.length; i = i + 1) {
|
|
@@ -345,8 +345,9 @@ class QuadTree {
|
|
|
345
345
|
/**
|
|
346
346
|
* clear the quadtree
|
|
347
347
|
* @name clear
|
|
348
|
-
* @
|
|
348
|
+
* @memberof me.QuadTree
|
|
349
349
|
* @function
|
|
350
|
+
* @param {me.Bounds} [bounds=this.bounds] the bounds to be cleared
|
|
350
351
|
*/
|
|
351
352
|
clear(bounds) {
|
|
352
353
|
this.objects.length = 0;
|