melonjs 14.5.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/LICENSE.md +1 -1
- package/README.md +6 -6
- 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 +18 -20
- 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 +56 -56
- 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 +8 -6
- 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 +59 -59
- 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 +25 -24
- 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 +35 -13
- 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 -65
- 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 +3 -3
- 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 +63 -92
- package/dist/melonjs.mjs/text/textmetrics.js +15 -15
- package/dist/melonjs.mjs/text/textstyle.js +4 -6
- 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 +41 -119
- package/dist/melonjs.mjs/video/renderer.js +70 -14
- package/dist/melonjs.mjs/video/texture/atlas.js +39 -45
- 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 +23 -19
- package/dist/melonjs.mjs/video/webgl/compositors/compositor.js +80 -80
- package/dist/melonjs.mjs/video/webgl/compositors/primitive_compositor.js +77 -0
- package/dist/melonjs.mjs/video/webgl/compositors/quad_compositor.js +252 -0
- package/dist/melonjs.mjs/video/webgl/compositors/webgl_compositor.js +1 -1
- 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 +2 -2
- package/dist/melonjs.mjs/video/webgl/shaders/quad.frag.js +1 -1
- package/dist/melonjs.mjs/video/webgl/shaders/quad.vert.js +2 -2
- 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 +188 -181
- package/dist/melonjs.module.js +25040 -25193
- package/dist/types/application/application.d.ts +11 -8
- package/dist/types/audio/audio.d.ts +3 -3
- package/dist/types/entity/entity.d.ts +1 -1
- package/dist/types/index.d.ts +7 -4
- 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/renderable.d.ts +6 -0
- 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 -12
- 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 +7 -21
- package/dist/types/text/textstyle.d.ts +1 -1
- package/dist/types/utils/array.d.ts +2 -2
- package/dist/types/video/canvas/canvas_renderer.d.ts +8 -81
- package/dist/types/video/renderer.d.ts +48 -4
- 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/buffer/vertex.d.ts +3 -3
- package/dist/types/video/webgl/compositors/compositor.d.ts +38 -32
- package/dist/types/video/webgl/compositors/primitive_compositor.d.ts +22 -0
- package/dist/types/video/webgl/compositors/quad_compositor.d.ts +72 -0
- package/dist/types/video/webgl/glshader.d.ts +1 -1
- package/dist/types/video/webgl/webgl_renderer.d.ts +47 -37
- package/package.json +16 -17
- 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 +17 -19
- 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 +55 -55
- 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 +9 -4
- 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 +24 -23
- 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/polyfill/index.js +0 -2
- 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 +34 -12
- 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 -67
- package/src/state/stage.js +6 -6
- package/src/state/state.js +14 -14
- package/src/system/device.js +2 -2
- 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 +62 -91
- package/src/text/textmetrics.js +14 -14
- package/src/text/textstyle.js +3 -5
- 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 +39 -117
- package/src/video/renderer.js +68 -12
- package/src/video/texture/atlas.js +38 -44
- 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 +22 -18
- package/src/video/webgl/compositors/compositor.js +79 -80
- package/src/video/webgl/compositors/primitive_compositor.js +68 -0
- package/src/video/webgl/compositors/{webgl_compositor.js → quad_compositor.js} +52 -109
- package/src/video/webgl/glshader.js +6 -6
- package/src/video/webgl/shaders/primitive.vert +2 -5
- package/src/video/webgl/shaders/quad.vert +3 -1
- 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 +186 -179
- package/dist/melonjs.mjs/_virtual/make-built-in.js +0 -10
- package/dist/melonjs.mjs/_virtual/object-define-property.js +0 -10
- package/dist/melonjs.mjs/_virtual/object-get-own-property-descriptor.js +0 -10
- package/dist/melonjs.mjs/_virtual/object-get-own-property-names.js +0 -10
- package/dist/melonjs.mjs/_virtual/object-get-own-property-symbols.js +0 -10
- package/dist/melonjs.mjs/_virtual/object-property-is-enumerable.js +0 -10
- package/dist/melonjs.mjs/_virtual/shared.js +0 -10
- package/dist/melonjs.mjs/game.js +0 -29
- package/dist/melonjs.mjs/polyfill/console.js +0 -18
- package/dist/melonjs.mjs/polyfill/performance.js +0 -27
- package/dist/melonjs.mjs/polyfill/requestAnimationFrame.js +0 -46
- package/dist/melonjs.mjs/polyfill/roundrect.js +0 -242
- package/dist/melonjs.mjs/renderable/re_container.js +0 -1016
- package/dist/melonjs.mjs/video/utils/resize.js +0 -116
- package/dist/melonjs.mjs/video/webgl/webgl_compositor.js +0 -494
- package/src/polyfill/performance.js +0 -20
- package/src/polyfill/requestAnimationFrame.js +0 -39
|
@@ -27,13 +27,14 @@ import { CANVAS, WEBGL, AUTO } from "../const.js";
|
|
|
27
27
|
* @param {number|string} [options.scale=1.0] - enable scaling of the canvas ('auto' for automatic scaling)
|
|
28
28
|
* @param {string} [options.scaleMethod="fit"] - screen scaling modes ('fit','fill-min','fill-max','flex','flex-width','flex-height','stretch')
|
|
29
29
|
* @param {boolean} [options.preferWebGL1=false] - if true the renderer will only use WebGL 1
|
|
30
|
+
* @param {boolean} [options.depthTest="sorting"] - ~Experimental~ the default method to sort object on the z axis in WebGL ("sorting", "z-buffer")
|
|
30
31
|
* @param {string} [options.powerPreference="default"] - a hint to the user agent indicating what configuration of GPU is suitable for the WebGL context ("default", "high-performance", "low-power"). To be noted that Safari and Chrome (since version 80) both default to "low-power" to save battery life and improve the user experience on these dual-GPU machines.
|
|
31
32
|
* @param {boolean} [options.transparent=false] - whether to allow transparent pixels in the front buffer (screen).
|
|
32
33
|
* @param {boolean} [options.antiAlias=false] - whether to enable or not video scaling interpolation
|
|
33
34
|
* @param {boolean} [options.consoleHeader=true] - whether to display melonJS version and basic device information in the console
|
|
34
35
|
* @throws Will throw an exception if it fails to instantiate a renderer
|
|
35
36
|
* @example
|
|
36
|
-
*
|
|
37
|
+
* let my game = new Application(640, 480, {renderer: me.video.AUTO}) {
|
|
37
38
|
* ....
|
|
38
39
|
* }
|
|
39
40
|
*/
|
|
@@ -72,14 +73,6 @@ import { CANVAS, WEBGL, AUTO } from "../const.js";
|
|
|
72
73
|
*/
|
|
73
74
|
this.mergeGroup = true;
|
|
74
75
|
|
|
75
|
-
/**
|
|
76
|
-
* Specify the property to be used when sorting renderables.
|
|
77
|
-
* Accepted values : "x", "y", "z"
|
|
78
|
-
* @type {string}
|
|
79
|
-
* @default "z"
|
|
80
|
-
*/
|
|
81
|
-
this.sortOn = "z";
|
|
82
|
-
|
|
83
76
|
/**
|
|
84
77
|
* Last time the game update loop was executed. <br>
|
|
85
78
|
* Use this value to implement frame prediction in drawing events,
|
|
@@ -144,6 +137,7 @@ import { CANVAS, WEBGL, AUTO } from "../const.js";
|
|
|
144
137
|
this.settings.transparent = !!(this.settings.transparent);
|
|
145
138
|
this.settings.antiAlias = !!(this.settings.antiAlias);
|
|
146
139
|
this.settings.failIfMajorPerformanceCaveat = !!(this.settings.failIfMajorPerformanceCaveat);
|
|
140
|
+
this.settings.depthTest = this.settings.depthTest === "z-buffer" ? "z-buffer" : "sorting";
|
|
147
141
|
this.settings.subPixel = !!(this.settings.subPixel);
|
|
148
142
|
this.settings.verbose = !!(this.settings.verbose);
|
|
149
143
|
if (this.settings.scaleMethod.search(/^(fill-(min|max)|fit|flex(-(width|height))?|stretch)$/) !== -1) {
|
|
@@ -155,7 +149,7 @@ import { CANVAS, WEBGL, AUTO } from "../const.js";
|
|
|
155
149
|
}
|
|
156
150
|
|
|
157
151
|
// override renderer settings if &webgl or &canvas is defined in the URL
|
|
158
|
-
|
|
152
|
+
let uriFragment = utils.getUriFragment();
|
|
159
153
|
if (uriFragment.webgl === true || uriFragment.webgl1 === true || uriFragment.webgl2 === true) {
|
|
160
154
|
this.settings.renderer = WEBGL;
|
|
161
155
|
if (uriFragment.webgl1 === true) {
|
|
@@ -183,14 +177,14 @@ import { CANVAS, WEBGL, AUTO } from "../const.js";
|
|
|
183
177
|
break;
|
|
184
178
|
}
|
|
185
179
|
} else {
|
|
186
|
-
|
|
180
|
+
let CustomRenderer = this.settings.renderer;
|
|
187
181
|
// a renderer class
|
|
188
182
|
this.renderer = new CustomRenderer(this.settings);
|
|
189
183
|
}
|
|
190
184
|
|
|
191
185
|
// register to the channel
|
|
192
|
-
event.on(event.WINDOW_ONRESIZE, () =>
|
|
193
|
-
event.on(event.WINDOW_ONORIENTATION_CHANGE, () =>
|
|
186
|
+
event.on(event.WINDOW_ONRESIZE, () => onresize(this), this);
|
|
187
|
+
event.on(event.WINDOW_ONORIENTATION_CHANGE, () => onresize(this), this);
|
|
194
188
|
|
|
195
189
|
// add our canvas (default to document.body if settings.parent is undefined)
|
|
196
190
|
this.parentElement = device.getElement(this.settings.parent);
|
|
@@ -208,7 +202,7 @@ import { CANVAS, WEBGL, AUTO } from "../const.js";
|
|
|
208
202
|
// add an observer to detect when the dom tree is modified
|
|
209
203
|
if ("MutationObserver" in globalThis) {
|
|
210
204
|
// Create an observer instance linked to the callback function
|
|
211
|
-
|
|
205
|
+
let observer = new MutationObserver(() => onresize(this));
|
|
212
206
|
|
|
213
207
|
// Start observing the target node for configured mutations
|
|
214
208
|
observer.observe(this.parentElement, {
|
|
@@ -221,10 +215,13 @@ import { CANVAS, WEBGL, AUTO } from "../const.js";
|
|
|
221
215
|
}
|
|
222
216
|
|
|
223
217
|
// create a new physic world
|
|
224
|
-
this.world = new World();
|
|
218
|
+
this.world = new World(0, 0, this.settings.width, this.settings.height);
|
|
225
219
|
// set the reference to this application instance
|
|
226
220
|
this.world.app = this;
|
|
221
|
+
// app starting time
|
|
227
222
|
this.lastUpdate = globalThis.performance.now();
|
|
223
|
+
// manually sort child if depthTest setting is "sorting"
|
|
224
|
+
this.world.autoSort = !(this.renderer.type === "WEBGL" && this.settings.depthTest === "z-buffer");
|
|
228
225
|
|
|
229
226
|
this.isInitialized = true;
|
|
230
227
|
|
|
@@ -237,7 +234,7 @@ import { CANVAS, WEBGL, AUTO } from "../const.js";
|
|
|
237
234
|
*/
|
|
238
235
|
reset() {
|
|
239
236
|
// point to the current active stage "default" camera
|
|
240
|
-
|
|
237
|
+
let current = state.get();
|
|
241
238
|
if (typeof current !== "undefined") {
|
|
242
239
|
this.viewport = current.cameras.get("default");
|
|
243
240
|
}
|
|
@@ -249,6 +246,19 @@ import { CANVAS, WEBGL, AUTO } from "../const.js";
|
|
|
249
246
|
this.updateFrameRate();
|
|
250
247
|
}
|
|
251
248
|
|
|
249
|
+
/**
|
|
250
|
+
* Specify the property to be used when sorting renderables for this application game world.
|
|
251
|
+
* Accepted values : "x", "y", "z", "depth"
|
|
252
|
+
* @type {string}
|
|
253
|
+
* @see World.sortOn
|
|
254
|
+
*/
|
|
255
|
+
get sortOn() {
|
|
256
|
+
return this.world.sortOn;
|
|
257
|
+
}
|
|
258
|
+
set sortOn(value) {
|
|
259
|
+
this.world.sortOn = value;
|
|
260
|
+
}
|
|
261
|
+
|
|
252
262
|
/**
|
|
253
263
|
* Fired when a level is fully loaded and all renderable instantiated. <br>
|
|
254
264
|
* Additionnaly the level id will also be passed to the called function.
|
|
@@ -5,13 +5,14 @@ import * as device from "../system/device";
|
|
|
5
5
|
* @param {Application} game - the game application instance calling this function
|
|
6
6
|
*/
|
|
7
7
|
export function consoleHeader(app) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
let renderType = app.renderer.type;
|
|
9
|
+
let gpu_renderer = (typeof app.renderer.GPURenderer === "string") ? " (" + app.renderer.GPURenderer + ")" : "";
|
|
10
|
+
let depthTesting = renderType.includes("WebGL") && app.renderer.depthTest === "z-buffer" ? "Depth Test | " : "";
|
|
11
|
+
let audioType = device.hasWebAudio ? "Web Audio" : "HTML5 Audio";
|
|
11
12
|
|
|
12
13
|
// output video information in the console
|
|
13
14
|
console.log(
|
|
14
|
-
renderType + " renderer" + gpu_renderer + " | " +
|
|
15
|
+
renderType + " renderer" + gpu_renderer + " | " + depthTesting +
|
|
15
16
|
audioType + " | " +
|
|
16
17
|
"pixel ratio " + device.devicePixelRatio + " | " +
|
|
17
18
|
(device.platform.nodeJS ? "node.js" : device.platform.isMobile ? "mobile" : "desktop") + " | " +
|
|
@@ -10,14 +10,14 @@ import * as device from "./../system/device";
|
|
|
10
10
|
* @param {number} y - y scaling multiplier
|
|
11
11
|
*/
|
|
12
12
|
function scale(game, x, y) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
let renderer = game.renderer;
|
|
14
|
+
let canvas = renderer.getCanvas();
|
|
15
|
+
let context = renderer.getContext();
|
|
16
|
+
let settings = renderer.settings;
|
|
17
|
+
let pixelRatio = device.devicePixelRatio;
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
let w = settings.zoomX = canvas.width * x * pixelRatio;
|
|
20
|
+
let h = settings.zoomY = canvas.height * y * pixelRatio;
|
|
21
21
|
|
|
22
22
|
// update the global scale variable
|
|
23
23
|
renderer.scaleRatio.set(x * pixelRatio, y * pixelRatio);
|
|
@@ -40,37 +40,37 @@ function scale(game, x, y) {
|
|
|
40
40
|
* @param {Application} game - the game application instance triggering the resize
|
|
41
41
|
*/
|
|
42
42
|
export function onresize(game) {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
43
|
+
let renderer = game.renderer;
|
|
44
|
+
let settings = renderer.settings;
|
|
45
|
+
let scaleX = 1, scaleY = 1;
|
|
46
46
|
|
|
47
47
|
if (settings.autoScale) {
|
|
48
48
|
|
|
49
49
|
// set max the canvas max size if CSS values are defined
|
|
50
|
-
|
|
51
|
-
|
|
50
|
+
let canvasMaxWidth = Infinity;
|
|
51
|
+
let canvasMaxHeight = Infinity;
|
|
52
52
|
|
|
53
53
|
if (globalThis.getComputedStyle) {
|
|
54
|
-
|
|
54
|
+
let style = globalThis.getComputedStyle(renderer.getCanvas(), null);
|
|
55
55
|
canvasMaxWidth = parseInt(style.maxWidth, 10) || Infinity;
|
|
56
56
|
canvasMaxHeight = parseInt(style.maxHeight, 10) || Infinity;
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
// get the maximum canvas size within the parent div containing the canvas container
|
|
60
|
-
|
|
60
|
+
let nodeBounds = device.getParentBounds(game.getParentElement());
|
|
61
61
|
|
|
62
|
-
|
|
63
|
-
|
|
62
|
+
let _max_width = Math.min(canvasMaxWidth, nodeBounds.width);
|
|
63
|
+
let _max_height = Math.min(canvasMaxHeight, nodeBounds.height);
|
|
64
64
|
|
|
65
65
|
// calculate final canvas width & height
|
|
66
|
-
|
|
66
|
+
let screenRatio = _max_width / _max_height;
|
|
67
67
|
|
|
68
68
|
if ((settings.scaleMethod === "fill-min" && screenRatio > renderer.designRatio) ||
|
|
69
69
|
(settings.scaleMethod === "fill-max" && screenRatio < renderer.designRatio) ||
|
|
70
70
|
(settings.scaleMethod === "flex-width")
|
|
71
71
|
) {
|
|
72
72
|
// resize the display canvas to fill the parent container
|
|
73
|
-
|
|
73
|
+
let sWidth = Math.min(canvasMaxWidth, settings.height * screenRatio);
|
|
74
74
|
scaleX = scaleY = _max_width / sWidth;
|
|
75
75
|
renderer.resize(Math.floor(sWidth), settings.height);
|
|
76
76
|
}
|
|
@@ -79,7 +79,7 @@ export function onresize(game) {
|
|
|
79
79
|
(settings.scaleMethod === "flex-height")
|
|
80
80
|
) {
|
|
81
81
|
// resize the display canvas to fill the parent container
|
|
82
|
-
|
|
82
|
+
let sHeight = Math.min(canvasMaxHeight, settings.width * (_max_height / _max_width));
|
|
83
83
|
scaleX = scaleY = _max_height / sHeight;
|
|
84
84
|
renderer.resize(settings.width, Math.floor(sHeight));
|
|
85
85
|
}
|
package/src/audio/audio.js
CHANGED
|
@@ -40,7 +40,7 @@ let soundLoadError = function (sound_name, onerror_cb) {
|
|
|
40
40
|
// check the retry counter
|
|
41
41
|
if (retry_counter++ > 3) {
|
|
42
42
|
// something went wrong
|
|
43
|
-
|
|
43
|
+
let errmsg = "melonJS: failed loading " + sound_name;
|
|
44
44
|
if (stopOnAudioError === false) {
|
|
45
45
|
// disable audio
|
|
46
46
|
disable();
|
|
@@ -146,14 +146,14 @@ export function disable() {
|
|
|
146
146
|
* @ignore
|
|
147
147
|
*/
|
|
148
148
|
export function load(sound, html5, onload_cb, onerror_cb) {
|
|
149
|
-
|
|
149
|
+
let urls = [];
|
|
150
150
|
if (audioExts.length === 0) {
|
|
151
151
|
throw new Error("target audio extension(s) should be set through me.audio.init() before calling the preloader.");
|
|
152
152
|
}
|
|
153
153
|
if (isDataUrl(sound.src) === true) {
|
|
154
154
|
urls.push(sound.src);
|
|
155
155
|
} else {
|
|
156
|
-
for (
|
|
156
|
+
for (let i = 0; i < audioExts.length; i++) {
|
|
157
157
|
urls.push(sound.src + sound.name + "." + audioExts[i] + nocache);
|
|
158
158
|
}
|
|
159
159
|
}
|
|
@@ -202,9 +202,9 @@ export function load(sound, html5, onload_cb, onerror_cb) {
|
|
|
202
202
|
* me.audio.play("gameover_sfx", false, null, 0.5);
|
|
203
203
|
*/
|
|
204
204
|
export function play(sound_name, loop = false, onend, volume) {
|
|
205
|
-
|
|
205
|
+
let sound = audioTracks[sound_name];
|
|
206
206
|
if (sound && typeof sound !== "undefined") {
|
|
207
|
-
|
|
207
|
+
let id = sound.play();
|
|
208
208
|
if (typeof loop === "boolean") {
|
|
209
209
|
// arg[0] can take different types in howler 2.0
|
|
210
210
|
sound.loop(loop, id);
|
|
@@ -234,7 +234,7 @@ export function play(sound_name, loop = false, onend, volume) {
|
|
|
234
234
|
* @param {number} [id] - the sound instance ID. If none is passed, all sounds in group will fade.
|
|
235
235
|
*/
|
|
236
236
|
export function fade(sound_name, from, to, duration, id) {
|
|
237
|
-
|
|
237
|
+
let sound = audioTracks[sound_name];
|
|
238
238
|
if (sound && typeof sound !== "undefined") {
|
|
239
239
|
sound.fade(from, to, duration, id);
|
|
240
240
|
} else {
|
|
@@ -251,12 +251,12 @@ export function fade(sound_name, from, to, duration, id) {
|
|
|
251
251
|
* @returns {number} return the current seek position (if no extra parameters were given)
|
|
252
252
|
* @example
|
|
253
253
|
* // return the current position of the background music
|
|
254
|
-
*
|
|
254
|
+
* let current_pos = me.audio.seek("dst-gameforest");
|
|
255
255
|
* // set back the position of the background music to the beginning
|
|
256
256
|
* me.audio.seek("dst-gameforest", 0);
|
|
257
257
|
*/
|
|
258
258
|
export function seek(sound_name, ...args) {
|
|
259
|
-
|
|
259
|
+
let sound = audioTracks[sound_name];
|
|
260
260
|
if (sound && typeof sound !== "undefined") {
|
|
261
261
|
return sound.seek(...args);
|
|
262
262
|
} else {
|
|
@@ -273,12 +273,12 @@ export function seek(sound_name, ...args) {
|
|
|
273
273
|
* @returns {number} return the current playback rate (if no extra parameters were given)
|
|
274
274
|
* @example
|
|
275
275
|
* // get the playback rate of the background music
|
|
276
|
-
*
|
|
276
|
+
* let rate = me.audio.rate("dst-gameforest");
|
|
277
277
|
* // speed up the playback of the background music
|
|
278
278
|
* me.audio.rate("dst-gameforest", 2.0);
|
|
279
279
|
*/
|
|
280
280
|
export function rate(sound_name, ...args) {
|
|
281
|
-
|
|
281
|
+
let sound = audioTracks[sound_name];
|
|
282
282
|
if (sound && typeof sound !== "undefined") {
|
|
283
283
|
return sound.rate(...args);
|
|
284
284
|
} else {
|
|
@@ -296,7 +296,7 @@ export function rate(sound_name, ...args) {
|
|
|
296
296
|
*/
|
|
297
297
|
export function stop(sound_name, id) {
|
|
298
298
|
if (typeof sound_name !== "undefined") {
|
|
299
|
-
|
|
299
|
+
let sound = audioTracks[sound_name];
|
|
300
300
|
if (sound && typeof sound !== "undefined") {
|
|
301
301
|
sound.stop(id);
|
|
302
302
|
// remove the defined onend callback (if any defined)
|
|
@@ -319,7 +319,7 @@ export function stop(sound_name, id) {
|
|
|
319
319
|
* me.audio.pause("cling");
|
|
320
320
|
*/
|
|
321
321
|
export function pause(sound_name, id) {
|
|
322
|
-
|
|
322
|
+
let sound = audioTracks[sound_name];
|
|
323
323
|
if (sound && typeof sound !== "undefined") {
|
|
324
324
|
sound.pause(id);
|
|
325
325
|
} else {
|
|
@@ -334,7 +334,7 @@ export function pause(sound_name, id) {
|
|
|
334
334
|
* @param {number} [id] - the sound instance ID. If none is passed, all sounds in group will resume.
|
|
335
335
|
* @example
|
|
336
336
|
* // play a audio clip
|
|
337
|
-
*
|
|
337
|
+
* let id = me.audio.play("myClip");
|
|
338
338
|
* ...
|
|
339
339
|
* // pause it
|
|
340
340
|
* me.audio.pause("myClip", id);
|
|
@@ -343,7 +343,7 @@ export function pause(sound_name, id) {
|
|
|
343
343
|
* me.audio.resume("myClip", id);
|
|
344
344
|
*/
|
|
345
345
|
export function resume(sound_name, id) {
|
|
346
|
-
|
|
346
|
+
let sound = audioTracks[sound_name];
|
|
347
347
|
if (sound && typeof sound !== "undefined") {
|
|
348
348
|
sound.play(id);
|
|
349
349
|
} else {
|
|
@@ -455,10 +455,8 @@ export function getVolume() {
|
|
|
455
455
|
* // mute the background music
|
|
456
456
|
* me.audio.mute("awesome_music");
|
|
457
457
|
*/
|
|
458
|
-
export function mute(sound_name, id, mute) {
|
|
459
|
-
|
|
460
|
-
mute = (typeof(mute) === "undefined" ? true : !!mute);
|
|
461
|
-
var sound = audioTracks[sound_name];
|
|
458
|
+
export function mute(sound_name, id, mute = true) {
|
|
459
|
+
let sound = audioTracks[sound_name];
|
|
462
460
|
if (sound && typeof(sound) !== "undefined") {
|
|
463
461
|
sound.mute(mute, id);
|
|
464
462
|
} else {
|
|
@@ -527,7 +525,7 @@ export function unload(sound_name) {
|
|
|
527
525
|
* me.audio.unloadAll();
|
|
528
526
|
*/
|
|
529
527
|
export function unloadAll() {
|
|
530
|
-
for (
|
|
528
|
+
for (let sound_name in audioTracks) {
|
|
531
529
|
if (audioTracks.hasOwnProperty(sound_name)) {
|
|
532
530
|
unload(sound_name);
|
|
533
531
|
}
|
package/src/camera/camera2d.js
CHANGED
|
@@ -16,7 +16,7 @@ import { game } from "../index.js";
|
|
|
16
16
|
// some ref shortcut
|
|
17
17
|
const MIN = Math.min, MAX = Math.max;
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
let targetV = new Vector2d();
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
22
|
* @classdesc
|
|
@@ -178,7 +178,7 @@ var targetV = new Vector2d();
|
|
|
178
178
|
|
|
179
179
|
/** @ignore */
|
|
180
180
|
_followH(target) {
|
|
181
|
-
|
|
181
|
+
let targetX = this.pos.x;
|
|
182
182
|
if ((target.x - this.pos.x) > (this.deadzone.right)) {
|
|
183
183
|
targetX = MIN((target.x) - (this.deadzone.right), this.bounds.width - this.width);
|
|
184
184
|
}
|
|
@@ -191,7 +191,7 @@ var targetV = new Vector2d();
|
|
|
191
191
|
|
|
192
192
|
/** @ignore */
|
|
193
193
|
_followV(target) {
|
|
194
|
-
|
|
194
|
+
let targetY = this.pos.y;
|
|
195
195
|
if ((target.y - this.pos.y) > (this.deadzone.bottom)) {
|
|
196
196
|
targetY = MIN((target.y) - (this.deadzone.bottom), this.bounds.height - this.height);
|
|
197
197
|
}
|
|
@@ -384,8 +384,8 @@ var targetV = new Vector2d();
|
|
|
384
384
|
* @param {number} y
|
|
385
385
|
*/
|
|
386
386
|
moveTo(x, y) {
|
|
387
|
-
|
|
388
|
-
|
|
387
|
+
let _x = this.pos.x;
|
|
388
|
+
let _y = this.pos.y;
|
|
389
389
|
|
|
390
390
|
this.pos.x = clamp(
|
|
391
391
|
x,
|
|
@@ -561,7 +561,7 @@ var targetV = new Vector2d();
|
|
|
561
561
|
*/
|
|
562
562
|
fadeIn(color, duration = 1000, onComplete) {
|
|
563
563
|
this._fadeIn.color = pool.pull("Color").copy(color);
|
|
564
|
-
|
|
564
|
+
let _alpha = this._fadeIn.color.alpha;
|
|
565
565
|
this._fadeIn.color.alpha = 0.0;
|
|
566
566
|
this._fadeIn.tween = pool.pull("Tween", this._fadeIn.color)
|
|
567
567
|
.to({ alpha: _alpha }, duration)
|
|
@@ -577,7 +577,7 @@ var targetV = new Vector2d();
|
|
|
577
577
|
* @param {Renderable} target - the renderable to focus the camera on
|
|
578
578
|
*/
|
|
579
579
|
focusOn(target) {
|
|
580
|
-
|
|
580
|
+
let bounds = target.getBounds();
|
|
581
581
|
this.moveTo(
|
|
582
582
|
target.pos.x + bounds.left + (bounds.width / 2),
|
|
583
583
|
target.pos.y + bounds.top + (bounds.height / 2)
|
|
@@ -687,8 +687,8 @@ var targetV = new Vector2d();
|
|
|
687
687
|
* @ignore
|
|
688
688
|
*/
|
|
689
689
|
draw(renderer, container) {
|
|
690
|
-
|
|
691
|
-
|
|
690
|
+
let translateX = this.pos.x + this.offset.x;
|
|
691
|
+
let translateY = this.pos.y + this.offset.y;
|
|
692
692
|
|
|
693
693
|
// translate the world coordinates by default to screen coordinates
|
|
694
694
|
container.currentTransform.translate(-translateX, -translateY);
|
package/src/entity/entity.js
CHANGED
|
@@ -108,7 +108,7 @@ import Body from "./../physics/body.js";
|
|
|
108
108
|
pool.pull("Vector2d", 0, this.height)
|
|
109
109
|
]);
|
|
110
110
|
}
|
|
111
|
-
this.body = new Body(this, settings.shapes, this.onBodyUpdate
|
|
111
|
+
this.body = new Body(this, settings.shapes, () => this.onBodyUpdate());
|
|
112
112
|
|
|
113
113
|
// resize the entity if required
|
|
114
114
|
if (this.width === 0 && this.height === 0) {
|
|
@@ -160,7 +160,7 @@ import Body from "./../physics/body.js";
|
|
|
160
160
|
* @returns {Bounds} this entity bounding box Rectangle object
|
|
161
161
|
*/
|
|
162
162
|
updateBounds(absolute = true) {
|
|
163
|
-
|
|
163
|
+
let bounds = this.getBounds();
|
|
164
164
|
|
|
165
165
|
bounds.clear();
|
|
166
166
|
bounds.addFrame(
|
|
@@ -230,7 +230,7 @@ import Body from "./../physics/body.js";
|
|
|
230
230
|
* @param {Camera2d} [viewport] - the viewport to (re)draw
|
|
231
231
|
*/
|
|
232
232
|
draw(renderer, viewport) {
|
|
233
|
-
|
|
233
|
+
let renderable = this.renderable;
|
|
234
234
|
if (renderable instanceof Renderable) {
|
|
235
235
|
// predraw (apply transforms)
|
|
236
236
|
renderable.preDraw(renderer);
|
|
@@ -84,14 +84,14 @@ import pool from "./../system/pooling.js";
|
|
|
84
84
|
* @returns {Ellipse} this instance for objecf chaining
|
|
85
85
|
*/
|
|
86
86
|
setShape(x, y, w, h) {
|
|
87
|
-
|
|
88
|
-
|
|
87
|
+
const hW = w / 2;
|
|
88
|
+
const hH = h / 2;
|
|
89
89
|
|
|
90
90
|
this.pos.set(x, y);
|
|
91
91
|
this.radius = Math.max(hW, hH);
|
|
92
92
|
this.ratio.set(hW / this.radius, hH / this.radius);
|
|
93
93
|
this.radiusV.set(this.radius, this.radius).scaleV(this.ratio);
|
|
94
|
-
|
|
94
|
+
const r = this.radius * this.radius;
|
|
95
95
|
this.radiusSq.set(r, r).scaleV(this.ratio);
|
|
96
96
|
|
|
97
97
|
// update the corresponding bounds
|
|
@@ -175,7 +175,7 @@ import pool from "./../system/pooling.js";
|
|
|
175
175
|
* @returns {Ellipse} this ellipse
|
|
176
176
|
*/
|
|
177
177
|
translate() {
|
|
178
|
-
|
|
178
|
+
let _x, _y;
|
|
179
179
|
|
|
180
180
|
if (arguments.length === 2) {
|
|
181
181
|
// x, y
|
|
@@ -212,7 +212,7 @@ import pool from "./../system/pooling.js";
|
|
|
212
212
|
* @returns {boolean} true if contains
|
|
213
213
|
*/
|
|
214
214
|
contains() {
|
|
215
|
-
|
|
215
|
+
let _x, _y;
|
|
216
216
|
|
|
217
217
|
if (arguments.length === 2) {
|
|
218
218
|
// x, y
|
package/src/geometries/line.js
CHANGED
|
@@ -30,7 +30,7 @@ import Polygon from "./poly.js";
|
|
|
30
30
|
* @returns {boolean} true if contains
|
|
31
31
|
*/
|
|
32
32
|
contains() {
|
|
33
|
-
|
|
33
|
+
let _x, _y;
|
|
34
34
|
|
|
35
35
|
if (arguments.length === 2) {
|
|
36
36
|
// x, y
|
|
@@ -46,8 +46,8 @@ import Polygon from "./poly.js";
|
|
|
46
46
|
// rather than creating temp translated vectors
|
|
47
47
|
_x -= this.pos.x; // Cx
|
|
48
48
|
_y -= this.pos.y; // Cy
|
|
49
|
-
|
|
50
|
-
|
|
49
|
+
let start = this.points[0]; // Ax/Ay
|
|
50
|
+
let end = this.points[1]; // Bx/By
|
|
51
51
|
|
|
52
52
|
//(Cy - Ay) * (Bx - Ax) = (By - Ay) * (Cx - Ax)
|
|
53
53
|
return (_y - start.y) * (end.x - start.x) === (end.y - start.y) * (_x - start.x);
|
|
@@ -61,12 +61,12 @@ import Polygon from "./poly.js";
|
|
|
61
61
|
* @returns {Line} this instance for objecf chaining
|
|
62
62
|
*/
|
|
63
63
|
recalc() {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
64
|
+
let edges = this.edges;
|
|
65
|
+
let normals = this.normals;
|
|
66
|
+
let indices = this.indices;
|
|
67
67
|
|
|
68
68
|
// Copy the original points array and apply the offset/angle
|
|
69
|
-
|
|
69
|
+
let points = this.points;
|
|
70
70
|
|
|
71
71
|
if (points.length !== 2) {
|
|
72
72
|
throw new Error("Requires exactly 2 points");
|
|
@@ -96,7 +96,7 @@ import Polygon from "./poly.js";
|
|
|
96
96
|
* @returns {Line} new Line
|
|
97
97
|
*/
|
|
98
98
|
clone() {
|
|
99
|
-
|
|
99
|
+
let copy = [];
|
|
100
100
|
this.points.forEach((point) => {
|
|
101
101
|
copy.push(point.clone());
|
|
102
102
|
});
|