melonjs 9.1.0 → 10.0.1

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 (78) hide show
  1. package/{LICENSE → LICENSE.md} +0 -0
  2. package/README.md +93 -57
  3. package/dist/melonjs.js +10334 -11179
  4. package/dist/melonjs.min.js +4 -10
  5. package/dist/melonjs.module.d.ts +13206 -0
  6. package/dist/melonjs.module.js +9913 -10872
  7. package/package.json +19 -14
  8. package/src/audio/audio.js +477 -553
  9. package/src/camera/camera2d.js +67 -65
  10. package/src/entity/draggable.js +26 -35
  11. package/src/entity/droptarget.js +17 -14
  12. package/src/entity/entity.js +59 -79
  13. package/src/game.js +194 -204
  14. package/src/index.js +12 -30
  15. package/src/input/gamepad.js +8 -19
  16. package/src/input/keyboard.js +4 -4
  17. package/src/input/pointer.js +14 -12
  18. package/src/input/pointerevent.js +15 -13
  19. package/src/lang/deprecated.js +2 -887
  20. package/src/level/level.js +3 -3
  21. package/src/level/tiled/TMXGroup.js +7 -11
  22. package/src/level/tiled/TMXLayer.js +33 -32
  23. package/src/level/tiled/TMXTileMap.js +15 -19
  24. package/src/level/tiled/TMXTileset.js +5 -5
  25. package/src/level/tiled/TMXUtils.js +3 -3
  26. package/src/level/tiled/renderer/TMXRenderer.js +4 -0
  27. package/src/loader/loader.js +8 -23
  28. package/src/loader/loadingscreen.js +51 -60
  29. package/src/math/matrix3.js +1 -1
  30. package/src/particles/emitter.js +36 -39
  31. package/src/particles/particle.js +27 -12
  32. package/src/particles/particlecontainer.js +17 -16
  33. package/src/physics/body.js +80 -118
  34. package/src/physics/collision.js +5 -235
  35. package/src/physics/detector.js +235 -0
  36. package/src/physics/quadtree.js +14 -14
  37. package/src/physics/world.js +84 -18
  38. package/src/plugin/plugin.js +26 -24
  39. package/src/polyfill/console.js +9 -14
  40. package/src/renderable/GUI.js +48 -62
  41. package/src/renderable/collectable.js +11 -4
  42. package/src/renderable/colorlayer.js +28 -26
  43. package/src/renderable/container.js +120 -96
  44. package/src/renderable/imagelayer.js +94 -93
  45. package/src/renderable/renderable.js +164 -138
  46. package/src/renderable/sprite.js +42 -44
  47. package/src/renderable/trigger.js +24 -17
  48. package/src/shapes/ellipse.js +27 -27
  49. package/src/shapes/line.js +12 -8
  50. package/src/shapes/poly.js +77 -49
  51. package/src/shapes/rectangle.js +193 -268
  52. package/src/state/stage.js +23 -25
  53. package/src/state/state.js +35 -86
  54. package/src/system/device.js +233 -285
  55. package/src/system/event.js +485 -432
  56. package/src/system/pooling.js +61 -54
  57. package/src/system/save.js +17 -16
  58. package/src/system/timer.js +34 -38
  59. package/src/text/bitmaptext.js +44 -46
  60. package/src/text/text.js +39 -34
  61. package/src/tweens/easing.js +0 -2
  62. package/src/tweens/interpolation.js +3 -8
  63. package/src/tweens/tween.js +332 -351
  64. package/src/utils/function.js +6 -8
  65. package/src/utils/utils.js +34 -30
  66. package/src/video/canvas/canvas_renderer.js +13 -8
  67. package/src/video/renderer.js +8 -7
  68. package/src/video/texture.js +8 -8
  69. package/src/video/texture_cache.js +5 -5
  70. package/src/video/video.js +373 -403
  71. package/src/video/webgl/glshader.js +2 -2
  72. package/src/video/webgl/webgl_compositor.js +14 -8
  73. package/src/video/webgl/webgl_renderer.js +21 -19
  74. package/plugins/debug/debugPanel.js +0 -770
  75. package/plugins/debug/font/PressStart2P.fnt +0 -100
  76. package/plugins/debug/font/PressStart2P.ltr +0 -1
  77. package/plugins/debug/font/PressStart2P.png +0 -0
  78. package/plugins/debug/particleDebugPanel.js +0 -303
package/src/text/text.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import Color from "./../math/color.js";
2
2
  import Renderer from "./../video/renderer.js";
3
- import video from "./../video/video.js";
4
- import utils from "./../utils/utils.js";
3
+ import { renderer } from "./../video/video.js";
4
+ import * as stringUtil from "./../utils/string.js";
5
5
  import pool from "./../system/pooling.js";
6
6
  import Renderable from "./../renderable/renderable.js";
7
7
 
