melonjs 10.3.0 → 10.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -6
- package/dist/melonjs.js +2419 -3072
- package/dist/melonjs.min.js +3 -3
- package/dist/melonjs.module.d.ts +3417 -3816
- package/dist/melonjs.module.js +2737 -3002
- package/package.json +16 -16
- package/src/audio/audio.js +29 -30
- package/src/camera/camera2d.js +46 -56
- package/src/entity/draggable.js +12 -13
- package/src/entity/droptarget.js +13 -15
- package/src/entity/entity.js +30 -36
- package/src/game.js +21 -22
- package/src/geometries/ellipse.js +40 -46
- package/src/geometries/line.js +9 -11
- package/src/geometries/poly.js +53 -53
- package/src/geometries/rectangle.js +42 -44
- package/src/index.js +4 -14
- package/src/input/gamepad.js +11 -10
- package/src/input/input.js +2 -3
- package/src/input/keyboard.js +113 -113
- package/src/input/pointer.js +30 -31
- package/src/input/pointerevent.js +26 -26
- package/src/lang/deprecated.js +25 -6
- package/src/level/level.js +23 -24
- package/src/level/tiled/TMXGroup.js +7 -8
- package/src/level/tiled/TMXLayer.js +30 -32
- package/src/level/tiled/TMXObject.js +21 -21
- package/src/level/tiled/TMXTile.js +18 -18
- package/src/level/tiled/TMXTileMap.js +37 -44
- package/src/level/tiled/TMXTileset.js +12 -15
- package/src/level/tiled/TMXTilesetGroup.js +9 -9
- package/src/level/tiled/renderer/TMXHexagonalRenderer.js +7 -8
- package/src/level/tiled/renderer/TMXIsometricRenderer.js +7 -8
- package/src/level/tiled/renderer/TMXOrthogonalRenderer.js +4 -5
- package/src/level/tiled/renderer/TMXRenderer.js +24 -25
- package/src/level/tiled/renderer/TMXStaggeredRenderer.js +1 -4
- package/src/loader/loader.js +14 -15
- package/src/loader/loadingscreen.js +2 -4
- package/src/math/color.js +47 -66
- package/src/math/math.js +15 -16
- package/src/math/matrix2.js +53 -58
- package/src/math/matrix3.js +56 -62
- package/src/math/observable_vector2.js +75 -76
- package/src/math/observable_vector3.js +79 -80
- package/src/math/vector2.js +91 -92
- package/src/math/vector3.js +94 -96
- package/src/particles/emitter.js +38 -40
- package/src/particles/particle.js +4 -5
- package/src/particles/particlecontainer.js +2 -3
- package/src/physics/body.js +44 -142
- package/src/physics/bounds.js +47 -47
- package/src/physics/collision.js +13 -14
- package/src/physics/detector.js +14 -14
- package/src/physics/quadtree.js +17 -19
- package/src/physics/sat.js +26 -26
- package/src/physics/world.js +24 -28
- package/src/plugin/plugin.js +11 -14
- package/src/renderable/GUI.js +41 -46
- package/src/renderable/collectable.js +4 -8
- package/src/renderable/colorlayer.js +6 -10
- package/src/renderable/container.js +87 -72
- package/src/renderable/imagelayer.js +25 -31
- package/src/renderable/nineslicesprite.js +41 -41
- package/src/renderable/renderable.js +112 -122
- package/src/renderable/sprite.js +62 -68
- package/src/renderable/trigger.js +25 -30
- package/src/state/stage.js +13 -17
- package/src/state/state.js +26 -27
- package/src/system/device.js +74 -75
- package/src/system/event.js +71 -72
- package/src/system/pooling.js +11 -12
- package/src/system/save.js +3 -4
- package/src/system/timer.js +19 -20
- package/src/text/bitmaptext.js +57 -54
- package/src/text/bitmaptextdata.js +10 -10
- package/src/text/glyph.js +3 -0
- package/src/text/text.js +44 -49
- package/src/tweens/easing.js +1 -1
- package/src/tweens/interpolation.js +1 -1
- package/src/tweens/tween.js +43 -44
- package/src/utils/agent.js +3 -4
- package/src/utils/array.js +4 -5
- package/src/utils/file.js +3 -4
- package/src/utils/function.js +4 -5
- package/src/utils/string.js +7 -9
- package/src/utils/utils.js +4 -5
- package/src/video/canvas/canvas_renderer.js +58 -59
- package/src/video/renderer.js +49 -53
- package/src/video/texture.js +98 -111
- package/src/video/texture_cache.js +2 -2
- package/src/video/video.js +15 -16
- package/src/video/webgl/glshader.js +37 -38
- package/src/video/webgl/webgl_compositor.js +31 -32
- package/src/video/webgl/webgl_renderer.js +79 -80
package/src/geometries/poly.js
CHANGED
|
@@ -10,31 +10,31 @@ import pool from "./../system/pooling.js";
|
|
|
10
10
|
* (which means that all angles are less than 180 degrees), as described here below : <br>
|
|
11
11
|
* <center><img src="images/convex_polygon.png"/></center><br>
|
|
12
12
|
* A polygon's `winding` is clockwise iff its vertices (points) are declared turning to the right. The image above shows COUNTERCLOCKWISE winding.
|
|
13
|
-
* @class Polygon
|
|
14
|
-
* @memberof me
|
|
15
|
-
* @param {number} x origin point of the Polygon
|
|
16
|
-
* @param {number} y origin point of the Polygon
|
|
17
|
-
* @param {me.Vector2d[]} points array of vector defining the Polygon
|
|
18
13
|
*/
|
|
19
14
|
|
|
20
15
|
class Polygon {
|
|
21
16
|
|
|
17
|
+
/**
|
|
18
|
+
* @param {number} x origin point of the Polygon
|
|
19
|
+
* @param {number} y origin point of the Polygon
|
|
20
|
+
* @param {Vector2d[]} points array of vector defining the Polygon
|
|
21
|
+
*/
|
|
22
22
|
constructor(x, y, points) {
|
|
23
23
|
/**
|
|
24
24
|
* origin point of the Polygon
|
|
25
25
|
* @public
|
|
26
|
-
* @type {
|
|
26
|
+
* @type {Vector2d}
|
|
27
27
|
* @name pos
|
|
28
|
-
* @memberof
|
|
28
|
+
* @memberof Polygon#
|
|
29
29
|
*/
|
|
30
30
|
this.pos = new Vector2d();
|
|
31
31
|
|
|
32
32
|
/**
|
|
33
33
|
* The bounding rectangle for this shape
|
|
34
34
|
* @ignore
|
|
35
|
-
* @type {
|
|
35
|
+
* @type {Bounds}
|
|
36
36
|
* @name _bounds
|
|
37
|
-
* @memberof
|
|
37
|
+
* @memberof Polygon#
|
|
38
38
|
*/
|
|
39
39
|
this._bounds;
|
|
40
40
|
|
|
@@ -42,9 +42,9 @@ class Polygon {
|
|
|
42
42
|
* Array of points defining the Polygon <br>
|
|
43
43
|
* Note: If you manually change `points`, you **must** call `recalc`afterwards so that the changes get applied correctly.
|
|
44
44
|
* @public
|
|
45
|
-
* @type {
|
|
45
|
+
* @type {Vector2d[]}
|
|
46
46
|
* @name points
|
|
47
|
-
* @memberof
|
|
47
|
+
* @memberof Polygon#
|
|
48
48
|
*/
|
|
49
49
|
this.points = [];
|
|
50
50
|
|
|
@@ -83,12 +83,12 @@ class Polygon {
|
|
|
83
83
|
/**
|
|
84
84
|
* set new value to the Polygon
|
|
85
85
|
* @name setShape
|
|
86
|
-
* @memberof
|
|
86
|
+
* @memberof Polygon.prototype
|
|
87
87
|
* @function
|
|
88
88
|
* @param {number} x position of the Polygon
|
|
89
89
|
* @param {number} y position of the Polygon
|
|
90
|
-
* @param {
|
|
91
|
-
* @returns {
|
|
90
|
+
* @param {Vector2d[]|number[]} points array of vector or vertice defining the Polygon
|
|
91
|
+
* @returns {Polygon} this instance for objecf chaining
|
|
92
92
|
*/
|
|
93
93
|
setShape(x, y, points) {
|
|
94
94
|
this.pos.set(x, y);
|
|
@@ -99,10 +99,10 @@ class Polygon {
|
|
|
99
99
|
/**
|
|
100
100
|
* set the vertices defining this Polygon
|
|
101
101
|
* @name setVertices
|
|
102
|
-
* @memberof
|
|
102
|
+
* @memberof Polygon.prototype
|
|
103
103
|
* @function
|
|
104
|
-
* @param {
|
|
105
|
-
* @returns {
|
|
104
|
+
* @param {Vector2d[]} vertices array of vector or vertice defining the Polygon
|
|
105
|
+
* @returns {Polygon} this instance for objecf chaining
|
|
106
106
|
*/
|
|
107
107
|
setVertices(vertices) {
|
|
108
108
|
|
|
@@ -139,10 +139,10 @@ class Polygon {
|
|
|
139
139
|
/**
|
|
140
140
|
* apply the given transformation matrix to this Polygon
|
|
141
141
|
* @name transform
|
|
142
|
-
* @memberof
|
|
142
|
+
* @memberof Polygon.prototype
|
|
143
143
|
* @function
|
|
144
|
-
* @param {
|
|
145
|
-
* @returns {
|
|
144
|
+
* @param {Matrix2d} m the transformation matrix
|
|
145
|
+
* @returns {Polygon} Reference to this object for method chaining
|
|
146
146
|
*/
|
|
147
147
|
transform(m) {
|
|
148
148
|
var points = this.points;
|
|
@@ -158,9 +158,9 @@ class Polygon {
|
|
|
158
158
|
/**
|
|
159
159
|
* apply an isometric projection to this shape
|
|
160
160
|
* @name toIso
|
|
161
|
-
* @memberof
|
|
161
|
+
* @memberof Polygon.prototype
|
|
162
162
|
* @function
|
|
163
|
-
* @returns {
|
|
163
|
+
* @returns {Polygon} Reference to this object for method chaining
|
|
164
164
|
*/
|
|
165
165
|
toIso() {
|
|
166
166
|
return this.rotate(Math.PI / 4).scale(Math.SQRT2, Math.SQRT1_2);
|
|
@@ -169,9 +169,9 @@ class Polygon {
|
|
|
169
169
|
/**
|
|
170
170
|
* apply a 2d projection to this shape
|
|
171
171
|
* @name to2d
|
|
172
|
-
* @memberof
|
|
172
|
+
* @memberof Polygon.prototype
|
|
173
173
|
* @function
|
|
174
|
-
* @returns {
|
|
174
|
+
* @returns {Polygon} Reference to this object for method chaining
|
|
175
175
|
*/
|
|
176
176
|
to2d() {
|
|
177
177
|
return this.scale(Math.SQRT1_2, Math.SQRT2).rotate(-Math.PI / 4);
|
|
@@ -180,11 +180,11 @@ class Polygon {
|
|
|
180
180
|
/**
|
|
181
181
|
* Rotate this Polygon (counter-clockwise) by the specified angle (in radians).
|
|
182
182
|
* @name rotate
|
|
183
|
-
* @memberof
|
|
183
|
+
* @memberof Polygon.prototype
|
|
184
184
|
* @function
|
|
185
185
|
* @param {number} angle The angle to rotate (in radians)
|
|
186
|
-
* @param {
|
|
187
|
-
* @returns {
|
|
186
|
+
* @param {Vector2d|ObservableVector2d} [v] an optional point to rotate around
|
|
187
|
+
* @returns {Polygon} Reference to this object for method chaining
|
|
188
188
|
*/
|
|
189
189
|
rotate(angle, v) {
|
|
190
190
|
if (angle !== 0) {
|
|
@@ -202,11 +202,11 @@ class Polygon {
|
|
|
202
202
|
/**
|
|
203
203
|
* Scale this Polygon by the given scalar.
|
|
204
204
|
* @name scale
|
|
205
|
-
* @memberof
|
|
205
|
+
* @memberof Polygon.prototype
|
|
206
206
|
* @function
|
|
207
207
|
* @param {number} x
|
|
208
208
|
* @param {number} [y=x]
|
|
209
|
-
* @returns {
|
|
209
|
+
* @returns {Polygon} Reference to this object for method chaining
|
|
210
210
|
*/
|
|
211
211
|
scale(x, y) {
|
|
212
212
|
y = typeof (y) !== "undefined" ? y : x;
|
|
@@ -224,10 +224,10 @@ class Polygon {
|
|
|
224
224
|
/**
|
|
225
225
|
* Scale this Polygon by the given vector
|
|
226
226
|
* @name scaleV
|
|
227
|
-
* @memberof
|
|
227
|
+
* @memberof Polygon.prototype
|
|
228
228
|
* @function
|
|
229
|
-
* @param {
|
|
230
|
-
* @returns {
|
|
229
|
+
* @param {Vector2d} v
|
|
230
|
+
* @returns {Polygon} Reference to this object for method chaining
|
|
231
231
|
*/
|
|
232
232
|
scaleV(v) {
|
|
233
233
|
return this.scale(v.x, v.y);
|
|
@@ -237,9 +237,9 @@ class Polygon {
|
|
|
237
237
|
* Computes the calculated collision polygon.
|
|
238
238
|
* This **must** be called if the `points` array, `angle`, or `offset` is modified manually.
|
|
239
239
|
* @name recalc
|
|
240
|
-
* @memberof
|
|
240
|
+
* @memberof Polygon.prototype
|
|
241
241
|
* @function
|
|
242
|
-
* @returns {
|
|
242
|
+
* @returns {Polygon} Reference to this object for method chaining
|
|
243
243
|
*/
|
|
244
244
|
recalc() {
|
|
245
245
|
var i;
|
|
@@ -281,7 +281,7 @@ class Polygon {
|
|
|
281
281
|
/**
|
|
282
282
|
* returns a list of indices for all triangles defined in this polygon
|
|
283
283
|
* @name getIndices
|
|
284
|
-
* @memberof
|
|
284
|
+
* @memberof Polygon.prototype
|
|
285
285
|
* @function
|
|
286
286
|
* @returns {Array} an array of vertex indices for all triangles forming this polygon.
|
|
287
287
|
*/
|
|
@@ -295,7 +295,7 @@ class Polygon {
|
|
|
295
295
|
/**
|
|
296
296
|
* Returns true if the vertices composing this polygon form a convex shape (vertices must be in clockwise order).
|
|
297
297
|
* @name isConvex
|
|
298
|
-
* @memberof
|
|
298
|
+
* @memberof Polygon.prototype
|
|
299
299
|
* @function
|
|
300
300
|
* @returns {boolean} true if the vertices are convex, false if not, null if not computable
|
|
301
301
|
*/
|
|
@@ -342,19 +342,19 @@ class Polygon {
|
|
|
342
342
|
/**
|
|
343
343
|
* translate the Polygon by the specified offset
|
|
344
344
|
* @name translate
|
|
345
|
-
* @memberof
|
|
345
|
+
* @memberof Polygon.prototype
|
|
346
346
|
* @function
|
|
347
347
|
* @param {number} x x offset
|
|
348
348
|
* @param {number} y y offset
|
|
349
|
-
* @returns {
|
|
349
|
+
* @returns {Polygon} this Polygon
|
|
350
350
|
*/
|
|
351
351
|
/**
|
|
352
352
|
* translate the Polygon by the specified vector
|
|
353
353
|
* @name translate
|
|
354
|
-
* @memberof
|
|
354
|
+
* @memberof Polygon.prototype
|
|
355
355
|
* @function
|
|
356
|
-
* @param {
|
|
357
|
-
* @returns {
|
|
356
|
+
* @param {Vector2d} v vector offset
|
|
357
|
+
* @returns {Polygon} Reference to this object for method chaining
|
|
358
358
|
*/
|
|
359
359
|
translate() {
|
|
360
360
|
var _x, _y;
|
|
@@ -379,14 +379,14 @@ class Polygon {
|
|
|
379
379
|
/**
|
|
380
380
|
* Shifts the Polygon to the given position vector.
|
|
381
381
|
* @name shift
|
|
382
|
-
* @memberof
|
|
382
|
+
* @memberof Polygon
|
|
383
383
|
* @function
|
|
384
|
-
* @param {
|
|
384
|
+
* @param {Vector2d} position
|
|
385
385
|
*/
|
|
386
386
|
/**
|
|
387
387
|
* Shifts the Polygon to the given x, y position.
|
|
388
388
|
* @name shift
|
|
389
|
-
* @memberof
|
|
389
|
+
* @memberof Polygon
|
|
390
390
|
* @function
|
|
391
391
|
* @param {number} x
|
|
392
392
|
* @param {number} y
|
|
@@ -412,9 +412,9 @@ class Polygon {
|
|
|
412
412
|
* (Note: it is highly recommended to first do a hit test on the corresponding <br>
|
|
413
413
|
* bounding rect, as the function can be highly consuming with complex shapes)
|
|
414
414
|
* @name contains
|
|
415
|
-
* @memberof
|
|
415
|
+
* @memberof Polygon.prototype
|
|
416
416
|
* @function
|
|
417
|
-
* @param
|
|
417
|
+
* @param {Vector2d} point
|
|
418
418
|
* @returns {boolean} true if contains
|
|
419
419
|
*/
|
|
420
420
|
|
|
@@ -423,7 +423,7 @@ class Polygon {
|
|
|
423
423
|
* (Note: it is highly recommended to first do a hit test on the corresponding <br>
|
|
424
424
|
* bounding rect, as the function can be highly consuming with complex shapes)
|
|
425
425
|
* @name contains
|
|
426
|
-
* @memberof
|
|
426
|
+
* @memberof Polygon.prototype
|
|
427
427
|
* @function
|
|
428
428
|
* @param {number} x x coordinate
|
|
429
429
|
* @param {number} y y coordinate
|
|
@@ -461,9 +461,9 @@ class Polygon {
|
|
|
461
461
|
/**
|
|
462
462
|
* returns the bounding box for this shape, the smallest Rectangle object completely containing this shape.
|
|
463
463
|
* @name getBounds
|
|
464
|
-
* @memberof
|
|
464
|
+
* @memberof Polygon.prototype
|
|
465
465
|
* @function
|
|
466
|
-
* @returns {
|
|
466
|
+
* @returns {Bounds} this shape bounding box Rectangle object
|
|
467
467
|
*/
|
|
468
468
|
getBounds() {
|
|
469
469
|
if (typeof this._bounds === "undefined") {
|
|
@@ -476,9 +476,9 @@ class Polygon {
|
|
|
476
476
|
* update the bounding box for this shape.
|
|
477
477
|
* @ignore
|
|
478
478
|
* @name updateBounds
|
|
479
|
-
* @memberof
|
|
479
|
+
* @memberof Polygon.prototype
|
|
480
480
|
* @function
|
|
481
|
-
* @returns {
|
|
481
|
+
* @returns {Bounds} this shape bounding box Rectangle object
|
|
482
482
|
*/
|
|
483
483
|
updateBounds() {
|
|
484
484
|
var bounds = this.getBounds();
|
|
@@ -492,9 +492,9 @@ class Polygon {
|
|
|
492
492
|
/**
|
|
493
493
|
* clone this Polygon
|
|
494
494
|
* @name clone
|
|
495
|
-
* @memberof
|
|
495
|
+
* @memberof Polygon.prototype
|
|
496
496
|
* @function
|
|
497
|
-
* @returns {
|
|
497
|
+
* @returns {Polygon} new Polygon
|
|
498
498
|
*/
|
|
499
499
|
clone() {
|
|
500
500
|
var copy = [];
|
|
@@ -4,17 +4,15 @@ import Polygon from "./poly.js";
|
|
|
4
4
|
/**
|
|
5
5
|
* @classdesc
|
|
6
6
|
* a rectangle Object
|
|
7
|
-
* @
|
|
8
|
-
* @augments me.Polygon
|
|
9
|
-
* @memberof me
|
|
10
|
-
* @param {number} x position of the Rectangle
|
|
11
|
-
* @param {number} y position of the Rectangle
|
|
12
|
-
* @param {number} w width of the rectangle
|
|
13
|
-
* @param {number} h height of the rectangle
|
|
7
|
+
* @augments Polygon
|
|
14
8
|
*/
|
|
15
|
-
|
|
16
9
|
class Rect extends Polygon {
|
|
17
|
-
|
|
10
|
+
/**
|
|
11
|
+
* @param {number} x position of the Rectangle
|
|
12
|
+
* @param {number} y position of the Rectangle
|
|
13
|
+
* @param {number} w width of the rectangle
|
|
14
|
+
* @param {number} h height of the rectangle
|
|
15
|
+
*/
|
|
18
16
|
constructor(x, y, w, h) {
|
|
19
17
|
// parent constructor
|
|
20
18
|
super(x, y, [
|
|
@@ -34,13 +32,13 @@ class Rect extends Polygon {
|
|
|
34
32
|
/**
|
|
35
33
|
* set new value to the rectangle shape
|
|
36
34
|
* @name setShape
|
|
37
|
-
* @memberof
|
|
35
|
+
* @memberof Rect.prototype
|
|
38
36
|
* @function
|
|
39
37
|
* @param {number} x position of the Rectangle
|
|
40
38
|
* @param {number} y position of the Rectangle
|
|
41
|
-
* @param {number|
|
|
39
|
+
* @param {number|Vector2d[]} w width of the rectangle, or an array of vector defining the rectangle
|
|
42
40
|
* @param {number} [h] height of the rectangle, if a numeral width parameter is specified
|
|
43
|
-
* @returns {
|
|
41
|
+
* @returns {Rect} this rectangle
|
|
44
42
|
*/
|
|
45
43
|
setShape(x, y, w, h) {
|
|
46
44
|
var points = w; // assume w is an array by default
|
|
@@ -65,7 +63,7 @@ class Rect extends Polygon {
|
|
|
65
63
|
* @public
|
|
66
64
|
* @type {number}
|
|
67
65
|
* @name left
|
|
68
|
-
* @memberof
|
|
66
|
+
* @memberof Rect
|
|
69
67
|
*/
|
|
70
68
|
get left() {
|
|
71
69
|
return this.pos.x;
|
|
@@ -76,7 +74,7 @@ class Rect extends Polygon {
|
|
|
76
74
|
* @public
|
|
77
75
|
* @type {number}
|
|
78
76
|
* @name right
|
|
79
|
-
* @memberof
|
|
77
|
+
* @memberof Rect
|
|
80
78
|
*/
|
|
81
79
|
get right() {
|
|
82
80
|
var w = this.width;
|
|
@@ -88,7 +86,7 @@ class Rect extends Polygon {
|
|
|
88
86
|
* @public
|
|
89
87
|
* @type {number}
|
|
90
88
|
* @name top
|
|
91
|
-
* @memberof
|
|
89
|
+
* @memberof Rect
|
|
92
90
|
*/
|
|
93
91
|
get top() {
|
|
94
92
|
return this.pos.y;
|
|
@@ -99,7 +97,7 @@ class Rect extends Polygon {
|
|
|
99
97
|
* @public
|
|
100
98
|
* @type {number}
|
|
101
99
|
* @name bottom
|
|
102
|
-
* @memberof
|
|
100
|
+
* @memberof Rect
|
|
103
101
|
*/
|
|
104
102
|
get bottom() {
|
|
105
103
|
var h = this.height;
|
|
@@ -111,7 +109,7 @@ class Rect extends Polygon {
|
|
|
111
109
|
* @public
|
|
112
110
|
* @type {number}
|
|
113
111
|
* @name width
|
|
114
|
-
* @memberof
|
|
112
|
+
* @memberof Rect
|
|
115
113
|
*/
|
|
116
114
|
get width() {
|
|
117
115
|
return this.points[2].x;
|
|
@@ -127,7 +125,7 @@ class Rect extends Polygon {
|
|
|
127
125
|
* @public
|
|
128
126
|
* @type {number}
|
|
129
127
|
* @name height
|
|
130
|
-
* @memberof
|
|
128
|
+
* @memberof Rect
|
|
131
129
|
*/
|
|
132
130
|
get height() {
|
|
133
131
|
return this.points[2].y;
|
|
@@ -143,7 +141,7 @@ class Rect extends Polygon {
|
|
|
143
141
|
* @public
|
|
144
142
|
* @type {number}
|
|
145
143
|
* @name centerX
|
|
146
|
-
* @memberof
|
|
144
|
+
* @memberof Rect
|
|
147
145
|
*/
|
|
148
146
|
get centerX() {
|
|
149
147
|
if (isFinite(this.width)) {
|
|
@@ -161,7 +159,7 @@ class Rect extends Polygon {
|
|
|
161
159
|
* @public
|
|
162
160
|
* @type {number}
|
|
163
161
|
* @name centerY
|
|
164
|
-
* @memberof
|
|
162
|
+
* @memberof Rect
|
|
165
163
|
*/
|
|
166
164
|
get centerY() {
|
|
167
165
|
if (isFinite(this.height)) {
|
|
@@ -177,11 +175,11 @@ class Rect extends Polygon {
|
|
|
177
175
|
/**
|
|
178
176
|
* resize the rectangle
|
|
179
177
|
* @name resize
|
|
180
|
-
* @memberof
|
|
178
|
+
* @memberof Rect.prototype
|
|
181
179
|
* @function
|
|
182
180
|
* @param {number} w new width of the rectangle
|
|
183
181
|
* @param {number} h new height of the rectangle
|
|
184
|
-
* @returns {
|
|
182
|
+
* @returns {Rect} this rectangle
|
|
185
183
|
*/
|
|
186
184
|
resize(w, h) {
|
|
187
185
|
this.width = w;
|
|
@@ -192,11 +190,11 @@ class Rect extends Polygon {
|
|
|
192
190
|
/**
|
|
193
191
|
* scale the rectangle
|
|
194
192
|
* @name scale
|
|
195
|
-
* @memberof
|
|
193
|
+
* @memberof Rect.prototype
|
|
196
194
|
* @function
|
|
197
195
|
* @param {number} x a number representing the abscissa of the scaling vector.
|
|
198
196
|
* @param {number} [y=x] a number representing the ordinate of the scaling vector.
|
|
199
|
-
* @returns {
|
|
197
|
+
* @returns {Rect} this rectangle
|
|
200
198
|
*/
|
|
201
199
|
scale(x, y = x) {
|
|
202
200
|
this.width *= x;
|
|
@@ -207,9 +205,9 @@ class Rect extends Polygon {
|
|
|
207
205
|
/**
|
|
208
206
|
* clone this rectangle
|
|
209
207
|
* @name clone
|
|
210
|
-
* @memberof
|
|
208
|
+
* @memberof Rect.prototype
|
|
211
209
|
* @function
|
|
212
|
-
* @returns {
|
|
210
|
+
* @returns {Rect} new rectangle
|
|
213
211
|
*/
|
|
214
212
|
clone() {
|
|
215
213
|
return new Rect(this.pos.x, this.pos.y, this.width, this.height);
|
|
@@ -218,10 +216,10 @@ class Rect extends Polygon {
|
|
|
218
216
|
/**
|
|
219
217
|
* copy the position and size of the given rectangle into this one
|
|
220
218
|
* @name copy
|
|
221
|
-
* @memberof
|
|
219
|
+
* @memberof Rect.prototype
|
|
222
220
|
* @function
|
|
223
|
-
* @param {
|
|
224
|
-
* @returns {
|
|
221
|
+
* @param {Rect} rect Source rectangle
|
|
222
|
+
* @returns {Rect} new rectangle
|
|
225
223
|
*/
|
|
226
224
|
copy(rect) {
|
|
227
225
|
return this.setShape(rect.pos.x, rect.pos.y, rect.width, rect.height);
|
|
@@ -230,10 +228,10 @@ class Rect extends Polygon {
|
|
|
230
228
|
/**
|
|
231
229
|
* merge this rectangle with another one
|
|
232
230
|
* @name union
|
|
233
|
-
* @memberof
|
|
231
|
+
* @memberof Rect.prototype
|
|
234
232
|
* @function
|
|
235
|
-
* @param {
|
|
236
|
-
* @returns {
|
|
233
|
+
* @param {Rect} rect other rectangle to union with
|
|
234
|
+
* @returns {Rect} the union(ed) rectangle
|
|
237
235
|
*/
|
|
238
236
|
union(rect) {
|
|
239
237
|
var x1 = Math.min(this.left, rect.left);
|
|
@@ -252,9 +250,9 @@ class Rect extends Polygon {
|
|
|
252
250
|
/**
|
|
253
251
|
* check if this rectangle is intersecting with the specified one
|
|
254
252
|
* @name overlaps
|
|
255
|
-
* @memberof
|
|
253
|
+
* @memberof Rect.prototype
|
|
256
254
|
* @function
|
|
257
|
-
* @param
|
|
255
|
+
* @param {Rect} rect
|
|
258
256
|
* @returns {boolean} true if overlaps
|
|
259
257
|
*/
|
|
260
258
|
overlaps(rect) {
|
|
@@ -269,16 +267,16 @@ class Rect extends Polygon {
|
|
|
269
267
|
/**
|
|
270
268
|
* Returns true if the rectangle contains the given rectangle
|
|
271
269
|
* @name contains
|
|
272
|
-
* @memberof
|
|
270
|
+
* @memberof Rect.prototype
|
|
273
271
|
* @function
|
|
274
|
-
* @param {
|
|
272
|
+
* @param {Rect} rect
|
|
275
273
|
* @returns {boolean} true if contains
|
|
276
274
|
*/
|
|
277
275
|
|
|
278
276
|
/**
|
|
279
277
|
* Returns true if the rectangle contains the given point
|
|
280
278
|
* @name contains
|
|
281
|
-
* @memberof
|
|
279
|
+
* @memberof Rect.prototype
|
|
282
280
|
* @function
|
|
283
281
|
* @param {number} x x coordinate
|
|
284
282
|
* @param {number} y y coordinate
|
|
@@ -288,9 +286,9 @@ class Rect extends Polygon {
|
|
|
288
286
|
/**
|
|
289
287
|
* Returns true if the rectangle contains the given point
|
|
290
288
|
* @name contains
|
|
291
|
-
* @memberof
|
|
289
|
+
* @memberof Rect
|
|
292
290
|
* @function
|
|
293
|
-
* @param {
|
|
291
|
+
* @param {Vector2d} point
|
|
294
292
|
* @returns {boolean} true if contains
|
|
295
293
|
*/
|
|
296
294
|
contains() {
|
|
@@ -324,9 +322,9 @@ class Rect extends Polygon {
|
|
|
324
322
|
/**
|
|
325
323
|
* check if this rectangle is identical to the specified one
|
|
326
324
|
* @name equals
|
|
327
|
-
* @memberof
|
|
325
|
+
* @memberof Rect.prototype
|
|
328
326
|
* @function
|
|
329
|
-
* @param
|
|
327
|
+
* @param {Rect} rect
|
|
330
328
|
* @returns {boolean} true if equals
|
|
331
329
|
*/
|
|
332
330
|
equals(rect) {
|
|
@@ -341,7 +339,7 @@ class Rect extends Polygon {
|
|
|
341
339
|
/**
|
|
342
340
|
* determines whether all coordinates of this rectangle are finite numbers.
|
|
343
341
|
* @name isFinite
|
|
344
|
-
* @memberof
|
|
342
|
+
* @memberof Rect.prototype
|
|
345
343
|
* @function
|
|
346
344
|
* @returns {boolean} false if all coordinates are positive or negative Infinity or NaN; otherwise, true.
|
|
347
345
|
*/
|
|
@@ -352,9 +350,9 @@ class Rect extends Polygon {
|
|
|
352
350
|
/**
|
|
353
351
|
* Returns a polygon whose edges are the same as this box.
|
|
354
352
|
* @name toPolygon
|
|
355
|
-
* @memberof
|
|
353
|
+
* @memberof Rect.prototype
|
|
356
354
|
* @function
|
|
357
|
-
* @returns {
|
|
355
|
+
* @returns {Polygon} a new Polygon that represents this rectangle.
|
|
358
356
|
*/
|
|
359
357
|
toPolygon() {
|
|
360
358
|
return new Polygon(
|
package/src/index.js
CHANGED
|
@@ -41,6 +41,7 @@ import WebGLCompositor from "./video/webgl/webgl_compositor.js";
|
|
|
41
41
|
import Renderer from "./video/renderer.js";
|
|
42
42
|
import WebGLRenderer from "./video/webgl/webgl_renderer.js";
|
|
43
43
|
import CanvasRenderer from "./video/canvas/canvas_renderer.js";
|
|
44
|
+
import { TextureAtlas } from "./video/texture.js";
|
|
44
45
|
import Renderable from "./renderable/renderable.js";
|
|
45
46
|
import Text from "./text/text.js";
|
|
46
47
|
import BitmapText from "./text/bitmaptext.js";
|
|
@@ -78,24 +79,15 @@ import DroptargetEntity from "./entity/droptarget.js";
|
|
|
78
79
|
// alias and wrapper for deprecated API
|
|
79
80
|
import * as deprecated from "./lang/deprecated.js";
|
|
80
81
|
|
|
81
|
-
/**
|
|
82
|
-
* (<b>m</b>)elonJS (<b>e</b>)ngine : All melonJS functions are defined inside this namespace.
|
|
83
|
-
* You generally should not add new properties to this namespace as it may be overwritten in future versions.
|
|
84
|
-
* @namespace me
|
|
85
|
-
*/
|
|
86
|
-
|
|
87
82
|
/**
|
|
88
83
|
* current melonJS version
|
|
89
84
|
* @static
|
|
90
85
|
* @constant
|
|
91
|
-
* @memberof me
|
|
92
86
|
* @name version
|
|
93
87
|
* @type {string}
|
|
94
88
|
*/
|
|
95
89
|
export const version = "__VERSION__";
|
|
96
90
|
|
|
97
|
-
// namespace "me" will be created by rollup automatically
|
|
98
|
-
|
|
99
91
|
// export all utility function
|
|
100
92
|
export {
|
|
101
93
|
audio,
|
|
@@ -137,6 +129,7 @@ export {
|
|
|
137
129
|
Renderer,
|
|
138
130
|
WebGLRenderer,
|
|
139
131
|
CanvasRenderer,
|
|
132
|
+
TextureAtlas,
|
|
140
133
|
Renderable,
|
|
141
134
|
Body,
|
|
142
135
|
Bounds,
|
|
@@ -184,7 +177,6 @@ export {
|
|
|
184
177
|
* @type {boolean}
|
|
185
178
|
* @default false
|
|
186
179
|
* @readonly
|
|
187
|
-
* @memberof me
|
|
188
180
|
*/
|
|
189
181
|
export var initialized = false;
|
|
190
182
|
|
|
@@ -192,8 +184,7 @@ export var initialized = false;
|
|
|
192
184
|
* disable melonJS auto-initialization
|
|
193
185
|
* @type {boolean}
|
|
194
186
|
* @default false
|
|
195
|
-
* @see
|
|
196
|
-
* @memberof me
|
|
187
|
+
* @see boot
|
|
197
188
|
*/
|
|
198
189
|
export var skipAutoInit = false;
|
|
199
190
|
|
|
@@ -202,8 +193,7 @@ export var skipAutoInit = false;
|
|
|
202
193
|
* this is automatically called unless me.skipAutoInit is set to true,
|
|
203
194
|
* to allow asynchronous loaders to work.
|
|
204
195
|
* @name boot
|
|
205
|
-
* @
|
|
206
|
-
* @see me.skipAutoInit
|
|
196
|
+
* @see skipAutoInit
|
|
207
197
|
* @public
|
|
208
198
|
* @function
|
|
209
199
|
*/
|
package/src/input/gamepad.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {getBindingKey, triggerKeyEvent} from "./keyboard.js";
|
|
2
2
|
import * as event from "./../system/event.js";
|
|
3
3
|
|
|
4
|
+
|
|
4
5
|
// Analog deadzone
|
|
5
6
|
var deadzone = 0.1;
|
|
6
7
|
|
|
@@ -284,7 +285,7 @@ window.addEventListener("gamepaddisconnected", function (e) {
|
|
|
284
285
|
* Namespace for standard gamepad mapping constants
|
|
285
286
|
* @public
|
|
286
287
|
* @namespace GAMEPAD
|
|
287
|
-
* @memberof
|
|
288
|
+
* @memberof input
|
|
288
289
|
*/
|
|
289
290
|
export var GAMEPAD = {
|
|
290
291
|
/**
|
|
@@ -297,7 +298,7 @@ export var GAMEPAD = {
|
|
|
297
298
|
* @public
|
|
298
299
|
* @name AXES
|
|
299
300
|
* @enum {number}
|
|
300
|
-
* @memberof
|
|
301
|
+
* @memberof input.GAMEPAD
|
|
301
302
|
* @see https://w3c.github.io/gamepad/#remapping
|
|
302
303
|
*/
|
|
303
304
|
"AXES" : {
|
|
@@ -324,7 +325,7 @@ export var GAMEPAD = {
|
|
|
324
325
|
* @public
|
|
325
326
|
* @name BUTTONS
|
|
326
327
|
* @enum {number}
|
|
327
|
-
* @memberof
|
|
328
|
+
* @memberof input.GAMEPAD
|
|
328
329
|
* @see https://w3c.github.io/gamepad/#remapping
|
|
329
330
|
*/
|
|
330
331
|
"BUTTONS" : {
|
|
@@ -357,15 +358,15 @@ export var GAMEPAD = {
|
|
|
357
358
|
/**
|
|
358
359
|
* Associate a gamepad event to a keycode
|
|
359
360
|
* @name bindGamepad
|
|
360
|
-
* @memberof
|
|
361
|
+
* @memberof input
|
|
361
362
|
* @public
|
|
362
363
|
* @function
|
|
363
364
|
* @param {number} index Gamepad index
|
|
364
365
|
* @param {object} button Button/Axis definition
|
|
365
366
|
* @param {string} button.type "buttons" or "axes"
|
|
366
|
-
* @param {
|
|
367
|
+
* @param {number} button.code button or axis code id (See {@link input.GAMEPAD.BUTTONS}, {@link input.GAMEPAD.AXES})
|
|
367
368
|
* @param {number} [button.threshold=1] value indicating when the axis should trigger the keycode (e.g. -0.5 or 0.5)
|
|
368
|
-
* @param {
|
|
369
|
+
* @param {number} keyCode (See {@link input.KEY})
|
|
369
370
|
* @example
|
|
370
371
|
* // enable the keyboard
|
|
371
372
|
* me.input.bindKey(me.input.KEY.X, "shoot");
|
|
@@ -432,11 +433,11 @@ export function bindGamepad(index, button, keyCode) {
|
|
|
432
433
|
/**
|
|
433
434
|
* unbind the defined keycode
|
|
434
435
|
* @name unbindGamepad
|
|
435
|
-
* @memberof
|
|
436
|
+
* @memberof input
|
|
436
437
|
* @public
|
|
437
438
|
* @function
|
|
438
439
|
* @param {number} index Gamepad index
|
|
439
|
-
* @param {
|
|
440
|
+
* @param {number} button (See {@link input.GAMEPAD.BUTTONS})
|
|
440
441
|
* @example
|
|
441
442
|
* me.input.unbindGamepad(0, me.input.GAMEPAD.BUTTONS.FACE_1);
|
|
442
443
|
*/
|
|
@@ -451,7 +452,7 @@ export function unbindGamepad(index, button) {
|
|
|
451
452
|
* Set deadzone for analog gamepad inputs<br>
|
|
452
453
|
* The default deadzone is 0.1 (10%) Analog values less than this will be ignored
|
|
453
454
|
* @name setGamepadDeadzone
|
|
454
|
-
* @memberof
|
|
455
|
+
* @memberof input
|
|
455
456
|
* @public
|
|
456
457
|
* @function
|
|
457
458
|
* @param {number} value Deadzone value
|
|
@@ -465,7 +466,7 @@ export function setGamepadDeadzone(value) {
|
|
|
465
466
|
* see below for the default mapping : <br>
|
|
466
467
|
* <center><img src="images/gamepad_diagram.png"/></center><br>
|
|
467
468
|
* @name setGamepadMapping
|
|
468
|
-
* @memberof
|
|
469
|
+
* @memberof input
|
|
469
470
|
* @public
|
|
470
471
|
* @function
|
|
471
472
|
* @param {string} id Gamepad id string
|