melonjs 10.1.0 → 10.2.2

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 (92) hide show
  1. package/README.md +6 -12
  2. package/dist/melonjs.js +3119 -2857
  3. package/dist/melonjs.min.js +3 -3
  4. package/dist/melonjs.module.d.ts +2590 -2490
  5. package/dist/melonjs.module.js +2698 -2470
  6. package/package.json +10 -11
  7. package/src/audio/audio.js +43 -43
  8. package/src/camera/camera2d.js +55 -77
  9. package/src/entity/draggable.js +18 -17
  10. package/src/entity/droptarget.js +19 -18
  11. package/src/entity/entity.js +22 -26
  12. package/src/game.js +3 -3
  13. package/src/index.js +15 -11
  14. package/src/input/gamepad.js +13 -13
  15. package/src/input/input.js +1 -1
  16. package/src/input/keyboard.js +14 -16
  17. package/src/input/pointer.js +42 -35
  18. package/src/input/pointerevent.js +25 -33
  19. package/src/lang/deprecated.js +3 -3
  20. package/src/level/level.js +24 -16
  21. package/src/level/tiled/TMXGroup.js +6 -6
  22. package/src/level/tiled/TMXLayer.js +31 -31
  23. package/src/level/tiled/TMXObject.js +19 -19
  24. package/src/level/tiled/TMXTile.js +11 -12
  25. package/src/level/tiled/TMXTileMap.js +23 -21
  26. package/src/level/tiled/TMXTileset.js +13 -13
  27. package/src/level/tiled/TMXTilesetGroup.js +4 -4
  28. package/src/level/tiled/TMXUtils.js +13 -11
  29. package/src/level/tiled/renderer/TMXHexagonalRenderer.js +1 -1
  30. package/src/level/tiled/renderer/TMXIsometricRenderer.js +1 -1
  31. package/src/level/tiled/renderer/TMXRenderer.js +17 -17
  32. package/src/loader/loader.js +31 -27
  33. package/src/loader/loadingscreen.js +40 -72
  34. package/src/math/color.js +45 -64
  35. package/src/math/math.js +17 -17
  36. package/src/math/matrix2.js +46 -46
  37. package/src/math/matrix3.js +64 -64
  38. package/src/math/observable_vector2.js +45 -57
  39. package/src/math/observable_vector3.js +56 -70
  40. package/src/math/vector2.js +60 -59
  41. package/src/math/vector3.js +65 -64
  42. package/src/particles/emitter.js +53 -55
  43. package/src/particles/particle.js +1 -1
  44. package/src/physics/body.js +45 -51
  45. package/src/physics/bounds.js +36 -36
  46. package/src/physics/collision.js +15 -16
  47. package/src/physics/detector.js +10 -11
  48. package/src/physics/quadtree.js +19 -17
  49. package/src/physics/sat.js +17 -17
  50. package/src/physics/world.js +13 -10
  51. package/src/plugin/plugin.js +6 -6
  52. package/src/renderable/GUI.js +13 -18
  53. package/src/renderable/collectable.js +3 -3
  54. package/src/renderable/colorlayer.js +4 -4
  55. package/src/renderable/container.js +65 -46
  56. package/src/renderable/imagelayer.js +32 -31
  57. package/src/renderable/nineslicesprite.js +211 -0
  58. package/src/renderable/renderable.js +69 -67
  59. package/src/renderable/sprite.js +57 -43
  60. package/src/renderable/trigger.js +14 -15
  61. package/src/shapes/ellipse.js +27 -26
  62. package/src/shapes/line.js +8 -7
  63. package/src/shapes/poly.js +33 -31
  64. package/src/shapes/rectangle.js +50 -96
  65. package/src/state/stage.js +8 -8
  66. package/src/state/state.js +56 -56
  67. package/src/system/device.js +97 -84
  68. package/src/system/event.js +72 -72
  69. package/src/system/pooling.js +14 -14
  70. package/src/system/save.js +6 -3
  71. package/src/system/timer.js +20 -20
  72. package/src/text/bitmaptext.js +27 -33
  73. package/src/text/bitmaptextdata.js +9 -9
  74. package/src/text/text.js +118 -59
  75. package/src/tweens/easing.js +4 -4
  76. package/src/tweens/interpolation.js +4 -4
  77. package/src/tweens/tween.js +37 -27
  78. package/src/utils/agent.js +9 -8
  79. package/src/utils/array.js +4 -4
  80. package/src/utils/file.js +4 -4
  81. package/src/utils/function.js +5 -5
  82. package/src/utils/string.js +12 -12
  83. package/src/utils/utils.js +19 -19
  84. package/src/video/canvas/canvas_renderer.js +90 -90
  85. package/src/video/renderer.js +40 -39
  86. package/src/video/texture.js +85 -76
  87. package/src/video/texture_cache.js +11 -0
  88. package/src/video/video.js +30 -30
  89. package/src/video/webgl/buffer/vertex.js +9 -1
  90. package/src/video/webgl/glshader.js +20 -20
  91. package/src/video/webgl/webgl_compositor.js +47 -37
  92. package/src/video/webgl/webgl_renderer.js +104 -104
