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