melonjs 10.2.2 → 10.4.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.
Files changed (95) hide show
  1. package/README.md +6 -6
  2. package/dist/melonjs.js +2907 -3383
  3. package/dist/melonjs.min.js +4 -4
  4. package/dist/melonjs.module.d.ts +3620 -4528
  5. package/dist/melonjs.module.js +3210 -3331
  6. package/package.json +19 -19
  7. package/src/audio/audio.js +30 -31
  8. package/src/camera/camera2d.js +47 -58
  9. package/src/entity/draggable.js +11 -21
  10. package/src/entity/droptarget.js +12 -22
  11. package/src/entity/entity.js +32 -38
  12. package/src/game.js +21 -22
  13. package/src/{shapes → geometries}/ellipse.js +40 -47
  14. package/src/{shapes → geometries}/line.js +9 -12
  15. package/src/{shapes → geometries}/poly.js +100 -53
  16. package/src/{shapes → geometries}/rectangle.js +42 -45
  17. package/src/index.js +9 -20
  18. package/src/input/gamepad.js +11 -10
  19. package/src/input/input.js +2 -3
  20. package/src/input/keyboard.js +113 -113
  21. package/src/input/pointer.js +61 -29
  22. package/src/input/pointerevent.js +92 -29
  23. package/src/lang/deprecated.js +44 -14
  24. package/src/level/level.js +23 -24
  25. package/src/level/tiled/TMXGroup.js +7 -9
  26. package/src/level/tiled/TMXLayer.js +30 -33
  27. package/src/level/tiled/TMXObject.js +59 -53
  28. package/src/level/tiled/TMXTile.js +18 -19
  29. package/src/level/tiled/TMXTileMap.js +38 -46
  30. package/src/level/tiled/TMXTileset.js +12 -16
  31. package/src/level/tiled/TMXTilesetGroup.js +9 -10
  32. package/src/level/tiled/renderer/TMXHexagonalRenderer.js +7 -9
  33. package/src/level/tiled/renderer/TMXIsometricRenderer.js +7 -9
  34. package/src/level/tiled/renderer/TMXOrthogonalRenderer.js +4 -6
  35. package/src/level/tiled/renderer/TMXRenderer.js +24 -26
  36. package/src/level/tiled/renderer/TMXStaggeredRenderer.js +1 -5
  37. package/src/loader/loader.js +17 -16
  38. package/src/loader/loadingscreen.js +8 -10
  39. package/src/math/color.js +47 -67
  40. package/src/math/math.js +15 -16
  41. package/src/math/matrix2.js +53 -59
  42. package/src/math/matrix3.js +56 -63
  43. package/src/math/observable_vector2.js +87 -77
  44. package/src/math/observable_vector3.js +97 -80
  45. package/src/math/vector2.js +107 -97
  46. package/src/math/vector3.js +116 -100
  47. package/src/particles/emitter.js +66 -76
  48. package/src/particles/particle.js +4 -6
  49. package/src/particles/particlecontainer.js +2 -4
  50. package/src/physics/body.js +47 -146
  51. package/src/physics/bounds.js +48 -50
  52. package/src/physics/collision.js +13 -14
  53. package/src/physics/detector.js +14 -14
  54. package/src/physics/quadtree.js +18 -21
  55. package/src/physics/sat.js +30 -30
  56. package/src/physics/world.js +24 -29
  57. package/src/plugin/plugin.js +11 -15
  58. package/src/renderable/GUI.js +41 -47
  59. package/src/renderable/collectable.js +5 -10
  60. package/src/renderable/colorlayer.js +10 -15
  61. package/src/renderable/container.js +87 -73
  62. package/src/renderable/imagelayer.js +25 -32
  63. package/src/renderable/nineslicesprite.js +41 -42
  64. package/src/renderable/renderable.js +113 -124
  65. package/src/renderable/sprite.js +62 -69
  66. package/src/renderable/trigger.js +26 -32
  67. package/src/state/stage.js +13 -18
  68. package/src/state/state.js +26 -27
  69. package/src/system/device.js +76 -133
  70. package/src/system/event.js +81 -70
  71. package/src/system/pooling.js +11 -12
  72. package/src/system/save.js +3 -4
  73. package/src/system/timer.js +19 -20
  74. package/src/text/bitmaptext.js +57 -55
  75. package/src/text/bitmaptextdata.js +10 -11
  76. package/src/text/glyph.js +3 -0
  77. package/src/text/text.js +49 -55
  78. package/src/tweens/easing.js +1 -1
  79. package/src/tweens/interpolation.js +1 -1
  80. package/src/tweens/tween.js +44 -46
  81. package/src/utils/agent.js +3 -4
  82. package/src/utils/array.js +4 -5
  83. package/src/utils/file.js +3 -4
  84. package/src/utils/function.js +4 -5
  85. package/src/utils/string.js +7 -9
  86. package/src/utils/utils.js +4 -5
  87. package/src/video/canvas/canvas_renderer.js +60 -62
  88. package/src/video/renderer.js +53 -58
  89. package/src/video/texture.js +98 -112
  90. package/src/video/texture_cache.js +4 -6
  91. package/src/video/video.js +16 -17
  92. package/src/video/webgl/buffer/vertex.js +2 -2
  93. package/src/video/webgl/glshader.js +37 -39
  94. package/src/video/webgl/webgl_compositor.js +128 -110
  95. package/src/video/webgl/webgl_renderer.js +126 -106
