melonjs 15.3.0 → 15.4.1
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/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 +53 -5
- package/dist/melonjs.mjs/application/header.js +2 -2
- package/dist/melonjs.mjs/application/resize.js +4 -8
- package/dist/melonjs.mjs/application/settings.js +5 -5
- 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 +26 -29
- 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 +2 -2
- 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 +26 -26
- 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 +2 -2
- package/dist/melonjs.mjs/state/state.js +1 -38
- package/dist/melonjs.mjs/system/device.js +49 -10
- package/dist/melonjs.mjs/system/dom.js +1 -1
- package/dist/melonjs.mjs/system/event.js +24 -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 +3 -7
- package/dist/melonjs.mjs/video/renderer.js +16 -16
- 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 +4 -4
- 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 +50 -52
- package/dist/melonjs.module.js +1137 -1576
- package/dist/types/application/application.d.ts +28 -4
- package/dist/types/application/header.d.ts +2 -2
- package/dist/types/application/settings.d.ts +23 -23
- package/dist/types/audio/audio.d.ts +3 -5
- 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/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 +9 -16
- 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/state.d.ts +11 -11
- package/dist/types/system/device.d.ts +15 -9
- package/dist/types/system/event.d.ts +20 -0
- package/dist/types/system/platform.d.ts +17 -17
- package/dist/types/utils/function.d.ts +1 -2
- package/dist/types/video/renderer.d.ts +13 -13
- package/dist/types/video/texture/canvas_texture.d.ts +14 -14
- package/dist/types/video/video.d.ts +2 -2
- 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 +47 -50
- package/package.json +15 -15
- package/src/application/application.js +51 -3
- package/src/application/header.js +1 -1
- package/src/application/resize.js +3 -7
- package/src/application/settings.js +4 -4
- 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 +25 -28
- 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 +1 -1
- 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 +25 -25
- 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 +1 -1
- package/src/state/state.js +0 -49
- package/src/system/device.js +48 -9
- package/src/system/event.js +22 -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 +2 -6
- package/src/video/renderer.js +15 -15
- package/src/video/texture/atlas.js +12 -12
- package/src/video/texture/canvas_texture.js +14 -14
- package/src/video/video.js +3 -3
- 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 +49 -51
- /package/src/{text → renderable/text}/textstyle.js +0 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* melonJS Game Engine - v15.
|
|
2
|
+
* melonJS Game Engine - v15.4.1
|
|
3
3
|
* http://www.melonjs.org
|
|
4
4
|
* melonjs is licensed under the MIT License.
|
|
5
5
|
* http://www.opensource.org/licenses/mit-license
|
|
@@ -13,7 +13,7 @@ import earcut from '../node_modules/earcut/src/earcut.js';
|
|
|
13
13
|
* @classdesc
|
|
14
14
|
* a simplified path2d implementation, supporting only one path
|
|
15
15
|
*/
|
|
16
|
-
|
|
16
|
+
class Path2D {
|
|
17
17
|
constructor() {
|
|
18
18
|
/**
|
|
19
19
|
* the points defining the current path
|
|
@@ -50,34 +50,35 @@ import earcut from '../node_modules/earcut/src/earcut.js';
|
|
|
50
50
|
*/
|
|
51
51
|
closePath() {
|
|
52
52
|
let points = this.points;
|
|
53
|
-
|
|
54
|
-
|
|
53
|
+
let firstPoint = points[0];
|
|
54
|
+
if (points.length > 1 && !points[points.length-1].equals(firstPoint)) {
|
|
55
|
+
points.push(pool.pull("Point", firstPoint.x, firstPoint.y));
|
|
55
56
|
}
|
|
56
57
|
}
|
|
57
58
|
|
|
58
59
|
/**
|
|
59
60
|
* triangulate the shape defined by this path into an array of triangles
|
|
60
|
-
* @returns {Point[]}
|
|
61
|
+
* @returns {Point[]} an array of vertices representing the triangulated path or shape
|
|
61
62
|
*/
|
|
62
63
|
triangulatePath() {
|
|
63
|
-
let i = 0;
|
|
64
64
|
let points = this.points;
|
|
65
65
|
let vertices = this.vertices;
|
|
66
66
|
let indices = earcut(points.flatMap(p => [p.x, p.y]));
|
|
67
|
+
let indicesLength = indices.length;
|
|
67
68
|
|
|
68
69
|
// pre-allocate vertices if necessary
|
|
69
|
-
while (vertices.length <
|
|
70
|
+
while (vertices.length < indicesLength) {
|
|
70
71
|
vertices.push(pool.pull("Point"));
|
|
71
72
|
}
|
|
72
73
|
|
|
73
74
|
// calculate all vertices
|
|
74
|
-
for (i = 0; i <
|
|
75
|
+
for (let i = 0; i < indicesLength; i++ ) {
|
|
75
76
|
let point = points[indices[i]];
|
|
76
77
|
vertices[i].set(point.x, point.y);
|
|
77
78
|
}
|
|
78
79
|
|
|
79
80
|
// recycle overhead from a previous triangulation
|
|
80
|
-
while (vertices.length >
|
|
81
|
+
while (vertices.length > indicesLength) {
|
|
81
82
|
pool.push(vertices[vertices.length-1]);
|
|
82
83
|
vertices.length -= 1;
|
|
83
84
|
}
|
|
@@ -91,7 +92,7 @@ import earcut from '../node_modules/earcut/src/earcut.js';
|
|
|
91
92
|
* @param {number} y - the y-axis (vertical) coordinate of the point.
|
|
92
93
|
*/
|
|
93
94
|
moveTo(x, y) {
|
|
94
|
-
|
|
95
|
+
this.points.push(pool.pull("Point", x, y));
|
|
95
96
|
}
|
|
96
97
|
|
|
97
98
|
/**
|
|
@@ -142,11 +143,12 @@ import earcut from '../node_modules/earcut/src/earcut.js';
|
|
|
142
143
|
const length = diff * radius;
|
|
143
144
|
const nr_of_interpolation_points = length / this.arcResolution;
|
|
144
145
|
const dangle = diff / nr_of_interpolation_points;
|
|
146
|
+
const angleStep = dangle * direction;
|
|
145
147
|
|
|
146
148
|
let angle = startAngle;
|
|
147
149
|
for (let j = 0; j < nr_of_interpolation_points; j++) {
|
|
148
150
|
points.push(pool.pull("Point", x + radius * Math.cos(angle), y + radius * Math.sin(angle)));
|
|
149
|
-
angle +=
|
|
151
|
+
angle += angleStep;
|
|
150
152
|
}
|
|
151
153
|
points.push(pool.pull("Point", x + radius * Math.cos(endAngle), y + radius * Math.sin(endAngle)));
|
|
152
154
|
}
|
|
@@ -237,6 +239,7 @@ import earcut from '../node_modules/earcut/src/earcut.js';
|
|
|
237
239
|
const length = (diff * radiusX + diff * radiusY) / 2;
|
|
238
240
|
const nr_of_interpolation_points = length / this.arcResolution;
|
|
239
241
|
const dangle = diff / nr_of_interpolation_points;
|
|
242
|
+
const angleStep = dangle * direction;
|
|
240
243
|
|
|
241
244
|
let angle = startAngle;
|
|
242
245
|
const cos_rotation = Math.cos(rotation);
|
|
@@ -247,7 +250,7 @@ import earcut from '../node_modules/earcut/src/earcut.js';
|
|
|
247
250
|
const _x2 = x + _x1 * cos_rotation - _y1 * sin_rotation;
|
|
248
251
|
const _y2 = y + _x1 * sin_rotation + _y1 * cos_rotation;
|
|
249
252
|
points.push(pool.pull("Point", _x2, _y2));
|
|
250
|
-
angle +=
|
|
253
|
+
angle += angleStep;
|
|
251
254
|
}
|
|
252
255
|
}
|
|
253
256
|
|
|
@@ -277,7 +280,7 @@ import earcut from '../node_modules/earcut/src/earcut.js';
|
|
|
277
280
|
* @param {number} height - the rectangle's height. Positive values are down, and negative are up.
|
|
278
281
|
* @param {number} radius - the arc's radius to draw the borders. Must be positive.
|
|
279
282
|
*/
|
|
280
|
-
|
|
283
|
+
roundRect(x, y, width, height, radius) {
|
|
281
284
|
this.moveTo(x + radius, y);
|
|
282
285
|
this.lineTo(x + width - radius, y);
|
|
283
286
|
this.arcTo(x + width, y, x + width, y + radius, radius);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* melonJS Game Engine - v15.
|
|
2
|
+
* melonJS Game Engine - v15.4.1
|
|
3
3
|
* http://www.melonjs.org
|
|
4
4
|
* melonjs is licensed under the MIT License.
|
|
5
5
|
* http://www.opensource.org/licenses/mit-license
|
|
@@ -9,18 +9,18 @@
|
|
|
9
9
|
* @classdesc
|
|
10
10
|
* represents a point in a 2d space
|
|
11
11
|
*/
|
|
12
|
-
|
|
12
|
+
class Point {
|
|
13
13
|
constructor(x = 0, y = 0) {
|
|
14
14
|
/**
|
|
15
15
|
* the position of the point on the horizontal axis
|
|
16
|
-
* @type {
|
|
16
|
+
* @type {number}
|
|
17
17
|
* @default 0
|
|
18
18
|
*/
|
|
19
19
|
this.x = x;
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
22
|
* the position of the point on the vertical axis
|
|
23
|
-
* @type {
|
|
23
|
+
* @type {number}
|
|
24
24
|
* @default 0
|
|
25
25
|
*/
|
|
26
26
|
this.y = y;
|
|
@@ -44,20 +44,12 @@
|
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
/**
|
|
47
|
-
* return true if
|
|
48
|
-
* @
|
|
49
|
-
* @
|
|
50
|
-
* @method
|
|
51
|
-
* @param {Point} point
|
|
47
|
+
* return true if this point is equal to the given point
|
|
48
|
+
* @param {number|Point|Vector2d} x
|
|
49
|
+
* @param {number} [y]
|
|
52
50
|
* @returns {boolean}
|
|
53
51
|
*/
|
|
54
|
-
|
|
55
|
-
* return true if this point is equal to the given values
|
|
56
|
-
* @param {number} x
|
|
57
|
-
* @param {number} y
|
|
58
|
-
* @returns {boolean}
|
|
59
|
-
*/
|
|
60
|
-
equals() {
|
|
52
|
+
equals() {
|
|
61
53
|
let _x, _y;
|
|
62
54
|
if (arguments.length === 2) {
|
|
63
55
|
// x, y
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* melonJS Game Engine - v15.
|
|
2
|
+
* melonJS Game Engine - v15.4.1
|
|
3
3
|
* http://www.melonjs.org
|
|
4
4
|
* melonjs is licensed under the MIT License.
|
|
5
5
|
* http://www.opensource.org/licenses/mit-license
|
|
@@ -19,7 +19,7 @@ import pool from '../system/pooling.js';
|
|
|
19
19
|
*
|
|
20
20
|
* A polygon's `winding` is clockwise if its vertices (points) are declared turning to the right. The image above shows COUNTERCLOCKWISE winding.
|
|
21
21
|
*/
|
|
22
|
-
|
|
22
|
+
class Polygon {
|
|
23
23
|
/**
|
|
24
24
|
* @param {number} x - origin point of the Polygon
|
|
25
25
|
* @param {number} y - origin point of the Polygon
|
|
@@ -28,10 +28,7 @@ import pool from '../system/pooling.js';
|
|
|
28
28
|
constructor(x, y, points) {
|
|
29
29
|
/**
|
|
30
30
|
* origin point of the Polygon
|
|
31
|
-
* @public
|
|
32
31
|
* @type {Vector2d}
|
|
33
|
-
* @name pos
|
|
34
|
-
* @memberof Polygon
|
|
35
32
|
*/
|
|
36
33
|
this.pos = pool.pull("Vector2d");
|
|
37
34
|
|
|
@@ -39,18 +36,13 @@ import pool from '../system/pooling.js';
|
|
|
39
36
|
* The bounding rectangle for this shape
|
|
40
37
|
* @ignore
|
|
41
38
|
* @member {Bounds}
|
|
42
|
-
* @name _bounds
|
|
43
|
-
* @memberof Polygon
|
|
44
39
|
*/
|
|
45
40
|
this._bounds;
|
|
46
41
|
|
|
47
42
|
/**
|
|
48
43
|
* Array of points defining the Polygon <br>
|
|
49
44
|
* Note: If you manually change `points`, you **must** call `recalc`afterwards so that the changes get applied correctly.
|
|
50
|
-
* @public
|
|
51
45
|
* @type {Vector2d[]}
|
|
52
|
-
* @name points
|
|
53
|
-
* @memberof Polygon
|
|
54
46
|
*/
|
|
55
47
|
this.points = [];
|
|
56
48
|
|
|
@@ -88,8 +80,6 @@ import pool from '../system/pooling.js';
|
|
|
88
80
|
|
|
89
81
|
/**
|
|
90
82
|
* set new value to the Polygon
|
|
91
|
-
* @name setShape
|
|
92
|
-
* @memberof Polygon
|
|
93
83
|
* @param {number} x - position of the Polygon
|
|
94
84
|
* @param {number} y - position of the Polygon
|
|
95
85
|
* @param {Vector2d[]|number[]} points - array of vector or vertice defining the Polygon
|
|
@@ -103,8 +93,6 @@ import pool from '../system/pooling.js';
|
|
|
103
93
|
|
|
104
94
|
/**
|
|
105
95
|
* set the vertices defining this Polygon
|
|
106
|
-
* @name setVertices
|
|
107
|
-
* @memberof Polygon
|
|
108
96
|
* @param {Vector2d[]} vertices - array of vector or vertice defining the Polygon
|
|
109
97
|
* @returns {Polygon} this instance for objecf chaining
|
|
110
98
|
*/
|
|
@@ -121,7 +109,7 @@ import pool from '../system/pooling.js';
|
|
|
121
109
|
if (typeof vertices[0] === "object") {
|
|
122
110
|
// array of {x,y} object
|
|
123
111
|
vertices.forEach((vertice) => {
|
|
124
|
-
|
|
112
|
+
this.points.push(pool.pull("Vector2d", vertice.x, vertice.y));
|
|
125
113
|
});
|
|
126
114
|
|
|
127
115
|
} else {
|
|
@@ -142,8 +130,6 @@ import pool from '../system/pooling.js';
|
|
|
142
130
|
|
|
143
131
|
/**
|
|
144
132
|
* apply the given transformation matrix to this Polygon
|
|
145
|
-
* @name transform
|
|
146
|
-
* @memberof Polygon
|
|
147
133
|
* @param {Matrix2d} m - the transformation matrix
|
|
148
134
|
* @returns {Polygon} Reference to this object for method chaining
|
|
149
135
|
*/
|
|
@@ -160,8 +146,6 @@ import pool from '../system/pooling.js';
|
|
|
160
146
|
|
|
161
147
|
/**
|
|
162
148
|
* apply an isometric projection to this shape
|
|
163
|
-
* @name toIso
|
|
164
|
-
* @memberof Polygon
|
|
165
149
|
* @returns {Polygon} Reference to this object for method chaining
|
|
166
150
|
*/
|
|
167
151
|
toIso() {
|
|
@@ -169,9 +153,7 @@ import pool from '../system/pooling.js';
|
|
|
169
153
|
}
|
|
170
154
|
|
|
171
155
|
/**
|
|
172
|
-
* apply a 2d projection to this
|
|
173
|
-
* @name to2d
|
|
174
|
-
* @memberof Polygon
|
|
156
|
+
* apply a 2d projection to this shapen
|
|
175
157
|
* @returns {Polygon} Reference to this object for method chaining
|
|
176
158
|
*/
|
|
177
159
|
to2d() {
|
|
@@ -180,8 +162,6 @@ import pool from '../system/pooling.js';
|
|
|
180
162
|
|
|
181
163
|
/**
|
|
182
164
|
* Rotate this Polygon (counter-clockwise) by the specified angle (in radians).
|
|
183
|
-
* @name rotate
|
|
184
|
-
* @memberof Polygon
|
|
185
165
|
* @param {number} angle - The angle to rotate (in radians)
|
|
186
166
|
* @param {Vector2d|ObservableVector2d} [v] - an optional point to rotate around
|
|
187
167
|
* @returns {Polygon} Reference to this object for method chaining
|
|
@@ -201,8 +181,6 @@ import pool from '../system/pooling.js';
|
|
|
201
181
|
|
|
202
182
|
/**
|
|
203
183
|
* Scale this Polygon by the given scalar.
|
|
204
|
-
* @name scale
|
|
205
|
-
* @memberof Polygon
|
|
206
184
|
* @param {number} x
|
|
207
185
|
* @param {number} [y=x]
|
|
208
186
|
* @returns {Polygon} Reference to this object for method chaining
|
|
@@ -220,8 +198,6 @@ import pool from '../system/pooling.js';
|
|
|
220
198
|
|
|
221
199
|
/**
|
|
222
200
|
* Scale this Polygon by the given vector
|
|
223
|
-
* @name scaleV
|
|
224
|
-
* @memberof Polygon
|
|
225
201
|
* @param {Vector2d} v
|
|
226
202
|
* @returns {Polygon} Reference to this object for method chaining
|
|
227
203
|
*/
|
|
@@ -232,12 +208,9 @@ import pool from '../system/pooling.js';
|
|
|
232
208
|
/**
|
|
233
209
|
* Computes the calculated collision polygon.
|
|
234
210
|
* This **must** be called if the `points` array, `angle`, or `offset` is modified manually.
|
|
235
|
-
* @name recalc
|
|
236
|
-
* @memberof Polygon
|
|
237
211
|
* @returns {Polygon} Reference to this object for method chaining
|
|
238
212
|
*/
|
|
239
213
|
recalc() {
|
|
240
|
-
let i;
|
|
241
214
|
let edges = this.edges;
|
|
242
215
|
let normals = this.normals;
|
|
243
216
|
let indices = this.indices;
|
|
@@ -251,7 +224,7 @@ import pool from '../system/pooling.js';
|
|
|
251
224
|
}
|
|
252
225
|
|
|
253
226
|
// Calculate the edges/normals
|
|
254
|
-
for (i = 0; i < len; i++) {
|
|
227
|
+
for (let i = 0; i < len; i++) {
|
|
255
228
|
if (edges[i] === undefined) {
|
|
256
229
|
edges[i] = pool.pull("Vector2d");
|
|
257
230
|
}
|
|
@@ -275,8 +248,6 @@ import pool from '../system/pooling.js';
|
|
|
275
248
|
|
|
276
249
|
/**
|
|
277
250
|
* returns a list of indices for all triangles defined in this polygon
|
|
278
|
-
* @name getIndices
|
|
279
|
-
* @memberof Polygon
|
|
280
251
|
* @returns {Array} an array of vertex indices for all triangles forming this polygon.
|
|
281
252
|
*/
|
|
282
253
|
getIndices() {
|
|
@@ -288,8 +259,6 @@ import pool from '../system/pooling.js';
|
|
|
288
259
|
|
|
289
260
|
/**
|
|
290
261
|
* Returns true if the vertices composing this polygon form a convex shape (vertices must be in clockwise order).
|
|
291
|
-
* @name isConvex
|
|
292
|
-
* @memberof Polygon
|
|
293
262
|
* @returns {boolean} true if the vertices are convex, false if not, null if not computable
|
|
294
263
|
*/
|
|
295
264
|
isConvex() {
|
|
@@ -298,20 +267,16 @@ import pool from '../system/pooling.js';
|
|
|
298
267
|
|
|
299
268
|
let flag = 0,
|
|
300
269
|
vertices = this.points,
|
|
301
|
-
n = vertices.length
|
|
302
|
-
i,
|
|
303
|
-
j,
|
|
304
|
-
k,
|
|
305
|
-
z;
|
|
270
|
+
n = vertices.length;
|
|
306
271
|
|
|
307
272
|
if (n < 3) {
|
|
308
273
|
return null;
|
|
309
274
|
}
|
|
310
275
|
|
|
311
|
-
for (i = 0; i < n; i++) {
|
|
312
|
-
j = (i + 1) % n;
|
|
313
|
-
k = (i + 2) % n;
|
|
314
|
-
z = (vertices[j].x - vertices[i].x) * (vertices[k].y - vertices[j].y);
|
|
276
|
+
for (let i = 0; i < n; i++) {
|
|
277
|
+
let j = (i + 1) % n;
|
|
278
|
+
let k = (i + 2) % n;
|
|
279
|
+
let z = (vertices[j].x - vertices[i].x) * (vertices[k].y - vertices[j].y);
|
|
315
280
|
z -= (vertices[j].y - vertices[i].y) * (vertices[k].x - vertices[j].x);
|
|
316
281
|
|
|
317
282
|
if (z < 0) {
|
|
@@ -334,19 +299,13 @@ import pool from '../system/pooling.js';
|
|
|
334
299
|
|
|
335
300
|
/**
|
|
336
301
|
* translate the Polygon by the specified offset
|
|
337
|
-
* @
|
|
338
|
-
* @
|
|
339
|
-
* @method
|
|
340
|
-
* @param {number} x - x offset
|
|
341
|
-
* @param {number} y - y offset
|
|
342
|
-
* @returns {Polygon} this Polygon
|
|
343
|
-
*/
|
|
344
|
-
/**
|
|
345
|
-
* translate the Polygon by the specified vector
|
|
346
|
-
* @name translate
|
|
347
|
-
* @memberof Polygon
|
|
348
|
-
* @param {Vector2d} v - vector offset
|
|
302
|
+
* @param {number|Vector2d} x - x offset or a vector point to translate by
|
|
303
|
+
* @param {number} [y] - y offset
|
|
349
304
|
* @returns {Polygon} Reference to this object for method chaining
|
|
305
|
+
* @example
|
|
306
|
+
* polygon.translate(10, 10);
|
|
307
|
+
* // or
|
|
308
|
+
* polygon.translate(myVector2d);
|
|
350
309
|
*/
|
|
351
310
|
translate() {
|
|
352
311
|
let _x, _y;
|
|
@@ -370,17 +329,12 @@ import pool from '../system/pooling.js';
|
|
|
370
329
|
|
|
371
330
|
/**
|
|
372
331
|
* Shifts the Polygon to the given position vector.
|
|
373
|
-
* @
|
|
374
|
-
* @
|
|
375
|
-
* @
|
|
376
|
-
*
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
* Shifts the Polygon to the given x, y position.
|
|
380
|
-
* @name shift
|
|
381
|
-
* @memberof Polygon
|
|
382
|
-
* @param {number} x
|
|
383
|
-
* @param {number} y
|
|
332
|
+
* @param {number|Vector2d} x - x coordinate or a vector point to shift to
|
|
333
|
+
* @param {number} [y]
|
|
334
|
+
* @example
|
|
335
|
+
* polygon.shift(10, 10);
|
|
336
|
+
* // or
|
|
337
|
+
* polygon.shift(myVector2d);
|
|
384
338
|
*/
|
|
385
339
|
shift() {
|
|
386
340
|
let _x, _y;
|
|
@@ -398,38 +352,33 @@ import pool from '../system/pooling.js';
|
|
|
398
352
|
this.updateBounds();
|
|
399
353
|
}
|
|
400
354
|
|
|
401
|
-
/**
|
|
402
|
-
* Returns true if the polygon contains the given point.
|
|
403
|
-
* (Note: it is highly recommended to first do a hit test on the corresponding <br>
|
|
404
|
-
* bounding rect, as the function can be highly consuming with complex shapes)
|
|
405
|
-
* @name contains
|
|
406
|
-
* @memberof Polygon
|
|
407
|
-
* @method
|
|
408
|
-
* @param {Vector2d} point
|
|
409
|
-
* @returns {boolean} true if contains
|
|
410
|
-
*/
|
|
411
|
-
|
|
412
355
|
/**
|
|
413
356
|
* Returns true if the polygon contains the given point. <br>
|
|
414
357
|
* (Note: it is highly recommended to first do a hit test on the corresponding <br>
|
|
415
358
|
* bounding rect, as the function can be highly consuming with complex shapes)
|
|
416
|
-
* @
|
|
417
|
-
* @
|
|
418
|
-
* @
|
|
419
|
-
* @
|
|
420
|
-
*
|
|
359
|
+
* @param {number|Vector2d} x - x coordinate or a vector point to check
|
|
360
|
+
* @param {number} [y] - y coordinate
|
|
361
|
+
* @returns {boolean} True if the polygon contain the point, otherwise false
|
|
362
|
+
* @example
|
|
363
|
+
* if (polygon.contains(10, 10)) {
|
|
364
|
+
* // do something
|
|
365
|
+
* }
|
|
366
|
+
* // or
|
|
367
|
+
* if (polygon.contains(myVector2d)) {
|
|
368
|
+
* // do something
|
|
369
|
+
* }
|
|
421
370
|
*/
|
|
422
371
|
contains() {
|
|
423
372
|
let _x, _y;
|
|
424
373
|
|
|
425
374
|
if (arguments.length === 2) {
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
375
|
+
// x, y
|
|
376
|
+
_x = arguments[0];
|
|
377
|
+
_y = arguments[1];
|
|
429
378
|
} else {
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
379
|
+
// vector
|
|
380
|
+
_x = arguments[0].x;
|
|
381
|
+
_y = arguments[0].y;
|
|
433
382
|
}
|
|
434
383
|
|
|
435
384
|
let intersects = false;
|
|
@@ -440,7 +389,7 @@ import pool from '../system/pooling.js';
|
|
|
440
389
|
//http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html
|
|
441
390
|
for (let i = 0, j = len - 1; i < len; j = i++) {
|
|
442
391
|
const iy = points[i].y + posy, ix = points[i].x + posx,
|
|
443
|
-
|
|
392
|
+
jy = points[j].y + posy, jx = points[j].x + posx;
|
|
444
393
|
if (((iy > _y) !== (jy > _y)) && (_x < (jx - ix) * (_y - iy) / (jy - iy) + ix)) {
|
|
445
394
|
intersects = !intersects;
|
|
446
395
|
}
|
|
@@ -450,8 +399,6 @@ import pool from '../system/pooling.js';
|
|
|
450
399
|
|
|
451
400
|
/**
|
|
452
401
|
* returns the bounding box for this shape, the smallest Rectangle object completely containing this shape.
|
|
453
|
-
* @name getBounds
|
|
454
|
-
* @memberof Polygon
|
|
455
402
|
* @returns {Bounds} this shape bounding box Rectangle object
|
|
456
403
|
*/
|
|
457
404
|
getBounds() {
|
|
@@ -463,8 +410,6 @@ import pool from '../system/pooling.js';
|
|
|
463
410
|
|
|
464
411
|
/**
|
|
465
412
|
* update the bounding box for this shape.
|
|
466
|
-
* @name updateBounds
|
|
467
|
-
* @memberof Polygon
|
|
468
413
|
* @returns {Bounds} this shape bounding box Rectangle object
|
|
469
414
|
*/
|
|
470
415
|
updateBounds() {
|
|
@@ -478,8 +423,6 @@ import pool from '../system/pooling.js';
|
|
|
478
423
|
|
|
479
424
|
/**
|
|
480
425
|
* clone this Polygon
|
|
481
|
-
* @name clone
|
|
482
|
-
* @memberof Polygon
|
|
483
426
|
* @returns {Polygon} new Polygon
|
|
484
427
|
*/
|
|
485
428
|
clone() {
|