melonjs 15.2.1 → 15.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.
- package/README.md +1 -1
- package/dist/melonjs.mjs/_virtual/_commonjsHelpers.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 +1 -1
- package/dist/melonjs.mjs/application/application.js +75 -23
- package/dist/melonjs.mjs/application/header.js +2 -2
- package/dist/melonjs.mjs/application/resize.js +13 -11
- package/dist/melonjs.mjs/application/settings.js +37 -1
- package/dist/melonjs.mjs/audio/audio.js +4 -6
- package/dist/melonjs.mjs/camera/camera2d.js +12 -14
- package/dist/melonjs.mjs/const.js +1 -1
- package/dist/melonjs.mjs/entity/entity.js +3 -4
- package/dist/melonjs.mjs/geometries/ellipse.js +26 -59
- package/dist/melonjs.mjs/geometries/line.js +18 -25
- package/dist/melonjs.mjs/geometries/path2d.js +16 -13
- package/dist/melonjs.mjs/geometries/point.js +8 -16
- package/dist/melonjs.mjs/geometries/poly.js +40 -97
- package/dist/melonjs.mjs/geometries/rectangle.js +37 -91
- package/dist/melonjs.mjs/geometries/roundrect.js +26 -35
- package/dist/melonjs.mjs/index.js +6 -6
- package/dist/melonjs.mjs/input/gamepad.js +1 -1
- package/dist/melonjs.mjs/input/input.js +1 -1
- package/dist/melonjs.mjs/input/keyboard.js +3 -3
- package/dist/melonjs.mjs/input/pointer.js +4 -4
- package/dist/melonjs.mjs/input/pointerevent.js +6 -7
- package/dist/melonjs.mjs/lang/console.js +1 -1
- package/dist/melonjs.mjs/lang/deprecated.js +2 -2
- package/dist/melonjs.mjs/level/level.js +1 -1
- package/dist/melonjs.mjs/level/tiled/TMXGroup.js +1 -1
- package/dist/melonjs.mjs/level/tiled/TMXLayer.js +16 -33
- package/dist/melonjs.mjs/level/tiled/TMXObject.js +3 -4
- package/dist/melonjs.mjs/level/tiled/TMXTile.js +4 -4
- package/dist/melonjs.mjs/level/tiled/TMXTileMap.js +3 -3
- package/dist/melonjs.mjs/level/tiled/TMXTileset.js +4 -7
- package/dist/melonjs.mjs/level/tiled/TMXTilesetGroup.js +2 -2
- package/dist/melonjs.mjs/level/tiled/TMXUtils.js +37 -47
- package/dist/melonjs.mjs/level/tiled/constants.js +1 -1
- package/dist/melonjs.mjs/level/tiled/renderer/TMXHexagonalRenderer.js +3 -3
- package/dist/melonjs.mjs/level/tiled/renderer/TMXIsometricRenderer.js +2 -2
- package/dist/melonjs.mjs/level/tiled/renderer/TMXOrthogonalRenderer.js +2 -2
- package/dist/melonjs.mjs/level/tiled/renderer/TMXRenderer.js +2 -2
- package/dist/melonjs.mjs/level/tiled/renderer/TMXStaggeredRenderer.js +2 -2
- 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 +1 -1
- package/dist/melonjs.mjs/loader/loadingscreen.js +1 -1
- package/dist/melonjs.mjs/loader/melonjs_logo.png.js +1 -1
- package/dist/melonjs.mjs/loader/parser.js +4 -5
- package/dist/melonjs.mjs/loader/settings.js +1 -1
- package/dist/melonjs.mjs/math/color.js +5 -5
- package/dist/melonjs.mjs/math/math.js +1 -1
- package/dist/melonjs.mjs/math/matrix2.js +5 -59
- package/dist/melonjs.mjs/math/matrix3.js +82 -141
- package/dist/melonjs.mjs/math/observable_vector2.js +7 -7
- package/dist/melonjs.mjs/math/observable_vector3.js +5 -5
- package/dist/melonjs.mjs/math/vector2.js +7 -91
- package/dist/melonjs.mjs/math/vector3.js +6 -90
- package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/esm/arraymultimap.js +1 -1
- package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/esm/multimap.js +1 -1
- package/dist/melonjs.mjs/node_modules/earcut/src/earcut.js +1 -1
- package/dist/melonjs.mjs/node_modules/eventemitter3/index.js +1 -1
- 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 +2 -2
- package/dist/melonjs.mjs/particles/particle.js +2 -2
- package/dist/melonjs.mjs/particles/settings.js +1 -1
- package/dist/melonjs.mjs/physics/body.js +22 -20
- package/dist/melonjs.mjs/physics/bounds.js +27 -33
- package/dist/melonjs.mjs/physics/collision.js +5 -5
- package/dist/melonjs.mjs/physics/detector.js +10 -10
- package/dist/melonjs.mjs/physics/quadtree.js +5 -5
- package/dist/melonjs.mjs/physics/response.js +1 -1
- package/dist/melonjs.mjs/physics/sat.js +3 -4
- package/dist/melonjs.mjs/physics/world.js +6 -9
- package/dist/melonjs.mjs/plugin/plugin.js +3 -3
- package/dist/melonjs.mjs/renderable/collectable.js +2 -2
- package/dist/melonjs.mjs/renderable/colorlayer.js +4 -4
- package/dist/melonjs.mjs/renderable/container.js +25 -25
- package/dist/melonjs.mjs/renderable/draggable.js +1 -1
- package/dist/melonjs.mjs/renderable/dragndrop.js +1 -1
- package/dist/melonjs.mjs/renderable/imagelayer.js +4 -4
- package/dist/melonjs.mjs/renderable/light2d.js +3 -3
- package/dist/melonjs.mjs/renderable/nineslicesprite.js +2 -2
- package/dist/melonjs.mjs/renderable/renderable.js +31 -39
- package/dist/melonjs.mjs/renderable/sprite.js +3 -3
- package/dist/melonjs.mjs/renderable/text/bitmaptext.js +421 -0
- package/dist/melonjs.mjs/renderable/text/bitmaptextdata.js +195 -0
- package/dist/melonjs.mjs/renderable/text/glyph.js +65 -0
- package/dist/melonjs.mjs/renderable/text/text.js +422 -0
- package/dist/melonjs.mjs/renderable/text/textmetrics.js +175 -0
- package/dist/melonjs.mjs/renderable/text/textstyle.js +21 -0
- package/dist/melonjs.mjs/renderable/trigger.js +10 -10
- package/dist/melonjs.mjs/renderable/ui/uibaseelement.js +7 -7
- package/dist/melonjs.mjs/renderable/ui/uispriteelement.js +7 -7
- package/dist/melonjs.mjs/renderable/ui/uitextbutton.js +3 -3
- package/dist/melonjs.mjs/state/stage.js +13 -14
- package/dist/melonjs.mjs/state/state.js +4 -51
- package/dist/melonjs.mjs/system/device.js +51 -10
- package/dist/melonjs.mjs/system/dom.js +1 -1
- package/dist/melonjs.mjs/system/event.js +46 -2
- package/dist/melonjs.mjs/system/platform.js +18 -18
- package/dist/melonjs.mjs/system/pooling.js +10 -10
- package/dist/melonjs.mjs/system/save.js +1 -1
- package/dist/melonjs.mjs/system/timer.js +1 -1
- package/dist/melonjs.mjs/text/bitmaptext.js +1 -1
- package/dist/melonjs.mjs/text/bitmaptextdata.js +3 -6
- package/dist/melonjs.mjs/text/glyph.js +1 -1
- package/dist/melonjs.mjs/text/text.js +1 -1
- package/dist/melonjs.mjs/text/textmetrics.js +1 -1
- package/dist/melonjs.mjs/text/textstyle.js +1 -1
- package/dist/melonjs.mjs/tweens/easing.js +1 -1
- package/dist/melonjs.mjs/tweens/interpolation.js +1 -1
- package/dist/melonjs.mjs/tweens/tween.js +2 -2
- package/dist/melonjs.mjs/utils/agent.js +1 -1
- package/dist/melonjs.mjs/utils/array.js +1 -1
- package/dist/melonjs.mjs/utils/file.js +1 -1
- package/dist/melonjs.mjs/utils/function.js +2 -3
- package/dist/melonjs.mjs/utils/string.js +1 -1
- package/dist/melonjs.mjs/utils/utils.js +1 -1
- package/dist/melonjs.mjs/video/canvas/canvas_renderer.js +5 -18
- package/dist/melonjs.mjs/video/renderer.js +17 -30
- package/dist/melonjs.mjs/video/texture/atlas.js +13 -13
- package/dist/melonjs.mjs/video/texture/cache.js +1 -1
- package/dist/melonjs.mjs/video/texture/canvas_texture.js +15 -15
- package/dist/melonjs.mjs/video/utils/autodetect.js +1 -1
- package/dist/melonjs.mjs/video/video.js +5 -29
- package/dist/melonjs.mjs/video/webgl/buffer/vertex.js +3 -3
- package/dist/melonjs.mjs/video/webgl/compositors/compositor.js +13 -14
- package/dist/melonjs.mjs/video/webgl/compositors/primitive_compositor.js +5 -5
- package/dist/melonjs.mjs/video/webgl/compositors/quad_compositor.js +2 -3
- package/dist/melonjs.mjs/video/webgl/glshader.js +2 -2
- 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 +1 -1
- package/dist/melonjs.mjs/video/webgl/utils/precision.js +4 -4
- package/dist/melonjs.mjs/video/webgl/utils/program.js +1 -1
- package/dist/melonjs.mjs/video/webgl/utils/string.js +1 -1
- package/dist/melonjs.mjs/video/webgl/utils/uniforms.js +1 -1
- package/dist/melonjs.mjs/video/webgl/webgl_renderer.js +62 -67
- package/dist/melonjs.module.js +1272 -1713
- package/dist/types/application/application.d.ts +32 -31
- package/dist/types/application/header.d.ts +2 -2
- package/dist/types/application/settings.d.ts +80 -16
- package/dist/types/audio/audio.d.ts +4 -6
- package/dist/types/camera/camera2d.d.ts +13 -16
- package/dist/types/entity/entity.d.ts +0 -1
- package/dist/types/geometries/ellipse.d.ts +18 -50
- package/dist/types/geometries/path2d.d.ts +1 -1
- package/dist/types/geometries/point.d.ts +5 -13
- package/dist/types/geometries/poly.d.ts +26 -75
- package/dist/types/geometries/rectangle.d.ts +12 -58
- package/dist/types/geometries/roundrect.d.ts +2 -11
- package/dist/types/index.d.ts +3 -3
- package/dist/types/input/gamepad.d.ts +31 -31
- package/dist/types/input/keyboard.d.ts +105 -105
- package/dist/types/input/pointer.d.ts +21 -21
- package/dist/types/input/pointerevent.d.ts +6 -6
- package/dist/types/level/tiled/TMXLayer.d.ts +1 -1
- package/dist/types/level/tiled/TMXUtils.d.ts +4 -6
- package/dist/types/math/matrix2.d.ts +9 -63
- package/dist/types/math/matrix3.d.ts +9 -68
- package/dist/types/math/observable_vector2.d.ts +2 -2
- package/dist/types/math/observable_vector3.d.ts +2 -2
- package/dist/types/math/vector2.d.ts +8 -92
- package/dist/types/math/vector3.d.ts +8 -92
- package/dist/types/particles/settings.d.ts +29 -29
- package/dist/types/physics/body.d.ts +10 -8
- package/dist/types/physics/bounds.d.ts +24 -30
- package/dist/types/physics/collision.d.ts +12 -12
- package/dist/types/physics/detector.d.ts +1 -1
- package/dist/types/physics/world.d.ts +4 -7
- package/dist/types/renderable/container.d.ts +19 -19
- package/dist/types/renderable/imagelayer.d.ts +6 -6
- package/dist/types/renderable/light2d.d.ts +7 -7
- package/dist/types/renderable/renderable.d.ts +10 -18
- package/dist/types/renderable/text/bitmaptext.d.ts +151 -0
- package/dist/types/renderable/text/bitmaptextdata.d.ts +35 -0
- package/dist/types/renderable/text/glyph.d.ts +28 -0
- package/dist/types/renderable/text/text.d.ts +159 -0
- package/dist/types/renderable/text/textmetrics.d.ts +47 -0
- package/dist/types/renderable/text/textstyle.d.ts +5 -0
- package/dist/types/renderable/ui/uibaseelement.d.ts +0 -1
- package/dist/types/renderable/ui/uispriteelement.d.ts +0 -1
- package/dist/types/renderable/ui/uitextbutton.d.ts +2 -7
- package/dist/types/state/stage.d.ts +3 -2
- package/dist/types/state/state.d.ts +11 -11
- package/dist/types/system/device.d.ts +16 -9
- package/dist/types/system/event.d.ts +40 -0
- package/dist/types/system/platform.d.ts +17 -17
- package/dist/types/utils/function.d.ts +1 -2
- package/dist/types/video/canvas/canvas_renderer.d.ts +0 -23
- package/dist/types/video/renderer.d.ts +16 -43
- package/dist/types/video/texture/canvas_texture.d.ts +14 -14
- package/dist/types/video/video.d.ts +4 -38
- package/dist/types/video/webgl/buffer/vertex.d.ts +2 -2
- package/dist/types/video/webgl/compositors/compositor.d.ts +24 -13
- package/dist/types/video/webgl/compositors/primitive_compositor.d.ts +0 -1
- package/dist/types/video/webgl/compositors/quad_compositor.d.ts +0 -1
- package/dist/types/video/webgl/utils/precision.d.ts +1 -1
- package/dist/types/video/webgl/webgl_renderer.d.ts +48 -84
- package/package.json +15 -15
- package/src/application/application.js +73 -21
- package/src/application/header.js +1 -1
- package/src/application/resize.js +11 -9
- package/src/application/settings.js +36 -0
- package/src/audio/audio.js +3 -5
- package/src/camera/camera2d.js +11 -13
- package/src/entity/entity.js +2 -3
- package/src/geometries/ellipse.js +25 -58
- package/src/geometries/line.js +17 -24
- package/src/geometries/path2d.js +15 -12
- package/src/geometries/point.js +7 -15
- package/src/geometries/poly.js +39 -96
- package/src/geometries/rectangle.js +36 -90
- package/src/geometries/roundrect.js +25 -34
- package/src/index.js +4 -4
- package/src/input/keyboard.js +2 -2
- package/src/input/pointer.js +3 -3
- package/src/input/pointerevent.js +5 -6
- package/src/lang/deprecated.js +1 -1
- package/src/level/tiled/TMXLayer.js +15 -32
- package/src/level/tiled/TMXObject.js +2 -3
- package/src/level/tiled/TMXTile.js +3 -3
- package/src/level/tiled/TMXTileMap.js +2 -2
- package/src/level/tiled/TMXTileset.js +3 -6
- package/src/level/tiled/TMXTilesetGroup.js +1 -1
- package/src/level/tiled/TMXUtils.js +36 -46
- package/src/level/tiled/renderer/TMXHexagonalRenderer.js +2 -2
- package/src/level/tiled/renderer/TMXIsometricRenderer.js +1 -1
- package/src/level/tiled/renderer/TMXOrthogonalRenderer.js +1 -1
- package/src/level/tiled/renderer/TMXRenderer.js +1 -1
- package/src/level/tiled/renderer/TMXStaggeredRenderer.js +1 -1
- package/src/loader/parser.js +3 -4
- package/src/math/color.js +4 -4
- package/src/math/matrix2.js +4 -58
- package/src/math/matrix3.js +81 -140
- package/src/math/observable_vector2.js +6 -6
- package/src/math/observable_vector3.js +4 -4
- package/src/math/vector2.js +6 -90
- package/src/math/vector3.js +5 -89
- package/src/particles/emitter.js +1 -1
- package/src/particles/particle.js +1 -1
- package/src/physics/body.js +21 -19
- package/src/physics/bounds.js +26 -32
- package/src/physics/collision.js +4 -4
- package/src/physics/detector.js +9 -9
- package/src/physics/quadtree.js +4 -4
- package/src/physics/sat.js +2 -3
- package/src/physics/world.js +5 -8
- package/src/polyfill/roundrect.js +163 -163
- package/src/renderable/collectable.js +1 -1
- package/src/renderable/colorlayer.js +3 -3
- package/src/renderable/container.js +24 -24
- package/src/renderable/imagelayer.js +3 -3
- package/src/renderable/light2d.js +2 -2
- package/src/renderable/nineslicesprite.js +1 -1
- package/src/renderable/renderable.js +30 -38
- package/src/renderable/sprite.js +2 -2
- package/src/{text → renderable/text}/bitmaptext.js +8 -8
- package/src/{text → renderable/text}/bitmaptextdata.js +4 -7
- package/src/{text → renderable/text}/glyph.js +1 -1
- package/src/{text → renderable/text}/text.js +16 -17
- package/src/{text → renderable/text}/textmetrics.js +2 -2
- package/src/renderable/trigger.js +9 -9
- package/src/renderable/ui/uibaseelement.js +6 -6
- package/src/renderable/ui/uispriteelement.js +6 -6
- package/src/renderable/ui/uitextbutton.js +2 -2
- package/src/state/stage.js +12 -13
- package/src/state/state.js +2 -61
- package/src/system/device.js +50 -9
- package/src/system/event.js +44 -0
- package/src/system/platform.js +18 -18
- package/src/system/pooling.js +9 -9
- package/src/tweens/tween.js +1 -1
- package/src/utils/function.js +1 -2
- package/src/video/canvas/canvas_renderer.js +4 -17
- package/src/video/renderer.js +16 -29
- package/src/video/texture/atlas.js +12 -12
- package/src/video/texture/canvas_texture.js +14 -14
- package/src/video/video.js +7 -28
- package/src/video/webgl/buffer/vertex.js +2 -2
- package/src/video/webgl/compositors/compositor.js +12 -13
- package/src/video/webgl/compositors/primitive_compositor.js +4 -4
- package/src/video/webgl/compositors/quad_compositor.js +1 -2
- package/src/video/webgl/glshader.js +1 -1
- package/src/video/webgl/utils/precision.js +3 -3
- package/src/video/webgl/webgl_renderer.js +61 -66
- /package/src/{text → renderable/text}/textstyle.js +0 -0
package/src/camera/camera2d.js
CHANGED
|
@@ -23,7 +23,7 @@ let targetV = new Vector2d();
|
|
|
23
23
|
* a 2D orthographic camera
|
|
24
24
|
* @augments Renderable
|
|
25
25
|
*/
|
|
26
|
-
|
|
26
|
+
export default class Camera2d extends Renderable {
|
|
27
27
|
/**
|
|
28
28
|
* @param {number} minX - start x offset
|
|
29
29
|
* @param {number} minY - start y offset
|
|
@@ -207,8 +207,8 @@ let targetV = new Vector2d();
|
|
|
207
207
|
* reset the camera position to specified coordinates
|
|
208
208
|
* @name reset
|
|
209
209
|
* @memberof Camera2d
|
|
210
|
-
* @param {number} [x=0]
|
|
211
|
-
* @param {number} [y=0]
|
|
210
|
+
* @param {number} [x=0] - initial position of the camera on the x axis
|
|
211
|
+
* @param {number} [y=0] - initial position of the camera on the y axis
|
|
212
212
|
*/
|
|
213
213
|
reset(x = 0, y = 0) {
|
|
214
214
|
// reset the initial camera position to 0,0
|
|
@@ -365,8 +365,8 @@ let targetV = new Vector2d();
|
|
|
365
365
|
* @name move
|
|
366
366
|
* @memberof Camera2d
|
|
367
367
|
* @see Camera2d.focusOn
|
|
368
|
-
* @param {number} x
|
|
369
|
-
* @param {number} y
|
|
368
|
+
* @param {number} x - horizontal offset
|
|
369
|
+
* @param {number} y - vertical offset
|
|
370
370
|
* @example
|
|
371
371
|
* // Move the camera up by four pixels
|
|
372
372
|
* me.game.viewport.move(0, -4);
|
|
@@ -590,7 +590,7 @@ let targetV = new Vector2d();
|
|
|
590
590
|
* @memberof Camera2d
|
|
591
591
|
* @param {Renderable|Entity|Sprite|NineSliceSprite} obj - to be checked against
|
|
592
592
|
* @param {boolean} [floating = obj.floating] - if visibility check should be done against screen coordinates
|
|
593
|
-
* @returns {boolean}
|
|
593
|
+
* @returns {boolean} true if within the viewport
|
|
594
594
|
*/
|
|
595
595
|
isVisible(obj, floating = obj.floating) {
|
|
596
596
|
if (floating === true || obj.floating === true) {
|
|
@@ -606,10 +606,9 @@ let targetV = new Vector2d();
|
|
|
606
606
|
* convert the given "local" (screen) coordinates into world coordinates
|
|
607
607
|
* @name localToWorld
|
|
608
608
|
* @memberof Camera2d
|
|
609
|
-
* @param {number} x
|
|
610
|
-
* @param {number} y
|
|
611
|
-
* @param {number} [v] - an optional vector object where to set the
|
|
612
|
-
* converted value
|
|
609
|
+
* @param {number} x - the x coordinate of the local point to be converted
|
|
610
|
+
* @param {number} y - the y coordinate of the local point to be converted
|
|
611
|
+
* @param {number} [v] - an optional vector object where to set the converted value
|
|
613
612
|
* @returns {Vector2d}
|
|
614
613
|
*/
|
|
615
614
|
localToWorld(x, y, v) {
|
|
@@ -628,9 +627,8 @@ let targetV = new Vector2d();
|
|
|
628
627
|
* @memberof Camera2d
|
|
629
628
|
* @param {number} x
|
|
630
629
|
* @param {number} y
|
|
631
|
-
* @param {number} [v] - an optional vector object where to set the
|
|
632
|
-
* converted
|
|
633
|
-
* @returns {Vector2d}
|
|
630
|
+
* @param {number} [v] - an optional vector object where to set the converted value
|
|
631
|
+
* @returns {Vector2d} a vector with the converted local coordinates
|
|
634
632
|
*/
|
|
635
633
|
worldToLocal(x, y, v) {
|
|
636
634
|
// TODO memoization for one set of coords (multitouch)
|
package/src/entity/entity.js
CHANGED
|
@@ -10,7 +10,7 @@ import Body from "./../physics/body.js";
|
|
|
10
10
|
* @augments Renderable
|
|
11
11
|
* @see Renderable
|
|
12
12
|
*/
|
|
13
|
-
|
|
13
|
+
export default class Entity extends Renderable {
|
|
14
14
|
/**
|
|
15
15
|
* @param {number} x - the x coordinates of the entity object
|
|
16
16
|
* @param {number} y - the y coordinates of the entity object
|
|
@@ -180,7 +180,7 @@ import Body from "./../physics/body.js";
|
|
|
180
180
|
}
|
|
181
181
|
|
|
182
182
|
if (absolute === true) {
|
|
183
|
-
|
|
183
|
+
let absPos = this.getAbsolutePosition();
|
|
184
184
|
bounds.centerOn(absPos.x + bounds.x + bounds.width / 2, absPos.y + bounds.y + bounds.height / 2);
|
|
185
185
|
}
|
|
186
186
|
|
|
@@ -192,7 +192,6 @@ import Body from "./../physics/body.js";
|
|
|
192
192
|
* @ignore
|
|
193
193
|
* @name onBodyUpdate
|
|
194
194
|
* @memberof Entity
|
|
195
|
-
* @param {Body} body - the body whose bounds to update
|
|
196
195
|
*/
|
|
197
196
|
onBodyUpdate() {
|
|
198
197
|
this.updateBounds();
|
|
@@ -4,7 +4,7 @@ import pool from "./../system/pooling.js";
|
|
|
4
4
|
* @classdesc
|
|
5
5
|
* an ellipse Object
|
|
6
6
|
*/
|
|
7
|
-
|
|
7
|
+
export default class Ellipse {
|
|
8
8
|
/**
|
|
9
9
|
* @param {number} x - the center x coordinate of the ellipse
|
|
10
10
|
* @param {number} y - the center y coordinate of the ellipse
|
|
@@ -16,8 +16,6 @@ import pool from "./../system/pooling.js";
|
|
|
16
16
|
* the center coordinates of the ellipse
|
|
17
17
|
* @public
|
|
18
18
|
* @type {Vector2d}
|
|
19
|
-
* @name pos
|
|
20
|
-
* @memberof Ellipse
|
|
21
19
|
*/
|
|
22
20
|
this.pos = pool.pull("Vector2d");
|
|
23
21
|
|
|
@@ -31,8 +29,6 @@ import pool from "./../system/pooling.js";
|
|
|
31
29
|
* Maximum radius of the ellipse
|
|
32
30
|
* @public
|
|
33
31
|
* @type {number}
|
|
34
|
-
* @name radius
|
|
35
|
-
* @memberof Ellipse
|
|
36
32
|
*/
|
|
37
33
|
this.radius = NaN;
|
|
38
34
|
|
|
@@ -40,8 +36,6 @@ import pool from "./../system/pooling.js";
|
|
|
40
36
|
* Pre-scaled radius vector for ellipse
|
|
41
37
|
* @public
|
|
42
38
|
* @type {Vector2d}
|
|
43
|
-
* @name radiusV
|
|
44
|
-
* @memberof Ellipse
|
|
45
39
|
*/
|
|
46
40
|
this.radiusV = pool.pull("Vector2d");
|
|
47
41
|
|
|
@@ -49,8 +43,6 @@ import pool from "./../system/pooling.js";
|
|
|
49
43
|
* Radius squared, for pythagorean theorom
|
|
50
44
|
* @public
|
|
51
45
|
* @type {Vector2d}
|
|
52
|
-
* @name radiusSq
|
|
53
|
-
* @memberof Ellipse
|
|
54
46
|
*/
|
|
55
47
|
this.radiusSq = pool.pull("Vector2d");
|
|
56
48
|
|
|
@@ -58,8 +50,6 @@ import pool from "./../system/pooling.js";
|
|
|
58
50
|
* x/y scaling ratio for ellipse
|
|
59
51
|
* @public
|
|
60
52
|
* @type {Vector2d}
|
|
61
|
-
* @name ratio
|
|
62
|
-
* @memberof Ellipse
|
|
63
53
|
*/
|
|
64
54
|
this.ratio = pool.pull("Vector2d");
|
|
65
55
|
|
|
@@ -75,8 +65,6 @@ import pool from "./../system/pooling.js";
|
|
|
75
65
|
|
|
76
66
|
/**
|
|
77
67
|
* set new value to the Ellipse shape
|
|
78
|
-
* @name setShape
|
|
79
|
-
* @memberof Ellipse
|
|
80
68
|
* @param {number} x - the center x coordinate of the ellipse
|
|
81
69
|
* @param {number} y - the center y coordinate of the ellipse
|
|
82
70
|
* @param {number} w - width (diameter) of the ellipse
|
|
@@ -104,8 +92,6 @@ import pool from "./../system/pooling.js";
|
|
|
104
92
|
|
|
105
93
|
/**
|
|
106
94
|
* Rotate this Ellipse (counter-clockwise) by the specified angle (in radians).
|
|
107
|
-
* @name rotate
|
|
108
|
-
* @memberof Ellipse
|
|
109
95
|
* @param {number} angle - The angle to rotate (in radians)
|
|
110
96
|
* @param {Vector2d|ObservableVector2d} [v] - an optional point to rotate around
|
|
111
97
|
* @returns {Ellipse} Reference to this object for method chaining
|
|
@@ -120,10 +106,8 @@ import pool from "./../system/pooling.js";
|
|
|
120
106
|
|
|
121
107
|
/**
|
|
122
108
|
* Scale this Ellipse by the specified scalar.
|
|
123
|
-
* @
|
|
124
|
-
* @
|
|
125
|
-
* @param {number} x
|
|
126
|
-
* @param {number} [y=x]
|
|
109
|
+
* @param {number} x - the scale factor along the x-axis
|
|
110
|
+
* @param {number} [y=x] - the scale factor along the y-axis
|
|
127
111
|
* @returns {Ellipse} Reference to this object for method chaining
|
|
128
112
|
*/
|
|
129
113
|
scale(x, y = x) {
|
|
@@ -137,8 +121,6 @@ import pool from "./../system/pooling.js";
|
|
|
137
121
|
|
|
138
122
|
/**
|
|
139
123
|
* Scale this Ellipse by the specified vector.
|
|
140
|
-
* @name scale
|
|
141
|
-
* @memberof Ellipse
|
|
142
124
|
* @param {Vector2d} v
|
|
143
125
|
* @returns {Ellipse} Reference to this object for method chaining
|
|
144
126
|
*/
|
|
@@ -148,8 +130,6 @@ import pool from "./../system/pooling.js";
|
|
|
148
130
|
|
|
149
131
|
/**
|
|
150
132
|
* apply the given transformation matrix to this ellipse
|
|
151
|
-
* @name transform
|
|
152
|
-
* @memberof Ellipse
|
|
153
133
|
* @param {Matrix2d} matrix - the transformation matrix
|
|
154
134
|
* @returns {Polygon} Reference to this object for method chaining
|
|
155
135
|
*/
|
|
@@ -160,19 +140,13 @@ import pool from "./../system/pooling.js";
|
|
|
160
140
|
|
|
161
141
|
/**
|
|
162
142
|
* translate the circle/ellipse by the specified offset
|
|
163
|
-
* @
|
|
164
|
-
* @
|
|
165
|
-
* @method
|
|
166
|
-
* @param {number} x - x offset
|
|
167
|
-
* @param {number} y - y offset
|
|
168
|
-
* @returns {Ellipse} this ellipse
|
|
169
|
-
*/
|
|
170
|
-
/**
|
|
171
|
-
* translate the circle/ellipse by the specified vector
|
|
172
|
-
* @name translate
|
|
173
|
-
* @memberof Ellipse
|
|
174
|
-
* @param {Vector2d} v - vector offset
|
|
143
|
+
* @param {number|Vector2d} x - x coordinate or a vector point to translate by
|
|
144
|
+
* @param {number} [y] - y offset
|
|
175
145
|
* @returns {Ellipse} this ellipse
|
|
146
|
+
* @example
|
|
147
|
+
* ellipse.translate(10, 10);
|
|
148
|
+
* // or
|
|
149
|
+
* ellipse.translate(myVector2d);
|
|
176
150
|
*/
|
|
177
151
|
translate() {
|
|
178
152
|
let _x, _y;
|
|
@@ -196,32 +170,29 @@ import pool from "./../system/pooling.js";
|
|
|
196
170
|
|
|
197
171
|
/**
|
|
198
172
|
* check if this circle/ellipse contains the specified point
|
|
199
|
-
* @
|
|
200
|
-
* @
|
|
201
|
-
* @memberof Ellipse
|
|
202
|
-
* @param {Vector2d} point
|
|
203
|
-
* @returns {boolean} true if contains
|
|
204
|
-
*/
|
|
205
|
-
|
|
206
|
-
/**
|
|
207
|
-
* check if this circle/ellipse contains the specified point
|
|
208
|
-
* @name contains
|
|
209
|
-
* @memberof Ellipse
|
|
210
|
-
* @param {number} x - x coordinate
|
|
211
|
-
* @param {number} y - y coordinate
|
|
173
|
+
* @param {number|Vector2d} x - x coordinate or a vector point to check
|
|
174
|
+
* @param {number} [y] - y coordinate
|
|
212
175
|
* @returns {boolean} true if contains
|
|
176
|
+
* @example
|
|
177
|
+
* if (circle.contains(10, 10)) {
|
|
178
|
+
* // do something
|
|
179
|
+
* }
|
|
180
|
+
* // or
|
|
181
|
+
* if (circle.contains(myVector2d)) {
|
|
182
|
+
* // do something
|
|
183
|
+
* }
|
|
213
184
|
*/
|
|
214
185
|
contains() {
|
|
215
186
|
let _x, _y;
|
|
216
187
|
|
|
217
188
|
if (arguments.length === 2) {
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
189
|
+
// x, y
|
|
190
|
+
_x = arguments[0];
|
|
191
|
+
_y = arguments[1];
|
|
221
192
|
} else {
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
193
|
+
// vector
|
|
194
|
+
_x = arguments[0].x;
|
|
195
|
+
_y = arguments[0].y;
|
|
225
196
|
}
|
|
226
197
|
|
|
227
198
|
// Make position relative to object center point.
|
|
@@ -236,8 +207,6 @@ import pool from "./../system/pooling.js";
|
|
|
236
207
|
|
|
237
208
|
/**
|
|
238
209
|
* returns the bounding box for this shape, the smallest Rectangle object completely containing this shape.
|
|
239
|
-
* @name getBounds
|
|
240
|
-
* @memberof Ellipse
|
|
241
210
|
* @returns {Bounds} this shape bounding box Rectangle object
|
|
242
211
|
*/
|
|
243
212
|
getBounds() {
|
|
@@ -249,8 +218,6 @@ import pool from "./../system/pooling.js";
|
|
|
249
218
|
|
|
250
219
|
/**
|
|
251
220
|
* clone this Ellipse
|
|
252
|
-
* @name clone
|
|
253
|
-
* @memberof Ellipse
|
|
254
221
|
* @returns {Ellipse} new Ellipse
|
|
255
222
|
*/
|
|
256
223
|
clone() {
|
package/src/geometries/line.js
CHANGED
|
@@ -10,36 +10,33 @@ import Polygon from "./poly.js";
|
|
|
10
10
|
* @param {Vector2d[]} points - array of vectors defining the Line
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
export default class Line extends Polygon {
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
16
|
* Returns true if the Line contains the given point
|
|
17
|
-
* @
|
|
18
|
-
* @
|
|
19
|
-
* @method
|
|
20
|
-
* @param {Vector2d} point
|
|
21
|
-
* @returns {boolean} true if contains
|
|
22
|
-
*/
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Returns true if the Line contains the given point
|
|
26
|
-
* @name contains
|
|
27
|
-
* @memberof Line
|
|
28
|
-
* @param {number} x - x coordinate
|
|
29
|
-
* @param {number} y - y coordinate
|
|
17
|
+
* @param {number|Vector2d} x - x coordinate or a vector point to check
|
|
18
|
+
* @param {number} [y] - y coordinate
|
|
30
19
|
* @returns {boolean} true if contains
|
|
20
|
+
* @example
|
|
21
|
+
* if (line.contains(10, 10)) {
|
|
22
|
+
* // do something
|
|
23
|
+
* }
|
|
24
|
+
* // or
|
|
25
|
+
* if (line.contains(myVector2d)) {
|
|
26
|
+
* // do something
|
|
27
|
+
* }
|
|
31
28
|
*/
|
|
32
29
|
contains() {
|
|
33
30
|
let _x, _y;
|
|
34
31
|
|
|
35
32
|
if (arguments.length === 2) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
33
|
+
// x, y
|
|
34
|
+
_x = arguments[0];
|
|
35
|
+
_y = arguments[1];
|
|
39
36
|
} else {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
37
|
+
// vector
|
|
38
|
+
_x = arguments[0].x;
|
|
39
|
+
_y = arguments[0].y;
|
|
43
40
|
}
|
|
44
41
|
|
|
45
42
|
// translate the given coordinates,
|
|
@@ -56,8 +53,6 @@ import Polygon from "./poly.js";
|
|
|
56
53
|
/**
|
|
57
54
|
* Computes the calculated collision edges and normals.
|
|
58
55
|
* This **must** be called if the `points` array, `angle`, or `offset` is modified manually.
|
|
59
|
-
* @name recalc
|
|
60
|
-
* @memberof Line
|
|
61
56
|
* @returns {Line} this instance for objecf chaining
|
|
62
57
|
*/
|
|
63
58
|
recalc() {
|
|
@@ -91,8 +86,6 @@ import Polygon from "./poly.js";
|
|
|
91
86
|
|
|
92
87
|
/**
|
|
93
88
|
* clone this line segment
|
|
94
|
-
* @name clone
|
|
95
|
-
* @memberof Line
|
|
96
89
|
* @returns {Line} new Line
|
|
97
90
|
*/
|
|
98
91
|
clone() {
|
package/src/geometries/path2d.js
CHANGED
|
@@ -6,7 +6,7 @@ import earcut from "earcut";
|
|
|
6
6
|
* @classdesc
|
|
7
7
|
* a simplified path2d implementation, supporting only one path
|
|
8
8
|
*/
|
|
9
|
-
|
|
9
|
+
export default class Path2D {
|
|
10
10
|
constructor() {
|
|
11
11
|
/**
|
|
12
12
|
* the points defining the current path
|
|
@@ -43,34 +43,35 @@ import earcut from "earcut";
|
|
|
43
43
|
*/
|
|
44
44
|
closePath() {
|
|
45
45
|
let points = this.points;
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
let firstPoint = points[0];
|
|
47
|
+
if (points.length > 1 && !points[points.length-1].equals(firstPoint)) {
|
|
48
|
+
points.push(pool.pull("Point", firstPoint.x, firstPoint.y));
|
|
48
49
|
}
|
|
49
50
|
}
|
|
50
51
|
|
|
51
52
|
/**
|
|
52
53
|
* triangulate the shape defined by this path into an array of triangles
|
|
53
|
-
* @returns {Point[]}
|
|
54
|
+
* @returns {Point[]} an array of vertices representing the triangulated path or shape
|
|
54
55
|
*/
|
|
55
56
|
triangulatePath() {
|
|
56
|
-
let i = 0;
|
|
57
57
|
let points = this.points;
|
|
58
58
|
let vertices = this.vertices;
|
|
59
59
|
let indices = earcut(points.flatMap(p => [p.x, p.y]));
|
|
60
|
+
let indicesLength = indices.length;
|
|
60
61
|
|
|
61
62
|
// pre-allocate vertices if necessary
|
|
62
|
-
while (vertices.length <
|
|
63
|
+
while (vertices.length < indicesLength) {
|
|
63
64
|
vertices.push(pool.pull("Point"));
|
|
64
65
|
}
|
|
65
66
|
|
|
66
67
|
// calculate all vertices
|
|
67
|
-
for (i = 0; i <
|
|
68
|
+
for (let i = 0; i < indicesLength; i++ ) {
|
|
68
69
|
let point = points[indices[i]];
|
|
69
70
|
vertices[i].set(point.x, point.y);
|
|
70
71
|
}
|
|
71
72
|
|
|
72
73
|
// recycle overhead from a previous triangulation
|
|
73
|
-
while (vertices.length >
|
|
74
|
+
while (vertices.length > indicesLength) {
|
|
74
75
|
pool.push(vertices[vertices.length-1]);
|
|
75
76
|
vertices.length -= 1;
|
|
76
77
|
}
|
|
@@ -84,7 +85,7 @@ import earcut from "earcut";
|
|
|
84
85
|
* @param {number} y - the y-axis (vertical) coordinate of the point.
|
|
85
86
|
*/
|
|
86
87
|
moveTo(x, y) {
|
|
87
|
-
|
|
88
|
+
this.points.push(pool.pull("Point", x, y));
|
|
88
89
|
}
|
|
89
90
|
|
|
90
91
|
/**
|
|
@@ -135,11 +136,12 @@ import earcut from "earcut";
|
|
|
135
136
|
const length = diff * radius;
|
|
136
137
|
const nr_of_interpolation_points = length / this.arcResolution;
|
|
137
138
|
const dangle = diff / nr_of_interpolation_points;
|
|
139
|
+
const angleStep = dangle * direction;
|
|
138
140
|
|
|
139
141
|
let angle = startAngle;
|
|
140
142
|
for (let j = 0; j < nr_of_interpolation_points; j++) {
|
|
141
143
|
points.push(pool.pull("Point", x + radius * Math.cos(angle), y + radius * Math.sin(angle)));
|
|
142
|
-
angle +=
|
|
144
|
+
angle += angleStep;
|
|
143
145
|
}
|
|
144
146
|
points.push(pool.pull("Point", x + radius * Math.cos(endAngle), y + radius * Math.sin(endAngle)));
|
|
145
147
|
}
|
|
@@ -230,6 +232,7 @@ import earcut from "earcut";
|
|
|
230
232
|
const length = (diff * radiusX + diff * radiusY) / 2;
|
|
231
233
|
const nr_of_interpolation_points = length / this.arcResolution;
|
|
232
234
|
const dangle = diff / nr_of_interpolation_points;
|
|
235
|
+
const angleStep = dangle * direction;
|
|
233
236
|
|
|
234
237
|
let angle = startAngle;
|
|
235
238
|
const cos_rotation = Math.cos(rotation);
|
|
@@ -240,7 +243,7 @@ import earcut from "earcut";
|
|
|
240
243
|
const _x2 = x + _x1 * cos_rotation - _y1 * sin_rotation;
|
|
241
244
|
const _y2 = y + _x1 * sin_rotation + _y1 * cos_rotation;
|
|
242
245
|
points.push(pool.pull("Point", _x2, _y2));
|
|
243
|
-
angle +=
|
|
246
|
+
angle += angleStep;
|
|
244
247
|
}
|
|
245
248
|
}
|
|
246
249
|
|
|
@@ -270,7 +273,7 @@ import earcut from "earcut";
|
|
|
270
273
|
* @param {number} height - the rectangle's height. Positive values are down, and negative are up.
|
|
271
274
|
* @param {number} radius - the arc's radius to draw the borders. Must be positive.
|
|
272
275
|
*/
|
|
273
|
-
|
|
276
|
+
roundRect(x, y, width, height, radius) {
|
|
274
277
|
this.moveTo(x + radius, y);
|
|
275
278
|
this.lineTo(x + width - radius, y);
|
|
276
279
|
this.arcTo(x + width, y, x + width, y + radius, radius);
|
package/src/geometries/point.js
CHANGED
|
@@ -2,18 +2,18 @@
|
|
|
2
2
|
* @classdesc
|
|
3
3
|
* represents a point in a 2d space
|
|
4
4
|
*/
|
|
5
|
-
|
|
5
|
+
export default class Point {
|
|
6
6
|
constructor(x = 0, y = 0) {
|
|
7
7
|
/**
|
|
8
8
|
* the position of the point on the horizontal axis
|
|
9
|
-
* @type {
|
|
9
|
+
* @type {number}
|
|
10
10
|
* @default 0
|
|
11
11
|
*/
|
|
12
12
|
this.x = x;
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* the position of the point on the vertical axis
|
|
16
|
-
* @type {
|
|
16
|
+
* @type {number}
|
|
17
17
|
* @default 0
|
|
18
18
|
*/
|
|
19
19
|
this.y = y;
|
|
@@ -37,20 +37,12 @@
|
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
/**
|
|
40
|
-
* return true if
|
|
41
|
-
* @
|
|
42
|
-
* @
|
|
43
|
-
* @method
|
|
44
|
-
* @param {Point} point
|
|
40
|
+
* return true if this point is equal to the given point
|
|
41
|
+
* @param {number|Point|Vector2d} x
|
|
42
|
+
* @param {number} [y]
|
|
45
43
|
* @returns {boolean}
|
|
46
44
|
*/
|
|
47
|
-
|
|
48
|
-
* return true if this point is equal to the given values
|
|
49
|
-
* @param {number} x
|
|
50
|
-
* @param {number} y
|
|
51
|
-
* @returns {boolean}
|
|
52
|
-
*/
|
|
53
|
-
equals() {
|
|
45
|
+
equals() {
|
|
54
46
|
let _x, _y;
|
|
55
47
|
if (arguments.length === 2) {
|
|
56
48
|
// x, y
|