@@ -1,23 +1,21 @@
1
1
  import Vector2d from "./../math/vector2.js";
2
- import Polygon from "./../shapes/poly.js";
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
- * @memberOf me.Bounds
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
- * @memberOf me.Bounds
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
- * @memberOf me.Bounds
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
- * @memberOf me.Bounds
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
- * @memberOf me.Bounds
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
- * @memberOf me.Bounds
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
- * @memberOf me.Bounds
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
- * @memberOf me.Bounds
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
- * @memberOf me.Bounds
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
- * @memberOf me.Bounds
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
- * @memberOf me.Bounds
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
- * @memberOf me.Bounds
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 {me.Vector2d}
197
+ * @type {Vector2d}
200
198
  * @name center
201
- * @memberOf me.Bounds
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
- * @memberOf me.Bounds
208
+ * @memberof Bounds
211
209
  * @function
212
- * @param {me.Vector2d[]} vertices an array of me.Vector2d points
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
- * @memberOf me.Bounds
219
+ * @memberof Bounds
222
220
  * @function
223
- * @param {me.Vector2d[]} vertices an array of me.Vector2d points
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
- * @memberOf me.Bounds
240
+ * @memberof Bounds
243
241
  * @function
244
- * @param {me.Bounds} bounds
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
- * @memberOf me.Bounds
259
+ * @memberof Bounds
262
260
  * @function
263
- * @param {me.Vector2d} v
264
- * @param {me.Matrix2d} [m] an optional transform to apply to the given point
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
- * @memberOf me.Bounds
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 {me.Matrix2d} [m] an optional transform to apply to the given frame coordinates
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
- * @memberOf me.Bounds
300
+ * @memberof Bounds
303
301
  * @function
304
- * @param {me.Vector2d} point
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
- * @memberOf me.Bounds
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
- * @memberOf me.Bounds
342
+ * @memberof Bounds
345
343
  * @function
346
- * @param {me.Bounds|me.Rect} bounds
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
- * @memberOf me.Bounds
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
- * @memberOf me.Bounds
366
+ * @memberof Bounds
369
367
  * @function
370
- * @param {me.Vector2d} vector
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
- * @memberOf me.Bounds
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
- * @memberOf me.Bounds
398
+ * @memberof Bounds
401
399
  * @function
402
- * @param {me.Vector2d} position
400
+ * @param {Vector2d} position
403
401
  */
404
402
  /**
405
403
  * Shifts the bounds to the given x, y position.
406
404
  * @name shift
407
- * @memberOf me.Bounds
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
- * @memberOf me.Bounds
435
+ * @memberof Bounds
438
436
  * @function
439
- * @returns {me.Bounds}
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
- * @memberOf me.Bounds
448
+ * @memberof Bounds
451
449
  * @function
452
- * @returns {me.Polygon} a new Polygon that represents this bounds.
450
+ * @returns {Polygon} a new Polygon that represents this bounds.
453
451
  */
