melonjs 15.0.0 → 15.1.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 +4 -4
- package/dist/melonjs.mjs/_virtual/_commonjsHelpers.js +1 -1
- package/dist/melonjs.mjs/_virtual/arraymultimap.js +1 -1
- package/dist/melonjs.mjs/_virtual/earcut.js +1 -1
- package/dist/melonjs.mjs/_virtual/howler.js +1 -1
- package/dist/melonjs.mjs/_virtual/index.js +7 -3
- package/dist/melonjs.mjs/_virtual/index2.js +1 -1
- package/dist/melonjs.mjs/_virtual/multimap.js +1 -1
- package/dist/melonjs.mjs/_virtual/setmultimap.js +1 -1
- package/dist/melonjs.mjs/application/application.js +27 -17
- package/dist/melonjs.mjs/application/header.js +6 -5
- package/dist/melonjs.mjs/application/resize.js +20 -20
- package/dist/melonjs.mjs/application/settings.js +1 -1
- package/dist/melonjs.mjs/audio/audio.js +17 -17
- package/dist/melonjs.mjs/camera/camera2d.js +10 -10
- package/dist/melonjs.mjs/const.js +1 -1
- package/dist/melonjs.mjs/entity/entity.js +4 -4
- package/dist/melonjs.mjs/geometries/ellipse.js +6 -6
- package/dist/melonjs.mjs/geometries/line.js +9 -9
- package/dist/melonjs.mjs/geometries/path2d.js +53 -53
- package/dist/melonjs.mjs/geometries/point.js +2 -2
- package/dist/melonjs.mjs/geometries/poly.js +29 -29
- package/dist/melonjs.mjs/geometries/rectangle.js +8 -8
- package/dist/melonjs.mjs/geometries/roundrect.js +6 -6
- package/dist/melonjs.mjs/index.js +5 -5
- package/dist/melonjs.mjs/input/gamepad.js +30 -30
- package/dist/melonjs.mjs/input/input.js +2 -2
- package/dist/melonjs.mjs/input/keyboard.js +15 -15
- package/dist/melonjs.mjs/input/pointer.js +2 -2
- package/dist/melonjs.mjs/input/pointerevent.js +58 -58
- package/dist/melonjs.mjs/lang/console.js +3 -3
- package/dist/melonjs.mjs/lang/deprecated.js +2 -2
- package/dist/melonjs.mjs/level/level.js +9 -9
- package/dist/melonjs.mjs/level/tiled/TMXGroup.js +3 -3
- package/dist/melonjs.mjs/level/tiled/TMXLayer.js +31 -31
- package/dist/melonjs.mjs/level/tiled/TMXObject.js +8 -8
- package/dist/melonjs.mjs/level/tiled/TMXTile.js +8 -8
- package/dist/melonjs.mjs/level/tiled/TMXTileMap.js +19 -19
- package/dist/melonjs.mjs/level/tiled/TMXTileset.js +15 -15
- package/dist/melonjs.mjs/level/tiled/TMXTilesetGroup.js +3 -3
- package/dist/melonjs.mjs/level/tiled/TMXUtils.js +46 -41
- package/dist/melonjs.mjs/level/tiled/constants.js +1 -1
- package/dist/melonjs.mjs/level/tiled/renderer/TMXHexagonalRenderer.js +30 -30
- package/dist/melonjs.mjs/level/tiled/renderer/TMXIsometricRenderer.js +21 -21
- package/dist/melonjs.mjs/level/tiled/renderer/TMXOrthogonalRenderer.js +10 -10
- package/dist/melonjs.mjs/level/tiled/renderer/TMXRenderer.js +2 -2
- package/dist/melonjs.mjs/level/tiled/renderer/TMXStaggeredRenderer.js +6 -6
- package/dist/melonjs.mjs/level/tiled/renderer/autodetect.js +1 -1
- package/dist/melonjs.mjs/loader/cache.js +1 -1
- package/dist/melonjs.mjs/loader/loader.js +7 -7
- package/dist/melonjs.mjs/loader/loadingscreen.js +2 -2
- package/dist/melonjs.mjs/loader/melonjs_logo.png.js +1 -1
- package/dist/melonjs.mjs/loader/parser.js +13 -13
- package/dist/melonjs.mjs/loader/settings.js +3 -3
- package/dist/melonjs.mjs/math/color.js +21 -21
- package/dist/melonjs.mjs/math/math.js +2 -2
- package/dist/melonjs.mjs/math/matrix2.js +22 -22
- package/dist/melonjs.mjs/math/matrix3.js +52 -52
- package/dist/melonjs.mjs/math/observable_vector2.js +12 -12
- package/dist/melonjs.mjs/math/observable_vector3.js +22 -22
- package/dist/melonjs.mjs/math/vector2.js +11 -11
- package/dist/melonjs.mjs/math/vector3.js +21 -21
- package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/esm/arraymultimap.js +45 -0
- package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/esm/multimap.js +130 -0
- package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/arraymultimap.js +1 -1
- package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/index.js +1 -1
- package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/multimap.js +1 -1
- package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/setmultimap.js +1 -1
- package/dist/melonjs.mjs/node_modules/earcut/src/earcut.js +1 -1
- package/dist/melonjs.mjs/node_modules/eventemitter3/index.js +2 -2
- package/dist/melonjs.mjs/node_modules/eventemitter3/index2.js +1 -1
- package/dist/melonjs.mjs/node_modules/howler/dist/howler.js +1 -1
- package/dist/melonjs.mjs/particles/emitter.js +5 -5
- package/dist/melonjs.mjs/particles/particle.js +8 -8
- package/dist/melonjs.mjs/particles/settings.js +3 -3
- package/dist/melonjs.mjs/physics/body.js +17 -17
- package/dist/melonjs.mjs/physics/bounds.js +12 -12
- package/dist/melonjs.mjs/physics/collision.js +3 -3
- package/dist/melonjs.mjs/physics/detector.js +14 -14
- package/dist/melonjs.mjs/physics/quadtree.js +19 -19
- package/dist/melonjs.mjs/physics/response.js +1 -1
- package/dist/melonjs.mjs/physics/sat.js +60 -60
- package/dist/melonjs.mjs/physics/world.js +4 -4
- package/dist/melonjs.mjs/plugin/plugin.js +11 -11
- package/dist/melonjs.mjs/renderable/collectable.js +2 -2
- package/dist/melonjs.mjs/renderable/colorlayer.js +1 -1
- package/dist/melonjs.mjs/renderable/container.js +77 -59
- package/dist/melonjs.mjs/renderable/dragndrop.js +5 -5
- package/dist/melonjs.mjs/renderable/imagelayer.js +7 -6
- package/dist/melonjs.mjs/renderable/light2d.js +6 -6
- package/dist/melonjs.mjs/renderable/nineslicesprite.js +12 -12
- package/dist/melonjs.mjs/renderable/renderable.js +11 -11
- package/dist/melonjs.mjs/renderable/sprite.js +25 -25
- package/dist/melonjs.mjs/renderable/trigger.js +11 -9
- package/dist/melonjs.mjs/renderable/ui/uibaseelement.js +97 -27
- package/dist/melonjs.mjs/renderable/ui/uispriteelement.js +25 -25
- package/dist/melonjs.mjs/renderable/ui/uitextbutton.js +83 -63
- package/dist/melonjs.mjs/state/stage.js +7 -7
- package/dist/melonjs.mjs/state/state.js +15 -15
- package/dist/melonjs.mjs/system/device.js +2 -2
- package/dist/melonjs.mjs/system/dom.js +1 -1
- package/dist/melonjs.mjs/system/event.js +2 -2
- package/dist/melonjs.mjs/system/platform.js +1 -1
- package/dist/melonjs.mjs/system/pooling.js +9 -9
- package/dist/melonjs.mjs/system/save.js +6 -6
- package/dist/melonjs.mjs/system/timer.js +16 -12
- package/dist/melonjs.mjs/text/bitmaptext.js +20 -20
- package/dist/melonjs.mjs/text/bitmaptextdata.js +22 -22
- package/dist/melonjs.mjs/text/glyph.js +3 -3
- package/dist/melonjs.mjs/text/text.js +10 -9
- package/dist/melonjs.mjs/text/textmetrics.js +15 -15
- package/dist/melonjs.mjs/text/textstyle.js +1 -1
- package/dist/melonjs.mjs/tweens/easing.js +4 -4
- package/dist/melonjs.mjs/tweens/interpolation.js +8 -8
- package/dist/melonjs.mjs/tweens/tween.js +11 -11
- package/dist/melonjs.mjs/utils/agent.js +6 -6
- package/dist/melonjs.mjs/utils/array.js +4 -4
- package/dist/melonjs.mjs/utils/file.js +1 -1
- package/dist/melonjs.mjs/utils/function.js +5 -5
- package/dist/melonjs.mjs/utils/string.js +3 -3
- package/dist/melonjs.mjs/utils/utils.js +16 -16
- package/dist/melonjs.mjs/video/canvas/canvas_renderer.js +35 -109
- package/dist/melonjs.mjs/video/renderer.js +74 -7
- package/dist/melonjs.mjs/video/texture/atlas.js +37 -37
- package/dist/melonjs.mjs/video/texture/cache.js +9 -10
- package/dist/melonjs.mjs/video/texture/canvas_texture.js +63 -3
- package/dist/melonjs.mjs/video/utils/autodetect.js +1 -1
- package/dist/melonjs.mjs/video/video.js +2 -2
- package/dist/melonjs.mjs/video/webgl/buffer/vertex.js +3 -3
- package/dist/melonjs.mjs/video/webgl/compositors/compositor.js +5 -5
- package/dist/melonjs.mjs/video/webgl/compositors/primitive_compositor.js +5 -5
- package/dist/melonjs.mjs/video/webgl/compositors/quad_compositor.js +18 -15
- package/dist/melonjs.mjs/video/webgl/glshader.js +7 -7
- package/dist/melonjs.mjs/video/webgl/shaders/primitive.frag.js +1 -1
- package/dist/melonjs.mjs/video/webgl/shaders/primitive.vert.js +1 -1
- package/dist/melonjs.mjs/video/webgl/shaders/quad.frag.js +1 -1
- package/dist/melonjs.mjs/video/webgl/shaders/quad.vert.js +1 -1
- package/dist/melonjs.mjs/video/webgl/utils/attributes.js +2 -2
- package/dist/melonjs.mjs/video/webgl/utils/precision.js +1 -1
- package/dist/melonjs.mjs/video/webgl/utils/program.js +7 -7
- package/dist/melonjs.mjs/video/webgl/utils/string.js +1 -1
- package/dist/melonjs.mjs/video/webgl/utils/uniforms.js +4 -4
- package/dist/melonjs.mjs/video/webgl/webgl_renderer.js +55 -38
- package/dist/melonjs.module.js +1747 -1809
- package/dist/types/application/application.d.ts +11 -8
- package/dist/types/audio/audio.d.ts +3 -3
- package/dist/types/index.d.ts +4 -3
- package/dist/types/input/input.d.ts +1 -1
- package/dist/types/input/keyboard.d.ts +1 -1
- package/dist/types/input/pointerevent.d.ts +6 -6
- package/dist/types/level/level.d.ts +2 -2
- package/dist/types/level/tiled/TMXLayer.d.ts +4 -4
- package/dist/types/level/tiled/TMXTileMap.d.ts +2 -2
- package/dist/types/level/tiled/TMXUtils.d.ts +5 -4
- package/dist/types/loader/loader.d.ts +2 -2
- package/dist/types/loader/settings.d.ts +2 -2
- package/dist/types/particles/emitter.d.ts +1 -1
- package/dist/types/physics/collision.d.ts +1 -1
- package/dist/types/physics/detector.d.ts +1 -1
- package/dist/types/plugin/plugin.d.ts +2 -2
- package/dist/types/renderable/container.d.ts +21 -17
- package/dist/types/renderable/sprite.d.ts +11 -11
- package/dist/types/renderable/trigger.d.ts +1 -1
- package/dist/types/renderable/ui/uibaseelement.d.ts +28 -6
- package/dist/types/renderable/ui/uispriteelement.d.ts +12 -14
- package/dist/types/renderable/ui/uitextbutton.d.ts +52 -11
- package/dist/types/state/stage.d.ts +1 -1
- package/dist/types/system/device.d.ts +1 -1
- package/dist/types/system/pooling.d.ts +3 -3
- package/dist/types/system/timer.d.ts +5 -5
- package/dist/types/text/bitmaptext.d.ts +1 -1
- package/dist/types/text/text.d.ts +1 -1
- package/dist/types/utils/array.d.ts +2 -2
- package/dist/types/video/canvas/canvas_renderer.d.ts +8 -76
- package/dist/types/video/renderer.d.ts +48 -0
- package/dist/types/video/texture/atlas.d.ts +3 -3
- package/dist/types/video/texture/canvas_texture.d.ts +40 -0
- package/dist/types/video/webgl/glshader.d.ts +1 -1
- package/dist/types/video/webgl/webgl_renderer.d.ts +13 -9
- package/package.json +14 -14
- package/src/application/application.js +26 -16
- package/src/application/header.js +5 -4
- package/src/application/resize.js +19 -19
- package/src/audio/audio.js +16 -16
- package/src/camera/camera2d.js +9 -9
- package/src/entity/entity.js +3 -3
- package/src/geometries/ellipse.js +5 -5
- package/src/geometries/line.js +8 -8
- package/src/geometries/path2d.js +52 -52
- package/src/geometries/point.js +1 -1
- package/src/geometries/poly.js +28 -28
- package/src/geometries/rectangle.js +7 -7
- package/src/geometries/roundrect.js +5 -5
- package/src/index.js +3 -2
- package/src/input/gamepad.js +29 -29
- package/src/input/input.js +1 -1
- package/src/input/keyboard.js +14 -14
- package/src/input/pointer.js +1 -1
- package/src/input/pointerevent.js +52 -52
- package/src/lang/console.js +2 -2
- package/src/lang/deprecated.js +1 -1
- package/src/level/level.js +8 -8
- package/src/level/tiled/TMXGroup.js +2 -2
- package/src/level/tiled/TMXLayer.js +30 -30
- package/src/level/tiled/TMXObject.js +7 -7
- package/src/level/tiled/TMXTile.js +7 -7
- package/src/level/tiled/TMXTileMap.js +18 -18
- package/src/level/tiled/TMXTileset.js +14 -14
- package/src/level/tiled/TMXTilesetGroup.js +2 -2
- package/src/level/tiled/TMXUtils.js +45 -40
- package/src/level/tiled/renderer/TMXHexagonalRenderer.js +29 -29
- package/src/level/tiled/renderer/TMXIsometricRenderer.js +20 -20
- package/src/level/tiled/renderer/TMXOrthogonalRenderer.js +9 -9
- package/src/level/tiled/renderer/TMXRenderer.js +1 -1
- package/src/level/tiled/renderer/TMXStaggeredRenderer.js +5 -5
- package/src/loader/loader.js +6 -6
- package/src/loader/loadingscreen.js +1 -1
- package/src/loader/parser.js +12 -12
- package/src/loader/settings.js +2 -2
- package/src/math/color.js +20 -20
- package/src/math/math.js +1 -1
- package/src/math/matrix2.js +21 -21
- package/src/math/matrix3.js +51 -51
- package/src/math/observable_vector2.js +11 -11
- package/src/math/observable_vector3.js +21 -21
- package/src/math/vector2.js +10 -10
- package/src/math/vector3.js +20 -20
- package/src/particles/emitter.js +4 -4
- package/src/particles/particle.js +7 -7
- package/src/particles/settings.js +2 -2
- package/src/physics/body.js +16 -16
- package/src/physics/bounds.js +11 -11
- package/src/physics/collision.js +2 -2
- package/src/physics/detector.js +13 -13
- package/src/physics/quadtree.js +18 -18
- package/src/physics/sat.js +59 -59
- package/src/physics/world.js +3 -3
- package/src/plugin/plugin.js +8 -8
- package/src/renderable/collectable.js +1 -1
- package/src/renderable/container.js +76 -58
- package/src/renderable/dragndrop.js +4 -4
- package/src/renderable/imagelayer.js +6 -5
- package/src/renderable/light2d.js +5 -5
- package/src/renderable/nineslicesprite.js +11 -11
- package/src/renderable/renderable.js +10 -10
- package/src/renderable/sprite.js +24 -24
- package/src/renderable/trigger.js +10 -8
- package/src/renderable/ui/uibaseelement.js +96 -26
- package/src/renderable/ui/uispriteelement.js +24 -24
- package/src/renderable/ui/uitextbutton.js +85 -65
- package/src/state/stage.js +6 -6
- package/src/state/state.js +14 -14
- package/src/system/device.js +1 -1
- package/src/system/event.js +1 -1
- package/src/system/pooling.js +8 -8
- package/src/system/save.js +5 -5
- package/src/system/timer.js +15 -11
- package/src/text/bitmaptext.js +19 -19
- package/src/text/bitmaptextdata.js +21 -21
- package/src/text/glyph.js +2 -2
- package/src/text/text.js +9 -8
- package/src/text/textmetrics.js +14 -14
- package/src/tweens/easing.js +3 -3
- package/src/tweens/interpolation.js +7 -7
- package/src/tweens/tween.js +10 -10
- package/src/utils/agent.js +5 -5
- package/src/utils/array.js +3 -3
- package/src/utils/function.js +4 -4
- package/src/utils/string.js +2 -2
- package/src/utils/utils.js +15 -15
- package/src/video/canvas/canvas_renderer.js +34 -108
- package/src/video/renderer.js +72 -5
- package/src/video/texture/atlas.js +36 -36
- package/src/video/texture/cache.js +6 -6
- package/src/video/texture/canvas_texture.js +62 -2
- package/src/video/video.js +1 -1
- package/src/video/webgl/buffer/vertex.js +2 -2
- package/src/video/webgl/compositors/compositor.js +4 -4
- package/src/video/webgl/compositors/primitive_compositor.js +4 -4
- package/src/video/webgl/compositors/quad_compositor.js +17 -14
- package/src/video/webgl/glshader.js +6 -6
- package/src/video/webgl/utils/attributes.js +1 -1
- package/src/video/webgl/utils/program.js +6 -6
- package/src/video/webgl/utils/uniforms.js +3 -3
- package/src/video/webgl/webgl_renderer.js +54 -37
package/src/math/vector3.js
CHANGED
|
@@ -222,7 +222,7 @@ import pool from "./../system/pooling.js";
|
|
|
222
222
|
* @returns {Vector3d} Reference to this object for method chaining
|
|
223
223
|
*/
|
|
224
224
|
minV(v) {
|
|
225
|
-
|
|
225
|
+
let _vz = v.z || 0;
|
|
226
226
|
return this._set((this.x < v.x) ? this.x : v.x, (this.y < v.y) ? this.y : v.y, (this.z < _vz) ? this.z : _vz);
|
|
227
227
|
}
|
|
228
228
|
|
|
@@ -234,7 +234,7 @@ import pool from "./../system/pooling.js";
|
|
|
234
234
|
* @returns {Vector3d} Reference to this object for method chaining
|
|
235
235
|
*/
|
|
236
236
|
maxV(v) {
|
|
237
|
-
|
|
237
|
+
let _vz = v.z || 0;
|
|
238
238
|
return this._set((this.x > v.x) ? this.x : v.x, (this.y > v.y) ? this.y : v.y, (this.z > _vz) ? this.z : _vz);
|
|
239
239
|
}
|
|
240
240
|
|
|
@@ -327,7 +327,7 @@ import pool from "./../system/pooling.js";
|
|
|
327
327
|
* @returns {boolean}
|
|
328
328
|
*/
|
|
329
329
|
equals() {
|
|
330
|
-
|
|
330
|
+
let _x, _y, _z;
|
|
331
331
|
if (arguments.length >= 2) {
|
|
332
332
|
// x, y, z
|
|
333
333
|
_x = arguments[0];
|
|
@@ -377,8 +377,8 @@ import pool from "./../system/pooling.js";
|
|
|
377
377
|
* @returns {Vector3d} Reference to this object for method chaining
|
|
378
378
|
*/
|
|
379
379
|
rotate(angle, v) {
|
|
380
|
-
|
|
381
|
-
|
|
380
|
+
let cx = 0;
|
|
381
|
+
let cy = 0;
|
|
382
382
|
|
|
383
383
|
if (typeof v === "object") {
|
|
384
384
|
cx = v.x;
|
|
@@ -386,11 +386,11 @@ import pool from "./../system/pooling.js";
|
|
|
386
386
|
}
|
|
387
387
|
|
|
388
388
|
// TODO also rotate on the z axis if the given vector is a 3d one
|
|
389
|
-
|
|
390
|
-
|
|
389
|
+
let x = this.x - cx;
|
|
390
|
+
let y = this.y - cy;
|
|
391
391
|
|
|
392
|
-
|
|
393
|
-
|
|
392
|
+
let c = Math.cos(angle);
|
|
393
|
+
let s = Math.sin(angle);
|
|
394
394
|
|
|
395
395
|
return this._set(x * c - y * s + cx, x * s + y * c + cy, this.z);
|
|
396
396
|
}
|
|
@@ -414,8 +414,8 @@ import pool from "./../system/pooling.js";
|
|
|
414
414
|
* @returns {Vector3d} Reference to this object for method chaining
|
|
415
415
|
*/
|
|
416
416
|
cross(v) {
|
|
417
|
-
|
|
418
|
-
|
|
417
|
+
let ax = this.x, ay = this.y, az = this.z;
|
|
418
|
+
let bx = v.x, by = v.y, bz = v.z;
|
|
419
419
|
|
|
420
420
|
this.x = ay * bz - az * by;
|
|
421
421
|
this.y = az * bx - ax * bz;
|
|
@@ -468,12 +468,12 @@ import pool from "./../system/pooling.js";
|
|
|
468
468
|
* @returns {Vector3d} Reference to this object for method chaining
|
|
469
469
|
*/
|
|
470
470
|
moveTowards(target, step) {
|
|
471
|
-
|
|
471
|
+
let angle = Math.atan2(target.y - this.y, target.x - this.x);
|
|
472
472
|
|
|
473
|
-
|
|
474
|
-
|
|
473
|
+
let dx = this.x - target.x;
|
|
474
|
+
let dy = this.y - target.y;
|
|
475
475
|
|
|
476
|
-
|
|
476
|
+
let distance = Math.sqrt(dx * dx + dy * dy);
|
|
477
477
|
|
|
478
478
|
if (distance === 0 || (step >= 0 && distance <= step * step)) {
|
|
479
479
|
return target;
|
|
@@ -493,9 +493,9 @@ import pool from "./../system/pooling.js";
|
|
|
493
493
|
* @returns {number}
|
|
494
494
|
*/
|
|
495
495
|
distance(v) {
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
496
|
+
let dx = this.x - v.x;
|
|
497
|
+
let dy = this.y - v.y;
|
|
498
|
+
let dz = this.z - (v.z || 0);
|
|
499
499
|
return Math.sqrt(dx * dx + dy * dy + dz * dz);
|
|
500
500
|
}
|
|
501
501
|
|
|
@@ -518,7 +518,7 @@ import pool from "./../system/pooling.js";
|
|
|
518
518
|
* @returns {Vector3d} Reference to this object for method chaining
|
|
519
519
|
*/
|
|
520
520
|
project(v) {
|
|
521
|
-
|
|
521
|
+
let ratio = this.dot(v) / v.length2();
|
|
522
522
|
return this.scale(ratio, ratio, ratio);
|
|
523
523
|
}
|
|
524
524
|
|
|
@@ -531,7 +531,7 @@ import pool from "./../system/pooling.js";
|
|
|
531
531
|
* @returns {Vector3d} Reference to this object for method chaining
|
|
532
532
|
*/
|
|
533
533
|
projectN(v) {
|
|
534
|
-
|
|
534
|
+
let ratio = this.dot(v) / v.length2();
|
|
535
535
|
return this.scale(ratio, ratio, ratio);
|
|
536
536
|
}
|
|
537
537
|
|
package/src/particles/emitter.js
CHANGED
|
@@ -8,7 +8,7 @@ import Container from "./../renderable/container.js";
|
|
|
8
8
|
* @ignore
|
|
9
9
|
*/
|
|
10
10
|
function createDefaultParticleTexture(w = 8, h = 8) {
|
|
11
|
-
|
|
11
|
+
let defaultParticleTexture = pool.pull("CanvasTexture", w, h, { offscreenCanvas: true });
|
|
12
12
|
|
|
13
13
|
defaultParticleTexture.context.fillStyle = "#fff";
|
|
14
14
|
defaultParticleTexture.context.fillRect(0, 0, w, h);
|
|
@@ -28,7 +28,7 @@ function createDefaultParticleTexture(w = 8, h = 8) {
|
|
|
28
28
|
* @param {ParticleEmitterSettings} [settings=ParticleEmitterSettings] - the settings for the particle emitter.
|
|
29
29
|
* @example
|
|
30
30
|
* // Create a particle emitter at position 100, 100
|
|
31
|
-
*
|
|
31
|
+
* let emitter = new ParticleEmitter(100, 100, {
|
|
32
32
|
* width: 16,
|
|
33
33
|
* height : 16,
|
|
34
34
|
* tint: "#f00",
|
|
@@ -144,7 +144,7 @@ function createDefaultParticleTexture(w = 8, h = 8) {
|
|
|
144
144
|
// Add count particles in the game world
|
|
145
145
|
/** @ignore */
|
|
146
146
|
addParticles(count) {
|
|
147
|
-
for (
|
|
147
|
+
for (let i = 0; i < count; i++) {
|
|
148
148
|
// Add particle to the container
|
|
149
149
|
this.addChild(pool.pull("Particle", this), this.pos.z);
|
|
150
150
|
}
|
|
@@ -224,7 +224,7 @@ function createDefaultParticleTexture(w = 8, h = 8) {
|
|
|
224
224
|
this._frequencyTimer += dt;
|
|
225
225
|
|
|
226
226
|
// Check for new particles launch
|
|
227
|
-
|
|
227
|
+
const particlesCount = this.children.length;
|
|
228
228
|
if ((particlesCount < this.settings.totalParticles) && (this._frequencyTimer >= this.settings.frequency)) {
|
|
229
229
|
if ((particlesCount + this.settings.maxParticles) <= this.settings.totalParticles) {
|
|
230
230
|
this.addParticles(this.settings.maxParticles);
|
|
@@ -60,8 +60,8 @@ import Renderable from "./../renderable/renderable.js";
|
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
// Set the start particle Angle and Speed as defined in emitter
|
|
63
|
-
|
|
64
|
-
|
|
63
|
+
let angle = emitter.settings.angle + ((emitter.settings.angleVariation > 0) ? (randomFloat(0, 2) - 1) * emitter.settings.angleVariation : 0);
|
|
64
|
+
let speed = emitter.settings.speed + ((emitter.settings.speedVariation > 0) ? (randomFloat(0, 2) - 1) * emitter.settings.speedVariation : 0);
|
|
65
65
|
|
|
66
66
|
// Set the start particle Velocity
|
|
67
67
|
this.vel.set(speed * Math.cos(angle), -speed * Math.sin(angle));
|
|
@@ -111,7 +111,7 @@ import Renderable from "./../renderable/renderable.js";
|
|
|
111
111
|
*/
|
|
112
112
|
update(dt) {
|
|
113
113
|
// move things forward independent of the current frame rate
|
|
114
|
-
|
|
114
|
+
let skew = dt * this._deltaInv;
|
|
115
115
|
|
|
116
116
|
// Decrease particle life
|
|
117
117
|
this.life = this.life > dt ? this.life - dt : 0;
|
|
@@ -122,10 +122,10 @@ import Renderable from "./../renderable/renderable.js";
|
|
|
122
122
|
}
|
|
123
123
|
|
|
124
124
|
// Calculate the particle Age Ratio
|
|
125
|
-
|
|
125
|
+
let ageRatio = this.life / this.startLife;
|
|
126
126
|
|
|
127
127
|
// Resize the particle as particle Age Ratio
|
|
128
|
-
|
|
128
|
+
let scale = this.startScale;
|
|
129
129
|
if (this.startScale > this.endScale) {
|
|
130
130
|
scale *= ageRatio;
|
|
131
131
|
scale = (scale < this.endScale) ? this.endScale : scale;
|
|
@@ -143,7 +143,7 @@ import Renderable from "./../renderable/renderable.js";
|
|
|
143
143
|
this.vel.y += this.gravity * skew;
|
|
144
144
|
|
|
145
145
|
// If necessary update the rotation of particle in accordance the particle trajectory
|
|
146
|
-
|
|
146
|
+
let angle = this.followTrajectory ? Math.atan2(this.vel.y, this.vel.x) : this.angle;
|
|
147
147
|
|
|
148
148
|
this.pos.x += this.vel.x * skew;
|
|
149
149
|
this.pos.y += this.vel.y * skew;
|
|
@@ -165,7 +165,7 @@ import Renderable from "./../renderable/renderable.js";
|
|
|
165
165
|
* @ignore
|
|
166
166
|
*/
|
|
167
167
|
draw(renderer) {
|
|
168
|
-
|
|
168
|
+
let w = this.width, h = this.height;
|
|
169
169
|
renderer.drawImage(
|
|
170
170
|
this.image,
|
|
171
171
|
0, 0,
|
|
@@ -78,7 +78,7 @@ const ParticleEmitterSettings = {
|
|
|
78
78
|
angle : Math.PI / 2,
|
|
79
79
|
|
|
80
80
|
/**
|
|
81
|
-
*
|
|
81
|
+
* letiation in the start angle for particle launch in Radians.
|
|
82
82
|
* @public
|
|
83
83
|
* @type {number}
|
|
84
84
|
* @name angleVariation
|
|
@@ -118,7 +118,7 @@ const ParticleEmitterSettings = {
|
|
|
118
118
|
speed : 2,
|
|
119
119
|
|
|
120
120
|
/**
|
|
121
|
-
*
|
|
121
|
+
* letiation in the start speed of particles
|
|
122
122
|
* @public
|
|
123
123
|
* @type {number}
|
|
124
124
|
* @name speedVariation
|
package/src/physics/body.js
CHANGED
|
@@ -212,7 +212,7 @@ import Point from "../geometries/point.js";
|
|
|
212
212
|
// parses the given shapes array and add them
|
|
213
213
|
if (typeof shapes !== "undefined") {
|
|
214
214
|
if (Array.isArray(shapes)) {
|
|
215
|
-
for (
|
|
215
|
+
for (let s = 0; s < shapes.length; s++) {
|
|
216
216
|
this.addShape(shapes[s]);
|
|
217
217
|
}
|
|
218
218
|
} else {
|
|
@@ -246,7 +246,7 @@ import Point from "../geometries/point.js";
|
|
|
246
246
|
*/
|
|
247
247
|
addShape(shape) {
|
|
248
248
|
if (shape instanceof Rect || shape instanceof Bounds) {
|
|
249
|
-
|
|
249
|
+
let poly = shape.toPolygon();
|
|
250
250
|
this.shapes.push(poly);
|
|
251
251
|
// update the body bounds
|
|
252
252
|
this.bounds.add(poly.points);
|
|
@@ -297,7 +297,7 @@ import Point from "../geometries/point.js";
|
|
|
297
297
|
* @param {boolean} [clear=true] - either to reset the body definition before adding the new vertices
|
|
298
298
|
*/
|
|
299
299
|
setVertices(vertices, index = 0, clear = true) {
|
|
300
|
-
|
|
300
|
+
let polygon = this.getShape(index);
|
|
301
301
|
if (polygon instanceof Polygon) {
|
|
302
302
|
polygon.setShape(0, 0, vertices);
|
|
303
303
|
} else {
|
|
@@ -336,7 +336,7 @@ import Point from "../geometries/point.js";
|
|
|
336
336
|
* this.body.fromJSON(me.loader.getJSON("shapesdef"), "banana");
|
|
337
337
|
*/
|
|
338
338
|
fromJSON(json, id) {
|
|
339
|
-
|
|
339
|
+
let data = json;
|
|
340
340
|
|
|
341
341
|
if (typeof id !== "undefined" ) {
|
|
342
342
|
data = json[id];
|
|
@@ -349,7 +349,7 @@ import Point from "../geometries/point.js";
|
|
|
349
349
|
|
|
350
350
|
if (data.length) {
|
|
351
351
|
// go through all shapes and add them to the body
|
|
352
|
-
for (
|
|
352
|
+
for (let i = 0; i < data.length; i++) {
|
|
353
353
|
this.addVertices(data[i].shape, i);
|
|
354
354
|
}
|
|
355
355
|
// apply density, friction and bounce properties from the first shape
|
|
@@ -391,7 +391,7 @@ import Point from "../geometries/point.js";
|
|
|
391
391
|
// remove the shape from shape list
|
|
392
392
|
arrayUtil.remove(this.shapes, shape);
|
|
393
393
|
// add everything left back
|
|
394
|
-
for (
|
|
394
|
+
for (let s = 0; s < this.shapes.length; s++) {
|
|
395
395
|
this.addShape(this.shapes[s]);
|
|
396
396
|
}
|
|
397
397
|
// return the length of the shape list
|
|
@@ -448,7 +448,7 @@ import Point from "../geometries/point.js";
|
|
|
448
448
|
*/
|
|
449
449
|
respondToCollision(response) {
|
|
450
450
|
// the overlap vector
|
|
451
|
-
|
|
451
|
+
let overlap = response.overlapV;
|
|
452
452
|
|
|
453
453
|
// FIXME: Respond proportionally to object mass
|
|
454
454
|
|
|
@@ -470,7 +470,7 @@ import Point from "../geometries/point.js";
|
|
|
470
470
|
|
|
471
471
|
if (!this.ignoreGravity) {
|
|
472
472
|
// cancel the falling an jumping flags if necessary
|
|
473
|
-
|
|
473
|
+
let dir = this.falling === true ? 1 : this.jumping === true ? -1 : 0;
|
|
474
474
|
this.falling = overlap.y >= dir;
|
|
475
475
|
this.jumping = overlap.y <= -dir;
|
|
476
476
|
}
|
|
@@ -495,10 +495,10 @@ import Point from "../geometries/point.js";
|
|
|
495
495
|
* mySprite.body.forEach((shape, index, array) => { ... }, thisArg);
|
|
496
496
|
*/
|
|
497
497
|
forEach(callback, thisArg) {
|
|
498
|
-
|
|
499
|
-
|
|
498
|
+
let context = this, i = 0;
|
|
499
|
+
let shapes = this.shapes;
|
|
500
500
|
|
|
501
|
-
|
|
501
|
+
let len = shapes.length;
|
|
502
502
|
|
|
503
503
|
if (typeof callback !== "function") {
|
|
504
504
|
throw new Error(callback + " is not a function");
|
|
@@ -527,7 +527,7 @@ import Point from "../geometries/point.js";
|
|
|
527
527
|
* @returns {boolean} true if contains
|
|
528
528
|
*/
|
|
529
529
|
contains() {
|
|
530
|
-
|
|
530
|
+
let _x, _y;
|
|
531
531
|
|
|
532
532
|
if (arguments.length === 2) {
|
|
533
533
|
// x, y
|
|
@@ -541,7 +541,7 @@ import Point from "../geometries/point.js";
|
|
|
541
541
|
|
|
542
542
|
if (this.getBounds().contains(_x, _y)) {
|
|
543
543
|
// cannot use forEach here as cannot break out with a return
|
|
544
|
-
for (
|
|
544
|
+
for (let i = this.shapes.length, shape; i--, (shape = this.shapes[i]);) {
|
|
545
545
|
if (shape.contains(_x, _y)) {
|
|
546
546
|
return true;
|
|
547
547
|
}
|
|
@@ -615,7 +615,7 @@ import Point from "../geometries/point.js";
|
|
|
615
615
|
update(dt) { // eslint-disable-line no-unused-vars
|
|
616
616
|
// apply timer.tick to delta time for linear interpolation (when enabled)
|
|
617
617
|
// #761 add delta time in body update
|
|
618
|
-
|
|
618
|
+
let deltaTime = /* dt * */ timer.tick;
|
|
619
619
|
|
|
620
620
|
// apply force if defined
|
|
621
621
|
if (this.force.x !== 0) {
|
|
@@ -627,7 +627,7 @@ import Point from "../geometries/point.js";
|
|
|
627
627
|
|
|
628
628
|
// apply friction if defined
|
|
629
629
|
if (this.friction.x > 0) {
|
|
630
|
-
|
|
630
|
+
let fx = this.friction.x * deltaTime,
|
|
631
631
|
nx = this.vel.x + fx,
|
|
632
632
|
x = this.vel.x - fx;
|
|
633
633
|
|
|
@@ -637,7 +637,7 @@ import Point from "../geometries/point.js";
|
|
|
637
637
|
);
|
|
638
638
|
}
|
|
639
639
|
if (this.friction.y > 0) {
|
|
640
|
-
|
|
640
|
+
let fy = this.friction.y * deltaTime,
|
|
641
641
|
ny = this.vel.y + fy,
|
|
642
642
|
y = this.vel.y - fy;
|
|
643
643
|
|
package/src/physics/bounds.js
CHANGED
|
@@ -62,7 +62,7 @@ import Vector2d from "./../math/vector2.js";
|
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
set x(value) {
|
|
65
|
-
|
|
65
|
+
let deltaX = this.max.x - this.min.x;
|
|
66
66
|
this.min.x = value;
|
|
67
67
|
this.max.x = value + deltaX;
|
|
68
68
|
}
|
|
@@ -76,7 +76,7 @@ import Vector2d from "./../math/vector2.js";
|
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
set y(value) {
|
|
79
|
-
|
|
79
|
+
let deltaY = this.max.y - this.min.y;
|
|
80
80
|
|
|
81
81
|
this.min.y = value;
|
|
82
82
|
this.max.y = value + deltaY;
|
|
@@ -189,8 +189,8 @@ import Vector2d from "./../math/vector2.js";
|
|
|
189
189
|
if (clear === true) {
|
|
190
190
|
this.clear();
|
|
191
191
|
}
|
|
192
|
-
for (
|
|
193
|
-
|
|
192
|
+
for (let i = 0; i < vertices.length; i++) {
|
|
193
|
+
let vertex = vertices[i];
|
|
194
194
|
if (vertex.x > this.max.x) this.max.x = vertex.x;
|
|
195
195
|
if (vertex.x < this.min.x) this.min.x = vertex.x;
|
|
196
196
|
if (vertex.y > this.max.y) this.max.y = vertex.y;
|
|
@@ -242,7 +242,7 @@ import Vector2d from "./../math/vector2.js";
|
|
|
242
242
|
* @param {Matrix2d} [m] - an optional transform to apply to the given frame coordinates
|
|
243
243
|
*/
|
|
244
244
|
addFrame(x0, y0, x1, y1, m) {
|
|
245
|
-
|
|
245
|
+
let v = pool.pull("Point");
|
|
246
246
|
|
|
247
247
|
this.addPoint(v.set(x0, y0), m);
|
|
248
248
|
this.addPoint(v.set(x1, y0), m);
|
|
@@ -267,8 +267,8 @@ import Vector2d from "./../math/vector2.js";
|
|
|
267
267
|
* @returns {boolean} True if the bounds contain the point, otherwise false
|
|
268
268
|
*/
|
|
269
269
|
contains() {
|
|
270
|
-
|
|
271
|
-
|
|
270
|
+
let arg0 = arguments[0];
|
|
271
|
+
let _x1, _x2, _y1, _y2;
|
|
272
272
|
if (arguments.length === 2) {
|
|
273
273
|
// x, y
|
|
274
274
|
_x1 = _x2 = arg0;
|
|
@@ -322,7 +322,7 @@ import Vector2d from "./../math/vector2.js";
|
|
|
322
322
|
* @param {number} y
|
|
323
323
|
*/
|
|
324
324
|
translate() {
|
|
325
|
-
|
|
325
|
+
let _x, _y;
|
|
326
326
|
if (arguments.length === 2) {
|
|
327
327
|
// x, y
|
|
328
328
|
_x = arguments[0];
|
|
@@ -351,7 +351,7 @@ import Vector2d from "./../math/vector2.js";
|
|
|
351
351
|
* @param {number} y
|
|
352
352
|
*/
|
|
353
353
|
shift() {
|
|
354
|
-
|
|
354
|
+
let _x, _y;
|
|
355
355
|
|
|
356
356
|
if (arguments.length === 2) {
|
|
357
357
|
// x, y
|
|
@@ -363,7 +363,7 @@ import Vector2d from "./../math/vector2.js";
|
|
|
363
363
|
_y = arguments[0].y;
|
|
364
364
|
}
|
|
365
365
|
|
|
366
|
-
|
|
366
|
+
let deltaX = this.max.x - this.min.x,
|
|
367
367
|
deltaY = this.max.y - this.min.y;
|
|
368
368
|
|
|
369
369
|
this.min.x = _x;
|
|
@@ -377,7 +377,7 @@ import Vector2d from "./../math/vector2.js";
|
|
|
377
377
|
* @returns {Bounds}
|
|
378
378
|
*/
|
|
379
379
|
clone() {
|
|
380
|
-
|
|
380
|
+
let bounds = new Bounds();
|
|
381
381
|
bounds.addBounds(this);
|
|
382
382
|
return bounds;
|
|
383
383
|
}
|
package/src/physics/collision.js
CHANGED
|
@@ -6,7 +6,7 @@ import { game } from "../index.js";
|
|
|
6
6
|
* @namespace collision
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
let collision = {
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* The maximum number of children that a quadtree node can contain before it is split into sub-nodes.
|
|
@@ -101,7 +101,7 @@ var collision = {
|
|
|
101
101
|
* @returns {Array.<Renderable>} an array of intersecting physic objects
|
|
102
102
|
* @example
|
|
103
103
|
* // define a line accross the viewport
|
|
104
|
-
*
|
|
104
|
+
* let ray = new me.Line(
|
|
105
105
|
* // absolute position of the line
|
|
106
106
|
* 0, 0, [
|
|
107
107
|
* // starting point relative to the initial position
|
package/src/physics/detector.js
CHANGED
|
@@ -45,7 +45,7 @@ export default class Detector {
|
|
|
45
45
|
* @returns {boolean} true if they should collide, false otherwise
|
|
46
46
|
*/
|
|
47
47
|
shouldCollide(a, b) {
|
|
48
|
-
|
|
48
|
+
let bodyA = a.body,
|
|
49
49
|
bodyB = b.body;
|
|
50
50
|
return (
|
|
51
51
|
(typeof bodyA === "object" && typeof bodyB === "object") &&
|
|
@@ -66,9 +66,9 @@ export default class Detector {
|
|
|
66
66
|
*/
|
|
67
67
|
collides(bodyA, bodyB, response = this.response) {
|
|
68
68
|
// for each shape in body A
|
|
69
|
-
for (
|
|
69
|
+
for (let indexA = bodyA.shapes.length, shapeA; indexA--, (shapeA = bodyA.shapes[indexA]);) {
|
|
70
70
|
// for each shape in body B
|
|
71
|
-
for (
|
|
71
|
+
for (let indexB = bodyB.shapes.length, shapeB; indexB--, (shapeB = bodyB.shapes[indexB]);) {
|
|
72
72
|
// full SAT collision check
|
|
73
73
|
if (SAT["test" + shapeA.shapeType + shapeB.shapeType].call(
|
|
74
74
|
this,
|
|
@@ -98,9 +98,9 @@ export default class Detector {
|
|
|
98
98
|
* @returns {boolean} in case of collision, false otherwise
|
|
99
99
|
*/
|
|
100
100
|
collisions(objA) {
|
|
101
|
-
|
|
101
|
+
let collisionCounter = 0;
|
|
102
102
|
// retreive a list of potential colliding objects from the game world
|
|
103
|
-
|
|
103
|
+
let candidates = this.world.broadphase.retrieve(objA);
|
|
104
104
|
|
|
105
105
|
boundsA.addBounds(objA.getBounds(), true);
|
|
106
106
|
boundsA.addBounds(objA.body.getBounds());
|
|
@@ -142,7 +142,7 @@ export default class Detector {
|
|
|
142
142
|
* @returns {Array.<Renderable>} an array of intersecting physic objects
|
|
143
143
|
* @example
|
|
144
144
|
* // define a line accross the viewport
|
|
145
|
-
*
|
|
145
|
+
* let ray = new me.Line(
|
|
146
146
|
* // absolute position of the line
|
|
147
147
|
* 0, 0, [
|
|
148
148
|
* // starting point relative to the initial position
|
|
@@ -159,28 +159,28 @@ export default class Detector {
|
|
|
159
159
|
* }
|
|
160
160
|
*/
|
|
161
161
|
rayCast(line, result = []) {
|
|
162
|
-
|
|
162
|
+
let collisionCounter = 0;
|
|
163
163
|
|
|
164
164
|
// retrieve a list of potential colliding objects from the game world
|
|
165
|
-
|
|
165
|
+
let candidates = this.world.broadphase.retrieve(line);
|
|
166
166
|
|
|
167
|
-
for (
|
|
167
|
+
for (let i = candidates.length, objB; i--, (objB = candidates[i]);) {
|
|
168
168
|
|
|
169
169
|
// fast AABB check if both bounding boxes are overlaping
|
|
170
170
|
if (objB.body && line.getBounds().overlaps(objB.getBounds())) {
|
|
171
171
|
|
|
172
172
|
// go trough all defined shapes in B (if any)
|
|
173
|
-
|
|
173
|
+
let bLen = objB.body.shapes.length;
|
|
174
174
|
if ( objB.body.shapes.length === 0) {
|
|
175
175
|
continue;
|
|
176
176
|
}
|
|
177
177
|
|
|
178
|
-
|
|
178
|
+
let shapeA = line;
|
|
179
179
|
|
|
180
180
|
// go through all defined shapes in B
|
|
181
|
-
|
|
181
|
+
let indexB = 0;
|
|
182
182
|
do {
|
|
183
|
-
|
|
183
|
+
let shapeB = objB.body.getShape(indexB);
|
|
184
184
|
|
|
185
185
|
// full SAT collision check
|
|
186
186
|
if (SAT["test" + shapeA.shapeType + shapeB.shapeType]
|
package/src/physics/quadtree.js
CHANGED
|
@@ -11,7 +11,7 @@ import * as arrayUtil from "./../utils/array.js";
|
|
|
11
11
|
* a pool of `QuadTree` objects
|
|
12
12
|
* @ignore
|
|
13
13
|
*/
|
|
14
|
-
|
|
14
|
+
let QT_ARRAY = [];
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
17
|
* will pop a quadtree object from the array
|
|
@@ -20,7 +20,7 @@ var QT_ARRAY = [];
|
|
|
20
20
|
*/
|
|
21
21
|
function QT_ARRAY_POP(world, bounds, max_objects = 4, max_levels = 4, level = 0) {
|
|
22
22
|
if (QT_ARRAY.length > 0) {
|
|
23
|
-
|
|
23
|
+
let _qt = QT_ARRAY.pop();
|
|
24
24
|
_qt.world = world;
|
|
25
25
|
_qt.bounds = bounds;
|
|
26
26
|
_qt.max_objects = max_objects;
|
|
@@ -44,7 +44,7 @@ function QT_ARRAY_PUSH(qt) {
|
|
|
44
44
|
* a temporary vector object to be reused
|
|
45
45
|
* @ignore
|
|
46
46
|
*/
|
|
47
|
-
|
|
47
|
+
let QT_VECTOR = new Vector2d();
|
|
48
48
|
|
|
49
49
|
/**
|
|
50
50
|
* @classdesc
|
|
@@ -77,7 +77,7 @@ var QT_VECTOR = new Vector2d();
|
|
|
77
77
|
* Split the node into 4 subnodes
|
|
78
78
|
*/
|
|
79
79
|
split() {
|
|
80
|
-
|
|
80
|
+
let nextLevel = this.level + 1,
|
|
81
81
|
subWidth = this.bounds.width / 2,
|
|
82
82
|
subHeight = this.bounds.height / 2,
|
|
83
83
|
left = this.bounds.left,
|
|
@@ -146,8 +146,8 @@ var QT_VECTOR = new Vector2d();
|
|
|
146
146
|
* @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
|
|
147
147
|
*/
|
|
148
148
|
getIndex(item) {
|
|
149
|
-
|
|
150
|
-
|
|
149
|
+
let pos;
|
|
150
|
+
let bounds = item.getBounds();
|
|
151
151
|
|
|
152
152
|
// use game world coordinates for floating items
|
|
153
153
|
if (item.isFloating === true) {
|
|
@@ -156,7 +156,7 @@ var QT_VECTOR = new Vector2d();
|
|
|
156
156
|
pos = QT_VECTOR.set(item.left, item.top);
|
|
157
157
|
}
|
|
158
158
|
|
|
159
|
-
|
|
159
|
+
let index = -1,
|
|
160
160
|
rx = pos.x,
|
|
161
161
|
ry = pos.y,
|
|
162
162
|
rw = bounds.width,
|
|
@@ -194,7 +194,7 @@ var QT_VECTOR = new Vector2d();
|
|
|
194
194
|
* @param {Container} container - group of objects to be added
|
|
195
195
|
*/
|
|
196
196
|
insertContainer(container) {
|
|
197
|
-
for (
|
|
197
|
+
for (let i = container.children.length, child; i--, (child = container.children[i]);) {
|
|
198
198
|
if (child.isKinematic !== true) {
|
|
199
199
|
if (typeof child.addChild === "function") {
|
|
200
200
|
if (child.name !== "rootContainer") {
|
|
@@ -222,7 +222,7 @@ var QT_VECTOR = new Vector2d();
|
|
|
222
222
|
* @param {object} item - object to be added
|
|
223
223
|
*/
|
|
224
224
|
insert(item) {
|
|
225
|
-
|
|
225
|
+
let index = -1;
|
|
226
226
|
|
|
227
227
|
//if we have subnodes ...
|
|
228
228
|
if (this.nodes.length > 0) {
|
|
@@ -243,7 +243,7 @@ var QT_VECTOR = new Vector2d();
|
|
|
243
243
|
this.split();
|
|
244
244
|
}
|
|
245
245
|
|
|
246
|
-
|
|
246
|
+
let i = 0;
|
|
247
247
|
|
|
248
248
|
//add all objects to there corresponding subnodes
|
|
249
249
|
while (i < this.objects.length) {
|
|
@@ -268,19 +268,19 @@ var QT_VECTOR = new Vector2d();
|
|
|
268
268
|
* @returns {object[]} array with all detected objects
|
|
269
269
|
*/
|
|
270
270
|
retrieve(item, fn) {
|
|
271
|
-
|
|
271
|
+
let returnObjects = this.objects;
|
|
272
272
|
|
|
273
273
|
//if we have subnodes ...
|
|
274
274
|
if (this.nodes.length > 0) {
|
|
275
275
|
|
|
276
|
-
|
|
276
|
+
let index = this.getIndex(item);
|
|
277
277
|
|
|
278
278
|
//if rect fits into a subnode ..
|
|
279
279
|
if (index !== -1) {
|
|
280
280
|
returnObjects = returnObjects.concat(this.nodes[index].retrieve(item));
|
|
281
281
|
} else {
|
|
282
282
|
//if rect does not fit into a subnode, check it against all subnodes
|
|
283
|
-
for (
|
|
283
|
+
for (let i = 0; i < this.nodes.length; i = i + 1) {
|
|
284
284
|
returnObjects = returnObjects.concat(this.nodes[i].retrieve(item));
|
|
285
285
|
}
|
|
286
286
|
}
|
|
@@ -302,7 +302,7 @@ var QT_VECTOR = new Vector2d();
|
|
|
302
302
|
* @returns {boolean} true if the item was found and removed.
|
|
303
303
|
*/
|
|
304
304
|
remove(item) {
|
|
305
|
-
|
|
305
|
+
let found = false;
|
|
306
306
|
|
|
307
307
|
if (typeof (item.getBounds) === "undefined") {
|
|
308
308
|
// ignore object that cannot be added in the first place
|
|
@@ -312,7 +312,7 @@ var QT_VECTOR = new Vector2d();
|
|
|
312
312
|
//if we have subnodes ...
|
|
313
313
|
if (this.nodes.length > 0) {
|
|
314
314
|
// determine to which node the item belongs to
|
|
315
|
-
|
|
315
|
+
let index = this.getIndex(item);
|
|
316
316
|
|
|
317
317
|
if (index !== -1) {
|
|
318
318
|
found = arrayUtil.remove(this.nodes[index], item);
|
|
@@ -351,8 +351,8 @@ var QT_VECTOR = new Vector2d();
|
|
|
351
351
|
* @returns {boolean} true if the node has any children
|
|
352
352
|
*/
|
|
353
353
|
hasChildren() {
|
|
354
|
-
for (
|
|
355
|
-
|
|
354
|
+
for (let i = 0; i < this.nodes.length; i = i + 1) {
|
|
355
|
+
let subnode = this.nodes[i];
|
|
356
356
|
if (subnode.length > 0 || subnode.objects.length > 0) {
|
|
357
357
|
return true;
|
|
358
358
|
}
|
|
@@ -369,7 +369,7 @@ var QT_VECTOR = new Vector2d();
|
|
|
369
369
|
clear(bounds) {
|
|
370
370
|
this.objects.length = 0;
|
|
371
371
|
|
|
372
|
-
for (
|
|
372
|
+
for (let i = 0; i < this.nodes.length; i++) {
|
|
373
373
|
this.nodes[i].clear();
|
|
374
374
|
// recycle the quadTree object
|
|
375
375
|
QT_ARRAY_PUSH(this.nodes[i]);
|