@@ -55,12 +55,17 @@ var setContextStyle = function(context, font, stroke) {
55
55
  * @example
56
56
  * var font = new me.Text(0, 0, {font: "Arial", size: 8, fillStyle: this.color});
57
57
  */
58
- var Text = Renderable.extend({
58
+ class Text extends Renderable {
59
59
 
60
60
  /** @ignore */
61
- init : function (x, y, settings) {
61
+ constructor(x, y, settings) {
62
62
  // call the parent constructor
63
- this._super(Renderable, "init", [x, y, settings.width || 0, settings.height || 0]);
63
+ super(x, y, settings.width || 0, settings.height || 0);
64
+ this.onResetEvent(x, y, settings);
65
+ }
66
+
67
+ /** @ignore */
68
+ onResetEvent(x, y, settings) {
64
69
 
65
70
  /**
66
71
  * defines the color used to draw the font.<br>
@@ -181,7 +186,7 @@ var Text = Renderable.extend({
181
186
 
182
187
  // set the text
183
188
  this.setText(settings.text);
184
- },
189
+ }
185
190
 
186
191
  /**
187
192
  * make the font bold
@@ -190,11 +195,11 @@ var Text = Renderable.extend({
190
195
  * @function
191
196
  * @return this object for chaining
192
197
  */
193
- bold : function () {
198
+ bold() {
194
199
  this.font = "bold " + this.font;
195
200
  this.isDirty = true;
196
201
  return this;
197
- },
202
+ }
198
203
 
199
204
  /**
200
205
  * make the font italic
@@ -203,11 +208,11 @@ var Text = Renderable.extend({
203
208
  * @function
204
209
  * @return this object for chaining
205
210
  */
206
- italic : function () {
211
+ italic() {
207
212
  this.font = "italic " + this.font;
208
213
  this.isDirty = true;
209
214
  return this;
210
- },
215
+ }
211
216
 
212
217
  /**
213
218
  * set the font family and size
@@ -221,7 +226,7 @@ var Text = Renderable.extend({
221
226
  * font.setFont("Arial", 20);
222
227
  * font.setFont("Arial", "1.5em");
223
228
  */
224
- setFont : function (font, size) {
229
+ setFont(font, size) {
225
230
  // font name and type
226
231
  var font_names = font.split(",").map(function (value) {
227
232
  value = value.trim();
@@ -251,7 +256,7 @@ var Text = Renderable.extend({
251
256
  this.isDirty = true;
252
257
 
253
258
  return this;
254
- },
259
+ }
255
260
 
256
261
  /**
257
262
  * change the text to be displayed
@@ -261,7 +266,7 @@ var Text = Renderable.extend({
261
266
  * @param {Number|String|String[]} value a string, or an array of strings
262
267
  * @return this object for chaining
263
268
  */
264
- setText : function (value) {
269
+ setText(value) {
265
270
  if (typeof value === "undefined") {
266
271
  value = "";
267
272
  }
@@ -276,7 +281,7 @@ var Text = Renderable.extend({
276
281
  }
277
282
 
278
283
  return this;
279
- },
284
+ }
280
285
 
281
286
  /**
282
287
  * measure the given text size in pixels
@@ -288,16 +293,16 @@ var Text = Renderable.extend({
288
293
  * @param {me.Rect|me.Bounds} [ret] a object in which to store the text metrics
289
294
  * @returns {TextMetrics} a TextMetrics object with two properties: `width` and `height`, defining the output dimensions
290
295
  */
291
- measureText : function (renderer, text, ret) {
296
+ measureText(_renderer, text, ret) {
292
297
  var context;
293
298
 
294
- if (typeof renderer === "undefined") {
295
- context = video.renderer.getFontContext();
296
- } else if (renderer instanceof Renderer) {
299
+ if (typeof _renderer === "undefined") {
297
300
  context = renderer.getFontContext();
301
+ } else if (_renderer instanceof Renderer) {
302
+ context = _renderer.getFontContext();
298
303
  } else {
299
304
  // else it's a 2d rendering context object
300
- context = renderer;
305
+ context = _renderer;
301
306
  }
302
307
 
303
308
  var textMetrics = ret || this.getBounds();
@@ -314,7 +319,7 @@ var Text = Renderable.extend({
314
319
  // compute the bounding box size
315
320
  this.height = this.width = 0;
316
321
  for (var i = 0; i < strings.length; i++) {
317
- this.width = Math.max(context.measureText(utils.string.trimRight(""+strings[i])).width, this.width);
322
+ this.width = Math.max(context.measureText(stringUtil.trimRight(""+strings[i])).width, this.width);
318
323
  this.height += lineHeight;
319
324
  }
320
325
  textMetrics.width = Math.ceil(this.width);
@@ -333,17 +338,17 @@ var Text = Renderable.extend({
333
338
 
334
339
  // returns the Font bounds me.Rect by default
335
340
  return textMetrics;
336
- },
341
+ }
337
342
 
338
343
  /**
339
344
  * @ignore
340
345
  */
341
- update : function (/* dt */) {
346
+ update(/* dt */) {
342
347
  if (this.isDirty === true) {
343
348
  this.measureText();
344
349
  }
345
350
  return this.isDirty;
346
- },
351
+ }
347
352
 
348
353
  /**
349
354
  * draw a text at the specified coord
@@ -355,7 +360,7 @@ var Text = Renderable.extend({
355
360
  * @param {Number} [x]
356
361
  * @param {Number} [y]
357
362
  */
358
- draw : function (renderer, text, x, y, stroke) {
363
+ draw(renderer, text, x, y, stroke) {
359
364
  // "hacky patch" for backward compatibilty
360
365
  if (typeof this.ancestor === "undefined") {
361
366
  // update text cache
@@ -401,7 +406,7 @@ var Text = Renderable.extend({
401
406
  // clear the dirty flag here for
402
407
  // backward compatibility
403
408
  this.isDirty = false;
404
- },
409
+ }
405
410
 
406
411
  /**
407
412
  * draw a stroke text at the specified coord, as defined <br>
@@ -415,38 +420,38 @@ var Text = Renderable.extend({
415
420
  * @param {Number} x
416
421
  * @param {Number} y
417
422
  */
418
- drawStroke : function (renderer, text, x, y) {
419
- this.draw.call(this, renderer, text, x, y, true);
420
- },
423
+ drawStroke(renderer, text, x, y) {
424
+ this.draw(renderer, text, x, y, true);
425
+ }
421
426
 
422
427
  /**
423
428
  * @ignore
424
429
  */
425
- _drawFont : function (context, text, x, y, stroke) {
430
+ _drawFont(context, text, x, y, stroke) {
426
431
  setContextStyle(context, this, stroke);
427
432
 
428
433
  var lineHeight = this.fontSize * this.lineHeight;
429
434
  for (var i = 0; i < text.length; i++) {
430
- var string = utils.string.trimRight(""+text[i]);
435
+ var string = stringUtil.trimRight(""+text[i]);
431
436
  // draw the string
432
437
  context[stroke ? "strokeText" : "fillText"](string, x, y);
433
438
  // add leading space
434
439
  y += lineHeight;
435
440
  }
436
441
  return this.getBounds();
437
- },
442
+ }
438
443
 
439
444
  /**
440
445
  * Destroy function
441
446
  * @ignore
442
447
  */
443
- destroy : function () {
448
+ destroy() {
444
449
  pool.push(this.fillStyle);
445
450
  pool.push(this.strokeStyle);
446
451
  this.fillStyle = this.strokeStyle = undefined;
447
452
  this._text.length = 0;
448
- this._super(Renderable, "destroy");
453
+ super.destroy();
449
454
  }
450
- });
455
+ };
451
456
 
452
457
  export default Text;
@@ -325,5 +325,3 @@ export let Easing = {
325
325
  }
326
326
 
327
327
  };
328
-
329
- /* eslint-enable quotes, keyword-spacing, comma-spacing, no-return-assign */
@@ -3,8 +3,6 @@
3
3
  * https://github.com/tweenjs/tween.js
4
4
  */
5
5
 
6
- /* eslint-disable quotes, keyword-spacing, comma-spacing, no-return-assign */
7
-
8
6
  /**
9
7
  * Interpolation Function :<br>
10
8
  * <p>
@@ -72,7 +70,7 @@ export let Interpolation = {
72
70
 
73
71
  },
74
72
  /** @ignore */
75
- Bernstein: function ( n , i ) {
73
+ Bernstein: function ( n, i ) {
76
74
 
77
75
  var fc = Interpolation.Utils.Factorial;
78
76
  return fc( n ) / fc( i ) / fc( n - i );
@@ -88,7 +86,8 @@ export let Interpolation = {
88
86
  var s = 1, i;
89
87
  if ( a[ n ] ) return a[ n ];
90
88
  for ( i = n; i > 1; i-- ) s *= i;
91
- return a[ n ] = s;
89
+ a[ n ] = s;
90
+ return s;
92
91
 
93
92
  };
94
93
 
@@ -98,11 +97,7 @@ export let Interpolation = {
98
97
 
99
98
  var v0 = ( p2 - p0 ) * 0.5, v1 = ( p3 - p1 ) * 0.5, t2 = t * t, t3 = t * t2;
100
99
  return ( 2 * p1 - 2 * p2 + v0 + v1 ) * t3 + ( - 3 * p1 + 3 * p2 - 2 * v0 - v1 ) * t2 + v0 * t + p1;
101
-
102
100
  }
103
-
104
101
  }
105
102
 
106
103
  };
107
-
108
- /* eslint-enable quotes, keyword-spacing, comma-spacing, no-return-assign */