454
452
  toPolygon () {
455
453
  return new Polygon(this.x, this.y, [
@@ -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 me.collision
14
+ * @memberof collision
16
15
  * @public
17
16
  * @type {number}
18
17
  * @default 8
19
- * @see me.game.world.broadphase
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 me.collision
25
+ * @memberof collision
27
26
  * @public
28
27
  * @type {number}
29
28
  * @default 4
30
- * @see me.game.world.broadphase
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 me.collision
50
- * @see me.body.setCollisionMask
51
- * @see me.body.collisionType
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 me.collision
99
+ * @memberof collision
101
100
  * @public
102
- * @type {me.collision.ResponseObject}
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 me.collision
108
+ * @memberof collision
110
109
  * @public
111
110
  * @function
112
- * @param {me.Line} line line to be tested for collision
113
- * @param {Array.<me.Renderable>} [result] a user defined array that will be populated with intersecting physic objects.
114
- * @returns {Array.<me.Renderable>} an array of intersecting physic objects
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(
@@ -17,11 +17,11 @@ 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 me.collision
20
+ * @memberof collision
21
21
  * @ignore
22
22
  * @function
23
- * @param {me.Renderable} a a reference to the object A.
24
- * @param {me.Renderable} b a reference to the object B.
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) {
@@ -36,17 +36,17 @@ function shouldCollide(a, b) {
36
36
  /**
37
37
  * @classdesc
38
38
  * An object representing the result of an intersection.
39
- * @property {me.Renderable} a The first object participating in the intersection
40
- * @property {me.Renderable} b The second object participating in the intersection
39
+ * @property {Renderable} a The first object participating in the intersection
40
+ * @property {Renderable} b The second object participating in the intersection
41
41
  * @property {number} overlap Magnitude of the overlap on the shortest colliding axis
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
- * @property {me.Vector2d} overlapN The shortest colliding axis (unit-vector)
42
+ * @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
43
+ * @property {Vector2d} overlapN The shortest colliding axis (unit-vector)
44
44
  * @property {boolean} aInB Whether the first object is entirely inside the second
45
45
  * @property {boolean} bInA Whether the second object is entirely inside the first
46
46
  * @property {number} indexShapeA The index of the colliding shape for the object a body
47
47
  * @property {number} indexShapeB The index of the colliding shape for the object b body
48
48
  * @name ResponseObject
49
- * @memberOf me.collision
49
+ * @memberof collision
50
50
  * @public
51
51
  */
52
52
  class ResponseObject {
@@ -68,7 +68,7 @@ class ResponseObject {
68
68
  * Response object for multiple intersection tests <br>
69
69
  * (recommended as it will avoid allocating extra memory) <br>
70
70
  * @name clear
71
- * @memberOf me.collision.ResponseObject
71
+ * @memberof collision.ResponseObject
72
72
  * @public
73
73
  * @function
74
74
  * @returns {object} this object for chaining
@@ -91,8 +91,8 @@ export var globalResponse = new ResponseObject();
91
91
  * @name collisionCheck
92
92
  * @ignore
93
93
  * @function
94
- * @param {me.Renderable} objA object to be tested for collision
95
- * @param {me.collision.ResponseObject} [response=me.collision.response] a user defined response object that will be populated if they intersect.
94
+ * @param {Renderable} objA object to be tested for collision
95
+ * @param {collision.ResponseObject} [response=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) {
@@ -163,9 +163,9 @@ export function collisionCheck(objA, response = globalResponse) {
163
163
  * @name rayCast
164
164
  * @ignore
165
165
  * @function
166
- * @param {me.Line} line line to be tested for collision
167
- * @param {Array.<me.Renderable>} [result] a user defined array that will be populated with intersecting physic objects.
168
- * @returns {Array.<me.Renderable>} an array of intersecting physic objects
166
+ * @param {Line} line line to be tested for collision
167
+ * @param {Array.<Renderable>} [result] a user defined array that will be populated with intersecting physic objects.
168
+ * @returns {Array.<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(
@@ -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
- * @class
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 {me.Rect} rect bounds of the area to be checked
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) {
@@ -130,7 +127,7 @@ class QuadTree {
130
127
  if (item.isFloating === true) {
131
128
  pos = viewport.localToWorld(bounds.left, bounds.top, QT_VECTOR);
132
129
  } else {
133
- pos = QT_VECTOR.set(bounds.left, bounds.top);
130
+ pos = QT_VECTOR.set(item.left, item.top);
134
131
  }
135
132
 
136
133
  var index = -1,
@@ -167,9 +164,9 @@ class QuadTree {
167
164
  /**
168
165
  * Insert the given object container into the node.
169
166
  * @name insertContainer
170
- * @memberOf me.QuadTree
167
+ * @memberof QuadTree
171
168
  * @function
172
- * @param {me.Container} container group of objects to be added
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
- * @memberOf me.QuadTree
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
- * @memberOf me.QuadTree
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
- * @memberOf me.QuadTree
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
- * @memberOf me.QuadTree
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
- * @memberOf me.QuadTree
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
- * @memberOf me.QuadTree
346
+ * @memberof QuadTree
350
347
  * @function
351
- * @param {me.Bounds} [bounds=this.bounds] the bounds to be cleared
348
+ * @param {Bounds} [bounds=this.bounds] the bounds to be cleared
352
349
  */
353
350
  clear(bounds) {
354
351
  this.objects.length = 0;