melonjs 10.2.3 → 10.5.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 (96) hide show
  1. package/README.md +6 -6
  2. package/dist/melonjs.js +3620 -3582
  3. package/dist/melonjs.min.js +5 -5
  4. package/dist/melonjs.module.d.ts +3646 -4545
  5. package/dist/melonjs.module.js +3912 -3521
  6. package/package.json +21 -20
  7. package/src/audio/audio.js +30 -31
  8. package/src/camera/camera2d.js +47 -58
  9. package/src/entity/entity.js +32 -38
  10. package/src/game.js +21 -22
  11. package/src/{shapes → geometries}/ellipse.js +40 -47
  12. package/src/{shapes → geometries}/line.js +9 -12
  13. package/src/{shapes → geometries}/poly.js +100 -53
  14. package/src/{shapes → geometries}/rectangle.js +42 -45
  15. package/src/index.js +14 -32
  16. package/src/input/gamepad.js +11 -10
  17. package/src/input/input.js +2 -3
  18. package/src/input/keyboard.js +113 -113
  19. package/src/input/pointer.js +61 -29
  20. package/src/input/pointerevent.js +92 -29
  21. package/src/lang/deprecated.js +83 -13
  22. package/src/level/level.js +23 -24
  23. package/src/level/tiled/TMXGroup.js +7 -9
  24. package/src/level/tiled/TMXLayer.js +30 -33
  25. package/src/level/tiled/TMXObject.js +59 -53
  26. package/src/level/tiled/TMXTile.js +18 -19
  27. package/src/level/tiled/TMXTileMap.js +40 -46
  28. package/src/level/tiled/TMXTileset.js +12 -16
  29. package/src/level/tiled/TMXTilesetGroup.js +9 -10
  30. package/src/level/tiled/renderer/TMXHexagonalRenderer.js +7 -9
  31. package/src/level/tiled/renderer/TMXIsometricRenderer.js +7 -9
  32. package/src/level/tiled/renderer/TMXOrthogonalRenderer.js +4 -6
  33. package/src/level/tiled/renderer/TMXRenderer.js +24 -26
  34. package/src/level/tiled/renderer/TMXStaggeredRenderer.js +1 -5
  35. package/src/loader/loader.js +17 -16
  36. package/src/loader/loadingscreen.js +2 -5
  37. package/src/math/color.js +47 -67
  38. package/src/math/math.js +15 -16
  39. package/src/math/matrix2.js +53 -59
  40. package/src/math/matrix3.js +56 -63
  41. package/src/math/observable_vector2.js +87 -77
  42. package/src/math/observable_vector3.js +97 -80
  43. package/src/math/vector2.js +107 -97
  44. package/src/math/vector3.js +116 -100
  45. package/src/particles/emitter.js +66 -76
  46. package/src/particles/particle.js +4 -6
  47. package/src/particles/particlecontainer.js +2 -4
  48. package/src/physics/body.js +49 -147
  49. package/src/physics/bounds.js +48 -50
  50. package/src/physics/collision.js +13 -14
  51. package/src/physics/detector.js +18 -17
  52. package/src/physics/quadtree.js +17 -20
  53. package/src/physics/sat.js +30 -30
  54. package/src/physics/world.js +24 -29
  55. package/src/plugin/plugin.js +11 -15
  56. package/src/renderable/GUI.js +41 -47
  57. package/src/renderable/collectable.js +5 -10
  58. package/src/renderable/colorlayer.js +10 -15
  59. package/src/renderable/container.js +87 -73
  60. package/src/renderable/dragndrop.js +224 -0
  61. package/src/renderable/imagelayer.js +25 -32
  62. package/src/renderable/nineslicesprite.js +41 -42
  63. package/src/renderable/renderable.js +113 -124
  64. package/src/renderable/sprite.js +62 -69
  65. package/src/renderable/trigger.js +26 -32
  66. package/src/state/stage.js +13 -18
  67. package/src/state/state.js +26 -27
  68. package/src/system/device.js +76 -133
  69. package/src/system/event.js +81 -70
  70. package/src/system/pooling.js +11 -12
  71. package/src/system/save.js +3 -4
  72. package/src/system/timer.js +19 -20
  73. package/src/text/bitmaptext.js +57 -55
  74. package/src/text/bitmaptextdata.js +10 -11
  75. package/src/text/glyph.js +3 -0
  76. package/src/text/text.js +49 -55
  77. package/src/tweens/easing.js +1 -1
  78. package/src/tweens/interpolation.js +1 -1
  79. package/src/tweens/tween.js +44 -46
  80. package/src/utils/agent.js +3 -4
  81. package/src/utils/array.js +4 -5
  82. package/src/utils/file.js +3 -4
  83. package/src/utils/function.js +4 -5
  84. package/src/utils/string.js +7 -9
  85. package/src/utils/utils.js +4 -5
  86. package/src/video/canvas/canvas_renderer.js +60 -62
  87. package/src/video/renderer.js +53 -58
  88. package/src/video/texture.js +98 -112
  89. package/src/video/texture_cache.js +26 -10
  90. package/src/video/video.js +15 -16
  91. package/src/video/webgl/buffer/vertex.js +2 -2
  92. package/src/video/webgl/glshader.js +37 -39
  93. package/src/video/webgl/webgl_compositor.js +128 -101
  94. package/src/video/webgl/webgl_renderer.js +126 -106
  95. package/src/entity/draggable.js +0 -139
  96. package/src/entity/droptarget.js +0 -109
