melonjs 10.2.2 → 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.
Files changed (95) hide show
  1. package/README.md +6 -6
  2. package/dist/melonjs.js +2907 -3383
  3. package/dist/melonjs.min.js +4 -4
  4. package/dist/melonjs.module.d.ts +3620 -4528
  5. package/dist/melonjs.module.js +3210 -3331
  6. package/package.json +19 -19
  7. package/src/audio/audio.js +30 -31
  8. package/src/camera/camera2d.js +47 -58
  9. package/src/entity/draggable.js +11 -21
  10. package/src/entity/droptarget.js +12 -22
  11. package/src/entity/entity.js +32 -38
  12. package/src/game.js +21 -22
  13. package/src/{shapes → geometries}/ellipse.js +40 -47
  14. package/src/{shapes → geometries}/line.js +9 -12
  15. package/src/{shapes → geometries}/poly.js +100 -53
  16. package/src/{shapes → geometries}/rectangle.js +42 -45
  17. package/src/index.js +9 -20
  18. package/src/input/gamepad.js +11 -10
  19. package/src/input/input.js +2 -3
  20. package/src/input/keyboard.js +113 -113
  21. package/src/input/pointer.js +61 -29
  22. package/src/input/pointerevent.js +92 -29
  23. package/src/lang/deprecated.js +44 -14
  24. package/src/level/level.js +23 -24
  25. package/src/level/tiled/TMXGroup.js +7 -9
  26. package/src/level/tiled/TMXLayer.js +30 -33
  27. package/src/level/tiled/TMXObject.js +59 -53
  28. package/src/level/tiled/TMXTile.js +18 -19
  29. package/src/level/tiled/TMXTileMap.js +38 -46
  30. package/src/level/tiled/TMXTileset.js +12 -16
  31. package/src/level/tiled/TMXTilesetGroup.js +9 -10
  32. package/src/level/tiled/renderer/TMXHexagonalRenderer.js +7 -9
  33. package/src/level/tiled/renderer/TMXIsometricRenderer.js +7 -9
  34. package/src/level/tiled/renderer/TMXOrthogonalRenderer.js +4 -6
  35. package/src/level/tiled/renderer/TMXRenderer.js +24 -26
  36. package/src/level/tiled/renderer/TMXStaggeredRenderer.js +1 -5
  37. package/src/loader/loader.js +17 -16
  38. package/src/loader/loadingscreen.js +8 -10
  39. package/src/math/color.js +47 -67
  40. package/src/math/math.js +15 -16
  41. package/src/math/matrix2.js +53 -59
  42. package/src/math/matrix3.js +56 -63
  43. package/src/math/observable_vector2.js +87 -77
  44. package/src/math/observable_vector3.js +97 -80
  45. package/src/math/vector2.js +107 -97
  46. package/src/math/vector3.js +116 -100
  47. package/src/particles/emitter.js +66 -76
  48. package/src/particles/particle.js +4 -6
  49. package/src/particles/particlecontainer.js +2 -4
  50. package/src/physics/body.js +47 -146
  51. package/src/physics/bounds.js +48 -50
  52. package/src/physics/collision.js +13 -14
  53. package/src/physics/detector.js +14 -14
  54. package/src/physics/quadtree.js +18 -21
  55. package/src/physics/sat.js +30 -30
  56. package/src/physics/world.js +24 -29
  57. package/src/plugin/plugin.js +11 -15
  58. package/src/renderable/GUI.js +41 -47
  59. package/src/renderable/collectable.js +5 -10
  60. package/src/renderable/colorlayer.js +10 -15
  61. package/src/renderable/container.js +87 -73
  62. package/src/renderable/imagelayer.js +25 -32
  63. package/src/renderable/nineslicesprite.js +41 -42
  64. package/src/renderable/renderable.js +113 -124
  65. package/src/renderable/sprite.js +62 -69
  66. package/src/renderable/trigger.js +26 -32
  67. package/src/state/stage.js +13 -18
  68. package/src/state/state.js +26 -27
  69. package/src/system/device.js +76 -133
  70. package/src/system/event.js +81 -70
  71. package/src/system/pooling.js +11 -12
  72. package/src/system/save.js +3 -4
  73. package/src/system/timer.js +19 -20
  74. package/src/text/bitmaptext.js +57 -55
  75. package/src/text/bitmaptextdata.js +10 -11
  76. package/src/text/glyph.js +3 -0
  77. package/src/text/text.js +49 -55
  78. package/src/tweens/easing.js +1 -1
  79. package/src/tweens/interpolation.js +1 -1
  80. package/src/tweens/tween.js +44 -46
  81. package/src/utils/agent.js +3 -4
  82. package/src/utils/array.js +4 -5
  83. package/src/utils/file.js +3 -4
  84. package/src/utils/function.js +4 -5
  85. package/src/utils/string.js +7 -9
  86. package/src/utils/utils.js +4 -5
  87. package/src/video/canvas/canvas_renderer.js +60 -62
  88. package/src/video/renderer.js +53 -58
  89. package/src/video/texture.js +98 -112
  90. package/src/video/texture_cache.js +4 -6
  91. package/src/video/video.js +16 -17
  92. package/src/video/webgl/buffer/vertex.js +2 -2
  93. package/src/video/webgl/glshader.js +37 -39
  94. package/src/video/webgl/webgl_compositor.js +128 -110
  95. package/src/video/webgl/webgl_renderer.js +126 -106