@@ -5,9 +5,9 @@ import { Easing } from "./easing.js";
5
5
  import { Interpolation } from "./interpolation.js";
6
6
 
7
7
  /**
8
- * Tween.js - Licensed under the MIT license
9
- * https://github.com/tweenjs/tween.js
10
- */
8
+ * Tween.js - Licensed under the MIT license
9
+ * https://github.com/tweenjs/tween.js
10
+ */
11
11
 
12
12
  /**
13
13
  * @classdesc
@@ -25,7 +25,7 @@ import { Interpolation } from "./interpolation.js";
25
25
  * @class Tween
26
26
  * @memberOf me
27
27
  * @constructor
28
- * @param {Object} object object on which to apply the tween
28
+ * @param {object} object object on which to apply the tween
29
29
  * @example
30
30
  * // add a tween to change the object pos.x and pos.y variable to 200 in 3 seconds
31
31
  * tween = new me.Tween(myObject.pos).to({
@@ -124,15 +124,16 @@ class Tween {
124
124
  * @memberOf me.Tween
125
125
  * @public
126
126
  * @function
127
- * @param {Object} properties hash of properties
128
- * @param {Object|Number} [options] object of tween properties, or a duration if a numeric value is passed
129
- * @param {Number} [options.duration] tween duration
127
+ * @param {object} properties hash of properties
128
+ * @param {object|number} [options] object of tween properties, or a duration if a numeric value is passed
129
+ * @param {number} [options.duration] tween duration
130
130
  * @param {me.Tween.Easing} [options.easing] easing function
131
- * @param {Number} [options.delay] delay amount expressed in milliseconds
132
- * @param {Boolean} [options.yoyo] allows the tween to bounce back to their original value when finished. To be used together with repeat to create endless loops.
133
- * @param {Number} [options.repeat] amount of times the tween should be repeated
131
+ * @param {number} [options.delay] delay amount expressed in milliseconds
132
+ * @param {boolean} [options.yoyo] allows the tween to bounce back to their original value when finished. To be used together with repeat to create endless loops.
133
+ * @param {number} [options.repeat] amount of times the tween should be repeated
134
134
  * @param {me.Tween.Interpolation} [options.interpolation] interpolation function
135
- * @param {Boolean} [options.autoStart] allow this tween to start automatically. Otherwise call me.Tween.start().
135
+ * @param {boolean} [options.autoStart] allow this tween to start automatically. Otherwise call me.Tween.start().
136
+ * @returns {me.Tween} this instance for object chaining
136
137
  */
137
138
  to( properties, options ) {
138
139
 
@@ -157,7 +158,6 @@ class Tween {
157
158
  }
158
159
 
159
160
  return this;
160
-
161
161
  }
162
162
 
163
163
  /**
@@ -166,6 +166,8 @@ class Tween {
166
166
  * @memberOf me.Tween
167
167
  * @public
168
168
  * @function
169
+ * @param {number} [time] the current time when the tween was started
170
+ * @returns {me.Tween} this instance for object chaining
169
171
  */
170
172
  start( time = timer.getTime() ) {
171
173
 
@@ -203,7 +205,6 @@ class Tween {
203
205
  }
204
206
 
205
207
  return this;
206
-
207
208
  }