@@ -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();
@@ -176,13 +154,12 @@ class Body {
176
154
 
177
155
 
178
156
  /**
179
- * either this body is a static body or not
157
+ * Either this body is a static body or not.
158
+ * A static body is completely fixed and can never change position or angle.
180
159
  * @readonly
181
160
  * @public
182
161
  * @type {boolean}
183
162
  * @default false
184
- * @name isStatic
185
- * @memberOf me.Body
186
163
  */
187
164
  this.isStatic = false;
188
165
 
@@ -190,22 +167,18 @@ class Body {
190
167
  /**
191
168
  * The degree to which this body is affected by the world gravity
192
169
  * @public
193
- * @see me.World.gravity
170
+ * @see World.gravity
194
171
  * @type {number}
195
172
  * @default 1.0
196
- * @name gravityScale
197
- * @memberOf me.Body
198
173
  */
199
174
  this.gravityScale = 1.0;
200
175
 
201
176
  /**
202
177
  * If true this body won't be affected by the world gravity
203
178
  * @public
204
- * @see me.World.gravity
179
+ * @see World.gravity
205
180
  * @type {boolean}
206
181
  * @default false
207
- * @name ignoreGravity
208
- * @memberOf me.Body
209
182
  */
210
183
  this.ignoreGravity = false;
211
184
 
@@ -217,8 +190,6 @@ class Body {
217
190
  * @public
218
191
  * @type {boolean}
219
192
  * @default false
220
- * @name falling
221
- * @memberOf me.Body
222
193
  */
223
194
  this.falling = false;
224
195
 
@@ -229,8 +200,6 @@ class Body {
229
200
  * @public
230
201
  * @type {boolean}
231
202
  * @default false
232
- * @name jumping
233
- * @memberOf me.Body
234
203
  */
235
204
  this.jumping = false;
236
205
 
@@ -259,10 +228,6 @@ class Body {
259
228
  /**
260
229
  * set the body as a static body
261
230
  * 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
231
  * @param {boolean} [isStatic=true]
267
232
  */
268
233
  setStatic(isStatic = true) {
@@ -272,11 +237,7 @@ class Body {
272
237
  /**
273
238
  * add a collision shape to this body <br>
274
239
  * (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
240
+ * @param {Rect|Polygon|Line|Ellipse|Bounds|object} shape a shape or JSON object
280
241
  * @returns {number} the shape array length
281
242
  * @example
282
243
  * // add a rectangle shape
@@ -326,11 +287,7 @@ class Body {
326
287
 
327
288
  /**
328
289
  * 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
290
+ * @param {Vector2d[]} vertices an array of me.Vector2d points defining a convex hull
334
291
  * @param {number} [index=0] the shape object for which to set the vertices
335
292
  * @param {boolean} [clear=true] either to reset the body definition before adding the new vertices
336
293
  */
@@ -353,11 +310,7 @@ class Body {
353
310
 
354
311
  /**
355
312
  * 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
313
+ * @param {Vector2d[]} vertices an array of me.Vector2d points defining a convex hull
361
314
  * @param {number} [index=0] the shape object for which to set the vertices
362
315
  */
363
316
  addVertices(vertices, index = 0) {
@@ -367,10 +320,6 @@ class Body {
367
320
  /**
368
321
  * add collision mesh based on a JSON object
369
322
  * (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
323
  * @param {object} json a JSON object as exported from a Physics Editor tool
375
324
  * @param {string} [id] an optional shape identifier within the given the json object
376
325
  * @see https://www.codeandweb.com/physicseditor
@@ -411,12 +360,8 @@ class Body {
411
360
 
412
361
  /**
413
362
  * return the collision shape at the given index
414
- * @name getShape
415
- * @memberOf me.Body
416
- * @public
417
- * @function
418
363
  * @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
364
+ * @returns {Polygon|Line|Ellipse} shape a shape object if defined
420
365
  */
421
366
  getShape(index) {
422
367
  return this.shapes[index || 0];
@@ -424,10 +369,8 @@ class Body {
424
369
 
425
370
  /**
426
371
  * returns the AABB bounding box for this body
427
- * @name getBounds
428
- * @memberOf me.Body
429
372
  * @function
430
- * @returns {me.Bounds} bounding box Rectangle object
373
+ * @returns {Bounds} bounding box Rectangle object
431
374
  */
432
375
  getBounds() {
433
376
  return this.bounds;
@@ -435,11 +378,7 @@ class Body {
435
378
 
436
379
  /**
437
380
  * 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
381
+ * @param {Polygon|Line|Ellipse} shape a shape object
443
382
  * @returns {number} the shape array length
444
383
  */
445
384
  removeShape(shape) {
@@ -457,10 +396,6 @@ class Body {
457
396
 
458
397
  /**
459
398
  * remove the shape at the given index from the body shape list
460
- * @name removeShapeAt
461
- * @memberOf me.Body
462
- * @public
463
- * @function
464
399
  * @param {number} index the shape object at the specified index
465
400
  * @returns {number} the shape array length
466
401
  */
@@ -472,12 +407,8 @@ class Body {
472
407
  * By default all entities are able to collide with all other entities, <br>
473
408
  * but it's also possible to specify 'collision filters' to provide a finer <br>
474
409
  * 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
410
+ * @see collision.types
411
+ * @param {number} [bitmask = collision.types.ALL_OBJECT] the collision mask
481
412
  * @example
482
413
  * // filter collision detection with collision shapes, enemies and collectables
483
414
  * myEntity.body.setCollisionMask(me.collision.types.WORLD_SHAPE | me.collision.types.ENEMY_OBJECT | me.collision.types.COLLECTABLE_OBJECT);
@@ -491,11 +422,7 @@ class Body {
491
422
 
492
423
  /**
493
424
  * 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
425
+ * @see collision.types
499
426
  * @param {number} type the collision type
500
427
  * @example
501
428
  * // set the body collision type
@@ -513,11 +440,7 @@ class Body {
513
440
 
514
441
  /**
515
442
  * 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
443
+ * @param {object} response the collision response object (see {@link collision.ResponseObject})
521
444
  */
522
445
  respondToCollision(response) {
523
446
  // the overlap vector
@@ -554,9 +477,6 @@ class Body {
554
477
  * - The current element being processed in the array <br>
555
478
  * - The index of element in the array. <br>
556
479
  * - The array forEach() was called upon. <br>
557
- * @name forEach
558
- * @memberOf me.Body.prototype
559
- * @function
560
480
  * @param {Function} callback fnction to execute on each element
561
481
  * @param {object} [thisArg] value to use as this(i.e reference Object) when executing callback.
562
482
  * @example
@@ -591,18 +511,12 @@ class Body {
591
511
 
592
512
  /**
593
513
  * 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
514
+ * @param {Vector2d} point
598
515
  * @returns {boolean} true if contains
599
516
  */
600
517
 
601
518
  /**
602
519
  * 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
520
  * @param {number} x x coordinate
607
521
  * @param {number} y y coordinate
608
522
  * @returns {boolean} true if contains
@@ -634,12 +548,9 @@ class Body {
634
548
  /**
635
549
  * Rotate this body (counter-clockwise) by the specified angle (in radians).
636
550
  * Unless specified the body will be rotated around its center point
637
- * @name rotate
638
- * @memberOf me.Body
639
- * @function
640
551
  * @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
552
+ * @param {Vector2d|ObservableVector2d} [v=Body.getBounds().center] an optional point to rotate around
553
+ * @returns {Body} Reference to this object for method chaining
643
554
  */
644
555
  rotate(angle, v = this.getBounds().center) {
645
556
  this.bounds.clear();
@@ -661,9 +572,6 @@ class Body {
661
572
 
662
573
  /**
663
574
  * cap the body velocity (body.maxVel property) to the specified value<br>
664
- * @name setMaxVelocity
665
- * @memberOf me.Body
666
- * @function
667
575
  * @param {number} x max velocity on x axis
668
576
  * @param {number} y max velocity on y axis
669
577
  * @protected
@@ -675,9 +583,6 @@ class Body {
675
583
 
676
584
  /**
677
585
  * set the body default friction
678
- * @name setFriction
679
- * @memberOf me.Body
680
- * @function
681
586
  * @param {number} x horizontal friction
682
587
  * @param {number} y vertical friction
683
588
  * @protected
@@ -761,10 +666,7 @@ class Body {
761
666
  * property is set to true and Body.jumping is set to !Body.falling.
762
667
  *
763
668
  * 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
669
+ * @protected
768
670
  * @param {number} dt time since the last update in milliseconds.
769
671
  * @returns {boolean} true if resulting velocity is different than 0
770
672
  */