@@ -1,7 +1,7 @@
1
1
  import Vector2d from "./../math/vector2.js";
2
- import Rect from "./../shapes/rectangle.js";
3
- import Ellipse from "./../shapes/ellipse.js";
4
- import Polygon from "./../shapes/poly.js";
2
+ import Rect from "./../geometries/rectangle.js";
3
+ import Ellipse from "./../geometries/ellipse.js";
4
+ import Polygon from "./../geometries/poly.js";
5
5
  import Bounds from "./bounds.js";
6
6
  import collision from "./collision.js";
7
7
  import * as arrayUtil from "./../utils/array.js";
@@ -11,47 +11,41 @@ import { world } from "./../game.js";
11
11
 
12
12
 
13
13
  /**
14
+ * @classdesc
14
15
  * a Generic Physic Body Object with some physic properties and behavior functionality, to as a member of a Renderable.
15
- * @class Body
16
- * @memberOf me
17
- * @constructor
18
- * @param {me.Renderable} ancestor the parent object this body is attached to
19
- * @param {me.Rect|me.Rect[]|me.Polygon|me.Polygon[]|me.Line|me.Line[]|me.Ellipse|me.Ellipse[]|me.Bounds|me.Bounds[]|object} [shapes] a initial shape, list of shapes, or JSON object defining the body
20
- * @param {Function} [onBodyUpdate] callback for when the body is updated (e.g. add/remove shapes)
21
16
  */