208
209
 
209
210
  /**
@@ -212,6 +213,7 @@ class Tween {
212
213
  * @memberOf me.Tween
213
214
  * @public
214
215
  * @function
216
+ * @returns {me.Tween} this instance for object chaining
215
217
  */
216
218
  stop() {
217
219
  // remove the tween from the world container
@@ -225,7 +227,8 @@ class Tween {
225
227
  * @memberOf me.Tween
226
228
  * @public
227
229
  * @function
228
- * @param {Number} amount delay amount expressed in milliseconds
230
+ * @param {number} amount delay amount expressed in milliseconds
231
+ * @returns {me.Tween} this instance for object chaining
229
232
  */
230
233
  delay( amount ) {
231
234
 
@@ -240,7 +243,8 @@ class Tween {
240
243
  * @memberOf me.Tween
241
244
  * @public
242
245
  * @function
243
- * @param {Number} times amount of times the tween should be repeated
246
+ * @param {number} times amount of times the tween should be repeated
247
+ * @returns {me.Tween} this instance for object chaining
244
248
  */
245
249
  repeat( times ) {
246
250
 
@@ -257,7 +261,8 @@ class Tween {
257
261
  * @public
258
262
  * @function
259
263
  * @see me.Tween#repeat
260
- * @param {Boolean} yoyo
264
+ * @param {boolean} yoyo
265
+ * @returns {me.Tween} this instance for object chaining
261
266
  */
262
267
  yoyo( yoyo ) {
263
268
 
@@ -272,7 +277,8 @@ class Tween {
272
277
  * @memberOf me.Tween
273
278
  * @public
274
279
  * @function
275
- * @param {me.Tween.Easing} fn easing function
280
+ * @param {me.Tween.Easing} easing easing function
281
+ * @returns {me.Tween} this instance for object chaining
276
282
  */
277
283
  easing( easing ) {
278
284
  if (typeof easing !== "function") {
@@ -280,7 +286,6 @@ class Tween {
280
286
  }
281
287
  this._easingFunction = easing;
282
288
  return this;
283
-
284
289
  }
285
290
 
286
291
  /**
@@ -289,7 +294,8 @@ class Tween {
289
294
  * @memberOf me.Tween
290
295
  * @public
291
296
  * @function
292
- * @param {me.Tween.Interpolation} fn interpolation function
297
+ * @param {me.Tween.Interpolation} interpolation interpolation function
298
+ * @returns {me.Tween} this instance for object chaining
293
299
  */
294
300
  interpolation( interpolation ) {
295
301
  this._interpolationFunction = interpolation;
@@ -302,9 +308,10 @@ class Tween {
302
308
  * @memberOf me.Tween
303
309
  * @public
304
310
  * @function
305
- * @param {me.Tween} chainedTween Tween to be chained
311
+ * @param {...me.Tween} chainedTween Tween(s) to be chained
312
+ * @returns {me.Tween} this instance for object chaining
306
313
  */
307
- chain() {
314
+ chain( chainedTween ) {
308
315
  this._chainedTweens = arguments;
309
316
  return this;
310
317
  }
@@ -316,9 +323,10 @@ class Tween {
316
323
  * @public
317
324
  * @function
318
325
  * @param {Function} onStartCallback callback
326
+ * @returns {me.Tween} this instance for object chaining
319
327
  */
320
- onStart( callback ) {
321
- this._onStartCallback = callback;
328
+ onStart( onStartCallback ) {
329
+ this._onStartCallback = onStartCallback;
322
330
  return this;
323
331
  }
324
332
 
@@ -329,9 +337,10 @@ class Tween {
329
337
  * @public
330
338
  * @function
331
339
  * @param {Function} onUpdateCallback callback
340
+ * @returns {me.Tween} this instance for object chaining
332
341
  */
333
- onUpdate( callback ) {
334
- this._onUpdateCallback = callback;
342
+ onUpdate( onUpdateCallback ) {
343
+ this._onUpdateCallback = onUpdateCallback;
335
344
  return this;
336
345
  }
337
346
 
@@ -342,9 +351,10 @@ class Tween {
342
351
  * @public
343
352
  * @function
344
353
  * @param {Function} onCompleteCallback callback
354
+ * @returns {me.Tween} this instance for object chaining
345
355
  */
346
- onComplete( callback ) {
347
- this._onCompleteCallback = callback;
356
+ onComplete( onCompleteCallback ) {
357
+ this._onCompleteCallback = onCompleteCallback;
348
358
  return this;
349
359
  };
350
360
 
@@ -17,9 +17,9 @@ var vendors = [ "ms", "MS", "moz", "webkit", "o" ];
17
17
  * @public
18
18
  * @name prefixed
19
19
  * @function
20
- * @param {String} name Property name
21
- * @param {Object} [obj=window] Object or element reference to access
22
- * @return {Mixed} Value of property
20
+ * @param {string} name Property name
21
+ * @param {object} [obj=window] Object or element reference to access
22
+ * @returns {string} Value of property
23
23
  * @memberOf me.utils.agent
24
24
  */
25
25
  export function prefixed(name, obj) {
@@ -43,10 +43,10 @@ export function prefixed(name, obj) {
43
43
  * @public
44
44
  * @name setPrefixed
45
45
  * @function
46
- * @param {String} name Property name
47
- * @param {Mixed} value Property value
48
- * @param {Object} [obj=window] Object or element reference to access
49
- * @return true if one of the vendor-prefixed property was found
46
+ * @param {string} name Property name
47
+ * @param {string} value Property value
48
+ * @param {object} [obj=window] Object or element reference to access
49
+ * @returns {boolean} true if one of the vendor-prefixed property was found
50
50
  * @memberOf me.utils.agent
51
51
  */
52
52
  export function setPrefixed(name, value, obj) {
@@ -64,6 +64,7 @@ export function setPrefixed(name, value, obj) {
64
64
  obj[name] = value;
65
65
  return true;
66
66
  }
67
- return false;
68
67
  });
68
+
69
+ return false;
69
70
  };
@@ -13,8 +13,8 @@ import {random as mathRandom, weightedRandom as mathWeightedRandom} from "./../m
13
13
  * @memberOf me.utils.array
14
14
  * @name remove
15
15
  * @param {Array} arr array from which to remove an object
16
- * @param {Object} object to be removed
17
- * @return {Array} the modified Array
16
+ * @param {object} obj to be removed
17
+ * @returns {Array} the modified Array
18
18
  * var arr = [ "foo", "bar", "baz" ];
19
19
  * // remove "foo" from the array
20
20
  * me.utils.array.remove(arr, "foo");
@@ -34,7 +34,7 @@ export function remove(arr, obj) {
34
34
  * @memberOf me.utils.array
35
35
  * @name random
36
36
  * @param {Array} arr array to pick a element
37
- * @return {any} random member of array
37
+ * @returns {any} random member of array
38
38
  * @example
39
39
  * // Select a random array element
40
40
  * var arr = [ "foo", "bar", "baz" ];
@@ -51,7 +51,7 @@ export function random(arr) {
51
51
  * @memberOf me.utils.array
52
52
  * @name weightedRandom
53
53
  * @param {Array} arr array to pick a element
54
- * @return {any} random member of array
54
+ * @returns {any} random member of array
55
55
  */
56
56
  export function weightedRandom(arr) {
57
57
  return arr[mathWeightedRandom(0, arr.length)];
package/src/utils/file.js CHANGED
@@ -16,8 +16,8 @@ const REMOVE_EXT = /\.[^\.]*$/;
16
16
  * @function
17
17
  * @memberOf me.utils.file
18
18
  * @name getBasename
19
- * @param {String} path path containing the filename
20
- * @return {String} the base name without path information.
19
+ * @param {string} path path containing the filename
20
+ * @returns {string} the base name without path information.
21
21
  */
22
22
  export function getBasename(path) {
23
23
  return path.replace(REMOVE_PATH, "").replace(REMOVE_EXT, "");
@@ -29,8 +29,8 @@ export function getBasename(path) {
29
29
  * @function
30
30
  * @memberOf me.utils.file
31
31
  * @name getExtension
32
- * @param {String} path path containing the filename
33
- * @return {String} filename extension.
32
+ * @param {string} path path containing the filename
33
+ * @returns {string} filename extension.
34
34
  */
35
35
  export function getExtension(path) {
36
36
  return path.substring(path.lastIndexOf(".") + 1, path.length);
@@ -4,17 +4,16 @@
4
4
  * @memberOf me
5
5
  */
6
6
 
7
-
8
7
  /**
9
8
  * Executes a function as soon as the interpreter is idle (stack empty).
10
9
  * @public
11
10
  * @function
12
11
  * @memberOf me.utils.function
13
12
  * @name defer
14
- * @param {Function} fn The function to be deferred.
15
- * @param {Object} thisArg The value to be passed as the this parameter to the target function when the deferred function is called
13
+ * @param {Function} func The function to be deferred.
14
+ * @param {object} thisArg The value to be passed as the this parameter to the target function when the deferred function is called
16
15
  * @param {...*} [args] Optional additional arguments to carry for the function.
17
- * @return {Number} id that can be used to clear the deferred function using
16
+ * @returns {number} id that can be used to clear the deferred function using
18
17
  * clearTimeout
19
18
  * @example
20
19
  * // execute myFunc() when the stack is empty,
@@ -33,8 +32,9 @@ export function defer(func, thisArg, ...args) {
33
32
  * @memberOf me.utils.function
34
33
  * @name throttle
35
34
  * @param {Function} fn the function to be throttled.
36
- * @param {Number} delay The delay in ms
35
+ * @param {number} delay The delay in ms
37
36
  * @param {no_trailing} no_trailing disable the execution on the trailing edge
37
+ * @returns {Function} the function that will be throttled
38
38
  */
39
39
  export function throttle(fn, delay, no_trailing) {
40
40
  var last = window.performance.now(), deferTimer;
@@ -11,8 +11,8 @@
11
11
  * @function
12
12
  * @memberOf me.utils.string
13
13
  * @name capitalize
14
- * @param {String} string the string to be capitalized
15
- * @return {string} the capitalized string
14
+ * @param {string} str the string to be capitalized
15
+ * @returns {string} the capitalized string
16
16
  */
17
17
  export function capitalize(str) {
18
18
  return str.charAt(0).toUpperCase() + str.slice(1);
@@ -24,8 +24,8 @@ export function capitalize(str) {
24
24
  * @function
25
25
  * @memberOf me.utils.string
26
26
  * @name trimLeft
27
- * @param {String} string the string to be trimmed
28
- * @return {string} trimmed string
27
+ * @param {string} str the string to be trimmed
28
+ * @returns {string} trimmed string
29
29
  */
30
30
  export function trimLeft(str) {
31
31
  return str.replace(/^\s+/, "");
@@ -37,8 +37,8 @@ export function trimLeft(str) {
37
37
  * @function
38
38
  * @memberOf me.utils.string
39
39
  * @name trimRight
40
- * @param {String} string the string to be trimmed
41
- * @return {string} trimmed string
40
+ * @param {string} str the string to be trimmed
41
+ * @returns {string} trimmed string
42
42
  */
43
43
  export function trimRight(str) {
44
44
  return str.replace(/\s+$/, "");
@@ -50,8 +50,8 @@ export function trimRight(str) {
50
50
  * @function
51
51
  * @memberOf me.utils.string
52
52
  * @name isNumeric
53
- * @param {String} string the string to be tested
54
- * @return {Boolean} true if string contains only digits
53
+ * @param {string} str the string to be tested
54
+ * @returns {boolean} true if string contains only digits
55
55
  */
56
56
  export function isNumeric(str) {
57
57
  if (typeof str === "string") {
@@ -66,8 +66,8 @@ export function isNumeric(str) {
66
66
  * @function
67
67
  * @memberOf me.utils.string
68
68
  * @name isBoolean
69
- * @param {String} string the string to be tested
70
- * @return {Boolean} true if the string is either true or false
69
+ * @param {string} str the string to be tested
70
+ * @returns {boolean} true if the string is either true or false
71
71
  */
72
72
  export function isBoolean(str) {
73
73
  var trimmed = str.trim();
@@ -80,8 +80,8 @@ export function isBoolean(str) {
80
80
  * @function
81
81
  * @memberOf me.utils.string
82
82
  * @name toHex
83
- * @param {String} string the string to be converted
84
- * @return {String}
83
+ * @param {string} str the string to be converted
84
+ * @returns {string} the converted hexadecimal value
85
85
  */
86
86
  export function toHex(str) {
87
87
  var res = "", c = 0;
@@ -31,20 +31,20 @@ var utils = {
31
31
  * @function
32
32
  * @memberOf me.utils
33
33
  * @name getPixels
34
- * @param {Image|Canvas} image Image to read
35
- * @return {ImageData} Canvas ImageData object
34
+ * @param {HTMLImageElement|HTMLCanvasElement} image Image to read
35
+ * @returns {ImageData} ImageData object
36
36
  */
37
- getPixels : function (arg) {
38
- if (arg instanceof HTMLImageElement) {
37
+ getPixels : function (image) {
38
+ if (image instanceof HTMLImageElement) {
39
39
  var _context = CanvasRenderer.getContext2d(
40
- createCanvas(arg.width, arg.height)
40
+ createCanvas(image.width, image.height)
41
41
  );
42
- _context.drawImage(arg, 0, 0);
43
- return _context.getImageData(0, 0, arg.width, arg.height);
42
+ _context.drawImage(image, 0, 0);
43
+ return _context.getImageData(0, 0, image.width, image.height);
44
44
  }
45
45
  else {
46
46
  // canvas !
47
- return arg.getContext("2d").getImageData(0, 0, arg.width, arg.height);
47
+ return image.getContext("2d").getImageData(0, 0, image.width, image.height);
48
48
  }
49
49
  },
50
50
 
@@ -54,9 +54,9 @@ var utils = {
54
54
  * @function
55
55
  * @memberOf me.utils
56
56
  * @name checkVersion
57
- * @param {String} first First version string to compare
58
- * @param {String} [second=me.version] Second version string to compare
59
- * @return {Number} comparison result <br>&lt; 0 : first &lt; second<br>
57
+ * @param {string} first First version string to compare
58
+ * @param {string} [second=me.version] Second version string to compare
59
+ * @returns {number} comparison result <br>&lt; 0 : first &lt; second<br>
60
60
  * 0 : first == second<br>
61
61
  * &gt; 0 : first &gt; second
62
62
  * @example
@@ -87,14 +87,14 @@ var utils = {
87
87
  * @function
88
88
  * @memberOf me.utils
89
89
  * @name getUriFragment
90
- * @param {String} [url=document.location] an optional params string or URL containing fragment (hash) params to be parsed
91
- * @return {Object} an object representing the deserialized params string.
92
- * @property {Boolean} [hitbox=false] draw the hitbox in the debug panel (if enabled)
93
- * @property {Boolean} [velocity=false] draw the entities velocity in the debug panel (if enabled)
94
- * @property {Boolean} [quadtree=false] draw the quadtree in the debug panel (if enabled)
95
- * @property {Boolean} [webgl=false] force the renderer to WebGL
96
- * @property {Boolean} [debug=false] display the debug panel (if preloaded)
97
- * @property {String} [debugToggleKey="s"] show/hide the debug panel (if preloaded)
90
+ * @param {string} [url=document.location] an optional params string or URL containing fragment (hash) params to be parsed
91
+ * @returns {object} an object representing the deserialized params string.
92
+ * @property {boolean} [hitbox=false] draw the hitbox in the debug panel (if enabled)
93
+ * @property {boolean} [velocity=false] draw the entities velocity in the debug panel (if enabled)
94
+ * @property {boolean} [quadtree=false] draw the quadtree in the debug panel (if enabled)
95
+ * @property {boolean} [webgl=false] force the renderer to WebGL
96
+ * @property {boolean} [debug=false] display the debug panel (if preloaded)
97
+ * @property {string} [debugToggleKey="s"] show/hide the debug panel (if preloaded)
98
98
  * @example
99
99
  * // http://www.example.com/index.html#debug&hitbox=true&mytag=value
100
100
  * var UriFragment = me.utils.getUriFragment();