22
17
  class Body {
23
-
24
- constructor(parent, shapes, onBodyUpdate) {
18
+ /**
19
+ * @param {Renderable} ancestor the parent object this body is attached to
20
+ * @param {Rect|Rect[]|Polygon|Polygon[]|Line|Line[]|Ellipse|Ellipse[]|Bounds|Bounds[]|object} [shapes] a initial shape, list of shapes, or JSON object defining the body
21
+ * @param {Function} [onBodyUpdate] callback for when the body is updated (e.g. add/remove shapes)
22
+ */
23
+ constructor(ancestor, shapes, onBodyUpdate) {
25
24
 
26
25
  /**
27
26
  * a reference to the parent object that contains this body,
28
27
  * or undefined if it has not been added to one.
29
28
  * @public
30
- * @type {me.Renderable}
29
+ * @type {Renderable}
31
30
  * @default undefined
32
- * @name me.Body#ancestor
33
31
  */
34
- this.ancestor = parent;
32
+ this.ancestor = ancestor;
35
33
 
36
- /**
37
- * The AABB bounds box reprensenting this body
38
- * @public
39
- * @type {me.Bounds}
40
- * @name bounds
41
- * @memberOf me.Body
42
- */
43
34
  if (typeof this.bounds === "undefined") {
35
+ /**
36
+ * The AABB bounds box reprensenting this body
37
+ * @public
38
+ * @type {Bounds}
39
+ */
44
40
  this.bounds = new Bounds();
45
41
  }
46
42
 
47
- /**
48
- * The collision shapes of the body
49
- * @ignore
50
- * @type {me.Polygon[]|me.Line[]|me.Ellipse[]}
51
- * @name shapes
52
- * @memberOf me.Body
53
- */
54
43
  if (typeof this.shapes === "undefined") {
44
+ /**
45
+ * The collision shapes of the body
46
+ * @ignore
47
+ * @type {Polygon[]|Line[]|Ellipse[]}
48
+ */
55
49
  this.shapes = [];
56
50
  }
57
51
 
@@ -60,10 +54,8 @@ class Body {
60
54
  * (by default will collide with all entities)
61
55
  * @ignore
62
56
  * @type {number}
63
- * @default me.collision.types.ALL_OBJECT
64
- * @name collisionMask
65
- * @see me.collision.types
66
- * @memberOf me.Body
57
+ * @default collision.types.ALL_OBJECT
58
+ * @see collision.types
67
59
  */
68
60
  this.collisionMask = collision.types.ALL_OBJECT;
69
61
 
@@ -71,10 +63,8 @@ class Body {
71
63
  * define the collision type of the body for collision filtering
72
64
  * @public
73
65
  * @type {number}
74
- * @default me.collision.types.ENEMY_OBJECT
75
- * @name collisionType
76
- * @see me.collision.types
77
- * @memberOf me.Body
66
+ * @default collision.types.ENEMY_OBJECT
67
+ * @see collision.types
78
68
  * @example
79
69
  * // set the body collision type
80
70
  * myEntity.body.collisionType = me.collision.types.PLAYER_OBJECT;
@@ -84,10 +74,8 @@ class Body {
84
74
  /**
85
75
  * body velocity
86
76
  * @public
87
- * @type {me.Vector2d}
77
+ * @type {Vector2d}
88
78
  * @default <0,0>
89
- * @name vel
90
- * @memberOf me.Body
91
79
  */
92
80
  if (typeof this.vel === "undefined") {
93
81
  this.vel = new Vector2d();
@@ -98,11 +86,9 @@ class Body {
98
86
  * body force or acceleration (automatically) applied to the body.
99
87
  * when defining a force, user should also define a max velocity
100
88
  * @public
101
- * @type {me.Vector2d}
89
+ * @type {Vector2d}
102
90
  * @default <0,0>
103
- * @name force
104
- * @see me.Body.setMaxVelocity
105
- * @memberOf me.Body
91
+ * @see Body.setMaxVelocity
106
92
  * @example
107
93
  * // define a default maximum acceleration, initial force and friction
108
94
  * this.body.force.set(0, 0);
@@ -129,10 +115,8 @@ class Body {
129
115
  /**
130
116
  * body friction
131
117
  * @public
132
- * @type {me.Vector2d}
118
+ * @type {Vector2d}
133
119
  * @default <0,0>
134
- * @name friction
135
- * @memberOf me.Body
136
120
  */
137
121
  if (typeof this.friction === "undefined") {
138
122
  this.friction = new Vector2d();
@@ -145,8 +129,6 @@ class Body {
145
129
  * @public
146
130
  * @type {number}
147
131
  * @default 0
148
- * @name bounce
149
- * @memberOf me.Body
150
132
  */
151
133
  this.bounce = 0;
152
134
 
@@ -155,18 +137,14 @@ class Body {
155
137
  * @public
156
138
  * @type {number}
157
139
  * @default 1
158
- * @name mass
159
- * @memberOf me.Body
160
140
  */
161
141
  this.mass = 1;
162
142
 
163
143
  /**
164
144
  * max velocity (to limit body velocity)
165
145
  * @public
166
- * @type {me.Vector2d}
146
+ * @type {Vector2d}
167
147
  * @default <490,490>
168
- * @name maxVel
169
- * @memberOf me.Body
170
148
  */
171
149
  if (typeof this.maxVel === "undefined") {
172
150
  this.maxVel = new Vector2d();
@@ -181,8 +159,6 @@ class Body {
181
159
  * @public
182
160
  * @type {boolean}
183
161
  * @default false
184
- * @name isStatic
185
- * @memberOf me.Body
186
162
  */
187
163
  this.isStatic = false;
188
164
 
@@ -190,22 +166,18 @@ class Body {
190
166
  /**
191
167
  * The degree to which this body is affected by the world gravity
192
168
  * @public
193
- * @see me.World.gravity
169
+ * @see World.gravity
194
170
  * @type {number}
195
171
  * @default 1.0
196
- * @name gravityScale
197
- * @memberOf me.Body
198
172
  */
199
173
  this.gravityScale = 1.0;
200
174
 
201
175
  /**
202
176
  * If true this body won't be affected by the world gravity
203
177
  * @public
204
- * @see me.World.gravity
178
+ * @see World.gravity
205
179
  * @type {boolean}
206
180
  * @default false
207
- * @name ignoreGravity
208
- * @memberOf me.Body
209
181
  */
210
182
  this.ignoreGravity = false;
211
183
 
@@ -217,8 +189,6 @@ class Body {
217
189
  * @public
218
190
  * @type {boolean}
219
191
  * @default false
220
- * @name falling
221
- * @memberOf me.Body
222
192
  */
223
193
  this.falling = false;
224
194
 
@@ -229,8 +199,6 @@ class Body {
229
199
  * @public
230
200
  * @type {boolean}
231
201
  * @default false
232
- * @name jumping
233
- * @memberOf me.Body
234
202
  */
235
203
  this.jumping = false;
236
204
 
@@ -259,10 +227,6 @@ class Body {
259
227
  /**
260
228
  * set the body as a static body
261
229
  * static body do not move automatically and do not check againt collision with others
262
- * @name setStatic
263
- * @memberOf me.Body
264
- * @public
265
- * @function
266
230
  * @param {boolean} [isStatic=true]
267
231
  */
268
232
  setStatic(isStatic = true) {
@@ -272,11 +236,7 @@ class Body {
272
236
  /**
273
237
  * add a collision shape to this body <br>
274
238
  * (note: me.Rect objects will be converted to me.Polygon before being added)
275
- * @name addShape
276
- * @memberOf me.Body
277
- * @public
278
- * @function
279
- * @param {me.Rect|me.Polygon|me.Line|me.Ellipse|me.Bounds|object} shape a shape or JSON object
239
+ * @param {Rect|Polygon|Line|Ellipse|Bounds|object} shape a shape or JSON object
280
240
  * @returns {number} the shape array length
281
241
  * @example
282
242
  * // add a rectangle shape
@@ -326,11 +286,7 @@ class Body {
326
286
 
327
287
  /**
328
288
  * set the body vertices to the given one
329
- * @name setVertices
330
- * @memberOf me.Body
331
- * @public
332
- * @function
333
- * @param {me.Vector2d[]} vertices an array of me.Vector2d points defining a convex hull
289
+ * @param {Vector2d[]} vertices an array of me.Vector2d points defining a convex hull
334
290
  * @param {number} [index=0] the shape object for which to set the vertices
335
291
  * @param {boolean} [clear=true] either to reset the body definition before adding the new vertices
336
292
  */
@@ -353,11 +309,7 @@ class Body {
353
309
 
354
310
  /**
355
311
  * add the given vertices to the body shape
356
- * @name addVertices
357
- * @memberOf me.Body
358
- * @public
359
- * @function
360
- * @param {me.Vector2d[]} vertices an array of me.Vector2d points defining a convex hull
312
+ * @param {Vector2d[]} vertices an array of me.Vector2d points defining a convex hull
361
313
  * @param {number} [index=0] the shape object for which to set the vertices
362
314
  */
363
315
  addVertices(vertices, index = 0) {
@@ -367,10 +319,6 @@ class Body {
367
319
  /**
368
320
  * add collision mesh based on a JSON object
369
321
  * (this will also apply any physic properties defined in the given JSON file)
370
- * @name fromJSON
371
- * @memberOf me.Body
372
- * @public
373
- * @function
374
322
  * @param {object} json a JSON object as exported from a Physics Editor tool
375
323
  * @param {string} [id] an optional shape identifier within the given the json object
376
324
  * @see https://www.codeandweb.com/physicseditor
@@ -411,12 +359,8 @@ class Body {
411
359
 
412
360
  /**
413
361
  * return the collision shape at the given index
414
- * @name getShape
415
- * @memberOf me.Body
416
- * @public
417
- * @function
418
362
  * @param {number} [index=0] the shape object at the specified index
419
- * @returns {me.Polygon|me.Line|me.Ellipse} shape a shape object if defined
363
+ * @returns {Polygon|Line|Ellipse} shape a shape object if defined
420
364
  */
421
365
  getShape(index) {
422
366
  return this.shapes[index || 0];
@@ -424,10 +368,8 @@ class Body {
424
368
 
425
369
  /**
426
370
  * returns the AABB bounding box for this body
427
- * @name getBounds
428
- * @memberOf me.Body
429
371
  * @function
430
- * @returns {me.Bounds} bounding box Rectangle object
372
+ * @returns {Bounds} bounding box Rectangle object
431
373
  */
432
374
  getBounds() {
433
375
  return this.bounds;
@@ -435,11 +377,7 @@ class Body {
435
377
 
436
378
  /**
437
379
  * remove the specified shape from the body shape list
438
- * @name removeShape
439
- * @memberOf me.Body
440
- * @public
441
- * @function
442
- * @param {me.Polygon|me.Line|me.Ellipse} shape a shape object
380
+ * @param {Polygon|Line|Ellipse} shape a shape object
443
381
  * @returns {number} the shape array length
444
382
  */
445
383
  removeShape(shape) {
@@ -457,10 +395,6 @@ class Body {
457
395
 
458
396
  /**
459
397
  * remove the shape at the given index from the body shape list
460
- * @name removeShapeAt
461
- * @memberOf me.Body
462
- * @public
463
- * @function
464
398
  * @param {number} index the shape object at the specified index
465
399
  * @returns {number} the shape array length
466
400
  */
@@ -472,12 +406,8 @@ class Body {
472
406
  * By default all entities are able to collide with all other entities, <br>
473
407
  * but it's also possible to specify 'collision filters' to provide a finer <br>
474
408
  * control over which entities can collide with each other.
475
- * @name setCollisionMask
476
- * @memberOf me.Body
477
- * @public
478
- * @function
479
- * @see me.collision.types
480
- * @param {number} [bitmask = me.collision.types.ALL_OBJECT] the collision mask
409
+ * @see collision.types
410
+ * @param {number} [bitmask = collision.types.ALL_OBJECT] the collision mask
481
411
  * @example
482
412
  * // filter collision detection with collision shapes, enemies and collectables
483
413
  * myEntity.body.setCollisionMask(me.collision.types.WORLD_SHAPE | me.collision.types.ENEMY_OBJECT | me.collision.types.COLLECTABLE_OBJECT);
@@ -491,11 +421,7 @@ class Body {
491
421
 
492
422
  /**
493
423
  * define the collision type of the body for collision filtering
494
- * @name setCollisionType
495
- * @memberOf me.Body
496
- * @public
497
- * @function
498
- * @see me.collision.types
424
+ * @see collision.types
499
425
  * @param {number} type the collision type
500
426
  * @example
501
427
  * // set the body collision type
@@ -513,11 +439,7 @@ class Body {
513
439
 
514
440
  /**
515
441
  * the built-in function to solve the collision response
516
- * @protected
517
- * @name respondToCollision
518
- * @memberOf me.Body
519
- * @function
520
- * @param {me.collision.ResponseObject} response the collision response object
442
+ * @param {object} response the collision response object (see {@link collision.ResponseObject})
521
443
  */
522
444
  respondToCollision(response) {
523
445
  // the overlap vector
@@ -554,9 +476,6 @@ class Body {
554
476
  * - The current element being processed in the array <br>
555
477
  * - The index of element in the array. <br>
556
478
  * - The array forEach() was called upon. <br>
557
- * @name forEach
558
- * @memberOf me.Body.prototype
559
- * @function
560
479
  * @param {Function} callback fnction to execute on each element
561
480
  * @param {object} [thisArg] value to use as this(i.e reference Object) when executing callback.
562
481
  * @example
@@ -591,18 +510,12 @@ class Body {
591
510
 
592
511
  /**
593
512
  * Returns true if the any of the shape composing the body contains the given point.
594
- * @name contains
595
- * @memberOf me.Body
596
- * @function
597
- * @param {me.Vector2d} point
513
+ * @param {Vector2d} point
598
514
  * @returns {boolean} true if contains
599
515
  */
600
516
 
601
517
  /**
602
518
  * Returns true if the any of the shape composing the body contains the given point.
603
- * @name contains
604
- * @memberOf me.Body
605
- * @function
606
519
  * @param {number} x x coordinate
607
520
  * @param {number} y y coordinate
608
521
  * @returns {boolean} true if contains
@@ -634,12 +547,9 @@ class Body {
634
547
  /**
635
548
  * Rotate this body (counter-clockwise) by the specified angle (in radians).
636
549
  * Unless specified the body will be rotated around its center point
637
- * @name rotate
638
- * @memberOf me.Body
639
- * @function
640
550
  * @param {number} angle The angle to rotate (in radians)
641
- * @param {me.Vector2d|me.ObservableVector2d} [v=me.Body.getBounds().center] an optional point to rotate around
642
- * @returns {me.Body} Reference to this object for method chaining
551
+ * @param {Vector2d|ObservableVector2d} [v=Body.getBounds().center] an optional point to rotate around
552
+ * @returns {Body} Reference to this object for method chaining
643
553
  */
644
554
  rotate(angle, v = this.getBounds().center) {
645
555
  this.bounds.clear();
@@ -661,9 +571,6 @@ class Body {
661
571
 
662
572
  /**
663
573
  * cap the body velocity (body.maxVel property) to the specified value<br>
664
- * @name setMaxVelocity
665
- * @memberOf me.Body
666
- * @function
667
574
  * @param {number} x max velocity on x axis
668
575
  * @param {number} y max velocity on y axis
669
576
  * @protected
@@ -675,9 +582,6 @@ class Body {
675
582
 
676
583
  /**
677
584
  * set the body default friction
678
- * @name setFriction
679
- * @memberOf me.Body
680
- * @function
681
585
  * @param {number} x horizontal friction
682
586
  * @param {number} y vertical friction
683
587
  * @protected
@@ -761,10 +665,7 @@ class Body {
761
665
  * property is set to true and Body.jumping is set to !Body.falling.
762
666
  *
763
667
  * At this time a call to Body.Update does not call the onBodyUpdate callback that is listed in the constructor arguments.
764
- * @name update
765
- * @ignore
766
- * @memberOf me.Body
767
- * @function
668
+ * @protected
768
669
  * @param {number} dt time since the last update in milliseconds.
769
670
  * @returns {boolean} true if resulting velocity is different than 0
770
671
  */