melonjs 10.2.0 → 10.3.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 +1 -1
  2. package/dist/melonjs.js +4435 -4283
  3. package/dist/melonjs.min.js +4 -4
  4. package/dist/melonjs.module.d.ts +3348 -3833
  5. package/dist/melonjs.module.js +4025 -3920
  6. package/package.json +13 -14
  7. package/src/audio/audio.js +45 -45
  8. package/src/camera/camera2d.js +78 -101
  9. package/src/entity/draggable.js +21 -29
  10. package/src/entity/droptarget.js +24 -31
  11. package/src/entity/entity.js +34 -38
  12. package/src/game.js +8 -8
  13. package/src/{shapes → geometries}/ellipse.js +46 -46
  14. package/src/{shapes → geometries}/line.js +14 -14
  15. package/src/{shapes → geometries}/poly.js +103 -54
  16. package/src/{shapes → geometries}/rectangle.js +73 -120
  17. package/src/index.js +18 -19
  18. package/src/input/gamepad.js +20 -20
  19. package/src/input/input.js +3 -3
  20. package/src/input/keyboard.js +122 -124
  21. package/src/input/pointer.js +102 -62
  22. package/src/input/pointerevent.js +97 -42
  23. package/src/lang/deprecated.js +29 -18
  24. package/src/level/level.js +34 -26
  25. package/src/level/tiled/TMXGroup.js +12 -13
  26. package/src/level/tiled/TMXLayer.js +41 -42
  27. package/src/level/tiled/TMXObject.js +76 -70
  28. package/src/level/tiled/TMXTile.js +13 -15
  29. package/src/level/tiled/TMXTileMap.js +26 -25
  30. package/src/level/tiled/TMXTileset.js +14 -15
  31. package/src/level/tiled/TMXTilesetGroup.js +5 -6
  32. package/src/level/tiled/TMXUtils.js +13 -11
  33. package/src/level/tiled/renderer/TMXHexagonalRenderer.js +3 -4
  34. package/src/level/tiled/renderer/TMXIsometricRenderer.js +3 -4
  35. package/src/level/tiled/renderer/TMXOrthogonalRenderer.js +2 -3
  36. package/src/level/tiled/renderer/TMXRenderer.js +18 -19
  37. package/src/level/tiled/renderer/TMXStaggeredRenderer.js +2 -3
  38. package/src/loader/loader.js +46 -40
  39. package/src/loader/loadingscreen.js +7 -7
  40. package/src/math/color.js +68 -88
  41. package/src/math/math.js +33 -33
  42. package/src/math/matrix2.js +70 -71
  43. package/src/math/matrix3.js +90 -91
  44. package/src/math/observable_vector2.js +91 -92
  45. package/src/math/observable_vector3.js +110 -106
  46. package/src/math/vector2.js +116 -104
  47. package/src/math/vector3.js +129 -110
  48. package/src/particles/emitter.js +116 -126
  49. package/src/particles/particle.js +4 -5
  50. package/src/particles/particlecontainer.js +2 -3
  51. package/src/physics/body.js +82 -83
  52. package/src/physics/bounds.js +64 -66
  53. package/src/physics/collision.js +21 -22
  54. package/src/physics/detector.js +13 -13
  55. package/src/physics/quadtree.js +26 -25
  56. package/src/physics/sat.js +21 -21
  57. package/src/physics/world.js +23 -22
  58. package/src/plugin/plugin.js +12 -13
  59. package/src/renderable/GUI.js +20 -26
  60. package/src/renderable/collectable.js +6 -7
  61. package/src/renderable/colorlayer.js +11 -12
  62. package/src/renderable/container.js +98 -81
  63. package/src/renderable/imagelayer.js +33 -35
  64. package/src/renderable/nineslicesprite.js +15 -16
  65. package/src/renderable/renderable.js +112 -111
  66. package/src/renderable/sprite.js +71 -58
  67. package/src/renderable/trigger.js +17 -19
  68. package/src/state/stage.js +14 -15
  69. package/src/state/state.js +78 -78
  70. package/src/system/device.js +137 -180
  71. package/src/system/event.js +116 -104
  72. package/src/system/pooling.js +15 -15
  73. package/src/system/save.js +9 -6
  74. package/src/system/timer.js +33 -33
  75. package/src/text/bitmaptext.js +39 -46
  76. package/src/text/bitmaptextdata.js +14 -15
  77. package/src/text/text.js +55 -58
  78. package/src/tweens/easing.js +5 -5
  79. package/src/tweens/interpolation.js +5 -5
  80. package/src/tweens/tween.js +49 -40
  81. package/src/utils/agent.js +12 -11
  82. package/src/utils/array.js +8 -8
  83. package/src/utils/file.js +7 -7
  84. package/src/utils/function.js +8 -8
  85. package/src/utils/string.js +19 -19
  86. package/src/utils/utils.js +23 -23
  87. package/src/video/canvas/canvas_renderer.js +127 -128
  88. package/src/video/renderer.js +69 -69
  89. package/src/video/texture.js +80 -82
  90. package/src/video/texture_cache.js +2 -4
  91. package/src/video/video.js +38 -38
  92. package/src/video/webgl/buffer/vertex.js +11 -3
  93. package/src/video/webgl/glshader.js +31 -32
  94. package/src/video/webgl/webgl_compositor.js +145 -127
  95. package/src/video/webgl/webgl_renderer.js +196 -175
@@ -5,31 +5,30 @@ import * as event from "./../system/event.js";
5
5
  import device from "./../system/device.js";
6
6
  import { setPrefixed } from "./../utils/agent.js";
7
7
  import { Texture } from "./texture.js";
8
- import Rect from "./../shapes/rectangle.js";
9
- import Ellipse from "./../shapes/ellipse.js";
10
- import Polygon from "./../shapes/poly.js";
11
- import Line from "./../shapes/line.js";
8
+ import Rect from "./../geometries/rectangle.js";
9
+ import Ellipse from "./../geometries/ellipse.js";
10
+ import Polygon from "./../geometries/poly.js";
11
+ import Line from "./../geometries/line.js";
12
12
  import Bounds from "./../physics/bounds.js";
13
13
 
14
14
  /**
15
15
  * @classdesc
16
16
  * a base renderer object
17
17
  * @class Renderer
18
- * @memberOf me
19
- * @constructor
20
- * @param {Object} options The renderer parameters
21
- * @param {Number} options.width The width of the canvas without scaling
22
- * @param {Number} options.height The height of the canvas without scaling
18
+ * @memberof me
19
+ * @param {object} options The renderer parameters
20
+ * @param {number} options.width The width of the canvas without scaling
21
+ * @param {number} options.height The height of the canvas without scaling
23
22
  * @param {HTMLCanvasElement} [options.canvas] The html canvas to draw to on screen
24
- * @param {Boolean} [options.doubleBuffering=false] Whether to enable double buffering
25
- * @param {Boolean} [options.antiAlias=false] Whether to enable anti-aliasing, use false (default) for a pixelated effect.
26
- * @param {Boolean} [options.failIfMajorPerformanceCaveat=true] If true, the renderer will switch to CANVAS mode if the performances of a WebGL context would be dramatically lower than that of a native application making equivalent OpenGL calls.
27
- * @param {Boolean} [options.transparent=false] Whether to enable transparency on the canvas (performance hit when enabled)
28
- * @param {Boolean} [options.blendMode="normal"] the default blend mode to use ("normal", "multiply")
29
- * @param {Boolean} [options.subPixel=false] Whether to enable subpixel rendering (performance hit when enabled)
30
- * @param {Boolean} [options.verbose=false] Enable the verbose mode that provides additional details as to what the renderer is doing
31
- * @param {Number} [options.zoomX=width] The actual width of the canvas with scaling applied
32
- * @param {Number} [options.zoomY=height] The actual height of the canvas with scaling applied
23
+ * @param {boolean} [options.doubleBuffering=false] Whether to enable double buffering
24
+ * @param {boolean} [options.antiAlias=false] Whether to enable anti-aliasing, use false (default) for a pixelated effect.
25
+ * @param {boolean} [options.failIfMajorPerformanceCaveat=true] If true, the renderer will switch to CANVAS mode if the performances of a WebGL context would be dramatically lower than that of a native application making equivalent OpenGL calls.
26
+ * @param {boolean} [options.transparent=false] Whether to enable transparency on the canvas (performance hit when enabled)
27
+ * @param {boolean} [options.blendMode="normal"] the default blend mode to use ("normal", "multiply")
28
+ * @param {boolean} [options.subPixel=false] Whether to enable subpixel rendering (performance hit when enabled)
29
+ * @param {boolean} [options.verbose=false] Enable the verbose mode that provides additional details as to what the renderer is doing
30
+ * @param {number} [options.zoomX=width] The actual width of the canvas with scaling applied
31
+ * @param {number} [options.zoomY=height] The actual height of the canvas with scaling applied
33
32
  */
34
33
  class Renderer {
35
34
 
@@ -38,17 +37,17 @@ class Renderer {
38
37
  * The given constructor options
39
38
  * @public
40
39
  * @name settings
41
- * @memberOf me.Renderer#
42
- * @enum {Object}
40
+ * @memberof me.Renderer#
41
+ * @enum {object}
43
42
  */
44
43
  this.settings = options;
45
44
 
46
45
  /**
47
46
  * true if the current rendering context is valid
48
47
  * @name isContextValid
49
- * @memberOf me.Renderer
48
+ * @memberof me.Renderer
50
49
  * @default true
51
- * type {Boolean}
50
+ * type {boolean}
52
51
  */
53
52
  this.isContextValid = true;
54
53
 
@@ -104,7 +103,7 @@ class Renderer {
104
103
  /**
105
104
  * prepare the framebuffer for drawing a new frame
106
105
  * @name clear
107
- * @memberOf me.Renderer.prototype
106
+ * @memberof me.Renderer.prototype
108
107
  * @function
109
108
  */
110
109
  clear() {}
@@ -112,7 +111,7 @@ class Renderer {
112
111
  /**
113
112
  * Reset context state
114
113
  * @name reset
115
- * @memberOf me.Renderer.prototype
114
+ * @memberof me.Renderer.prototype
116
115
  * @function
117
116
  */
118
117
  reset() {
@@ -130,9 +129,9 @@ class Renderer {
130
129
  /**
131
130
  * return a reference to the system canvas
132
131
  * @name getCanvas
133
- * @memberOf me.Renderer.prototype
132
+ * @memberof me.Renderer.prototype
134
133
  * @function
135
- * @return {HTMLCanvasElement}
134
+ * @returns {HTMLCanvasElement}
136
135
  */
137
136
  getCanvas() {
138
137
  return this.backBufferCanvas;
@@ -141,9 +140,9 @@ class Renderer {
141
140
  /**
142
141
  * return a reference to the screen canvas
143
142
  * @name getScreenCanvas
144
- * @memberOf me.Renderer.prototype
143
+ * @memberof me.Renderer.prototype
145
144
  * @function
146
- * @return {HTMLCanvasElement}
145
+ * @returns {HTMLCanvasElement}
147
146
  */
148
147
  getScreenCanvas() {
149
148
  return this.canvas;
@@ -153,9 +152,9 @@ class Renderer {
153
152
  * return a reference to the screen canvas corresponding 2d Context<br>
154
153
  * (will return buffered context if double buffering is enabled, or a reference to the Screen Context)
155
154
  * @name getScreenContext
156
- * @memberOf me.Renderer.prototype
155
+ * @memberof me.Renderer.prototype
157
156
  * @function
158
- * @return {Context2d}
157
+ * @returns {CanvasRenderingContext2D}
159
158
  */
160
159
  getScreenContext() {
161
160
  return this.context;
@@ -164,9 +163,9 @@ class Renderer {
164
163
  /**
165
164
  * returns the current blend mode for this renderer
166
165
  * @name getBlendMode
167
- * @memberOf me.Renderer.prototype
166
+ * @memberof me.Renderer.prototype
168
167
  * @function
169
- * @return {String} blend mode
168
+ * @returns {string} blend mode
170
169
  */
171
170
  getBlendMode() {
172
171
  return this.currentBlendMode;
@@ -176,21 +175,21 @@ class Renderer {
176
175
  * Returns the 2D Context object of the given Canvas<br>
177
176
  * Also configures anti-aliasing and blend modes based on constructor options.
178
177
  * @name getContext2d
179
- * @memberOf me.Renderer.prototype
178
+ * @memberof me.Renderer.prototype
180
179
  * @function
181
180
  * @param {HTMLCanvasElement} canvas
182
- * @param {Boolean} [transparent=true] use false to disable transparency
183
- * @return {CanvasRenderingContext2D}
181
+ * @param {boolean} [transparent=true] use false to disable transparency
182
+ * @returns {CanvasRenderingContext2D}
184
183
  */
185
- getContext2d(c, transparent) {
186
- if (typeof c === "undefined" || c === null) {
184
+ getContext2d(canvas, transparent) {
185
+ if (typeof canvas === "undefined" || canvas === null) {
187
186
  throw new Error(
188
187
  "You must pass a canvas element in order to create " +
189
188
  "a 2d context"
190
189
  );
191
190
  }
192
191
 
193
- if (typeof c.getContext === "undefined") {
192
+ if (typeof canvas.getContext === "undefined") {
194
193
  throw new Error(
195
194
  "Your browser does not support HTML5 canvas."
196
195
  );
@@ -200,12 +199,12 @@ class Renderer {
200
199
  transparent = true;
201
200
  }
202
201
 
203
- var _context = c.getContext("2d", {
202
+ var _context = canvas.getContext("2d", {
204
203
  "alpha" : transparent
205
204
  });
206
205
 
207
206
  if (!_context.canvas) {
208
- _context.canvas = c;
207
+ _context.canvas = canvas;
209
208
  }
210
209
  this.setAntiAlias(_context, this.settings.antiAlias);
211
210
  return _context;
@@ -214,9 +213,9 @@ class Renderer {
214
213
  /**
215
214
  * return the width of the system Canvas
216
215
  * @name getWidth
217
- * @memberOf me.Renderer.prototype
216
+ * @memberof me.Renderer.prototype
218
217
  * @function
219
- * @return {Number}
218
+ * @returns {number}
220
219
  */
221
220
  getWidth() {
222
221
  return this.backBufferCanvas.width;
@@ -225,9 +224,9 @@ class Renderer {
225
224
  /**
226
225
  * return the height of the system Canvas
227
226
  * @name getHeight
228
- * @memberOf me.Renderer.prototype
227
+ * @memberof me.Renderer.prototype
229
228
  * @function
230
- * @return {Number}
229
+ * @returns {number} height of the system Canvas
231
230
  */
232
231
  getHeight() {
233
232
  return this.backBufferCanvas.height;
@@ -236,9 +235,9 @@ class Renderer {
236
235
  /**
237
236
  * get the current fill & stroke style color.
238
237
  * @name getColor
239
- * @memberOf me.Renderer.prototype
238
+ * @memberof me.Renderer.prototype
240
239
  * @function
241
- * @param {me.Color} current global color
240
+ * @returns {me.Color} current global color
242
241
  */
243
242
  getColor() {
244
243
  return this.currentColor;
@@ -247,9 +246,9 @@ class Renderer {
247
246
  /**
248
247
  * return the current global alpha
249
248
  * @name globalAlpha
250
- * @memberOf me.Renderer.prototype
249
+ * @memberof me.Renderer.prototype
251
250
  * @function
252
- * @return {Number}
251
+ * @returns {number}
253
252
  */
254
253
  globalAlpha() {
255
254
  return this.currentColor.glArray[3];
@@ -258,10 +257,10 @@ class Renderer {
258
257
  /**
259
258
  * check if the given rect or bounds overlaps with the renderer screen coordinates
260
259
  * @name overlaps
261
- * @memberOf me.Renderer.prototype
260
+ * @memberof me.Renderer.prototype
262
261
  * @function
263
262
  * @param {me.Rect|me.Bounds} bounds
264
- * @return {boolean} true if overlaps
263
+ * @returns {boolean} true if overlaps
265
264
  */
266
265
  overlaps(bounds) {
267
266
  return (
@@ -274,10 +273,10 @@ class Renderer {
274
273
  /**
275
274
  * resizes the system canvas
276
275
  * @name resize
277
- * @memberOf me.Renderer.prototype
276
+ * @memberof me.Renderer.prototype
278
277
  * @function
279
- * @param {Number} width new width of the canvas
280
- * @param {Number} height new height of the canvas
278
+ * @param {number} width new width of the canvas
279
+ * @param {number} height new height of the canvas
281
280
  */
282
281
  resize(width, height) {
283
282
  if (width !== this.backBufferCanvas.width || height !== this.backBufferCanvas.height) {
@@ -295,10 +294,10 @@ class Renderer {
295
294
  /**
296
295
  * enable/disable image smoothing (scaling interpolation) for the given context
297
296
  * @name setAntiAlias
298
- * @memberOf me.Renderer.prototype
297
+ * @memberof me.Renderer.prototype
299
298
  * @function
300
- * @param {Context2d} context
301
- * @param {Boolean} [enable=false]
299
+ * @param {CanvasRenderingContext2D} context
300
+ * @param {boolean} [enable=false]
302
301
  */
303
302
  setAntiAlias(context, enable) {
304
303
  var canvas = context.canvas;
@@ -325,7 +324,7 @@ class Renderer {
325
324
  /**
326
325
  * set/change the current projection matrix (WebGL only)
327
326
  * @name setProjection
328
- * @memberOf me.Renderer.prototype
327
+ * @memberof me.Renderer.prototype
329
328
  * @function
330
329
  * @param {me.Matrix3d} matrix
331
330
  */
@@ -336,9 +335,10 @@ class Renderer {
336
335
  /**
337
336
  * stroke the given shape
338
337
  * @name stroke
339
- * @memberOf me.Renderer.prototype
338
+ * @memberof me.Renderer.prototype
340
339
  * @function
341
340
  * @param {me.Rect|me.Polygon|me.Line|me.Ellipse} shape a shape object to stroke
341
+ * @param {boolean} [fill=false] fill the shape with the current color if true
342
342
  */
343
343
  stroke(shape, fill) {
344
344
  if (shape instanceof Rect || shape instanceof Bounds) {
@@ -359,12 +359,12 @@ class Renderer {
359
359
  /**
360
360
  * tint the given image or canvas using the given color
361
361
  * @name tint
362
- * @memberOf me.Renderer.prototype
362
+ * @memberof me.Renderer.prototype
363
363
  * @function
364
- * @param {HTMLImageElement|HTMLCanvasElement|OffscreenCanvas} image the source image to be tinted
365
- * @param {me.Color|String} color the color that will be used to tint the image
366
- * @param {String} [mode="multiply"] the composition mode used to tint the image
367
- * @return {HTMLCanvasElement|OffscreenCanvas} a new canvas element representing the tinted image
364
+ * @param {HTMLImageElement|HTMLCanvasElement|OffscreenCanvas} src the source image to be tinted
365
+ * @param {me.Color|string} color the color that will be used to tint the image
366
+ * @param {string} [mode="multiply"] the composition mode used to tint the image
367
+ * @returns {HTMLCanvasElement|OffscreenCanvas} a new canvas element representing the tinted image
368
368
  */
369
369
  tint(src, color, mode) {
370
370
  var canvas = createCanvas(src.width, src.height, true);
@@ -388,7 +388,7 @@ class Renderer {
388
388
  /**
389
389
  * fill the given shape
390
390
  * @name fill
391
- * @memberOf me.Renderer.prototype
391
+ * @memberof me.Renderer.prototype
392
392
  * @function
393
393
  * @param {me.Rect|me.Polygon|me.Line|me.Ellipse} shape a shape object to fill
394
394
  */
@@ -401,7 +401,7 @@ class Renderer {
401
401
  * So, if the renderable is larger than the mask, only the intersecting part of the renderable will be visible.
402
402
  * Mask are not preserved through renderer context save and restore.
403
403
  * @name setMask
404
- * @memberOf me.Renderer.prototype
404
+ * @memberof me.Renderer.prototype
405
405
  * @function
406
406
  * @param {me.Rect|me.Polygon|me.Line|me.Ellipse} [mask] the shape defining the mask to be applied
407
407
  */
@@ -412,7 +412,7 @@ class Renderer {
412
412
  * disable (remove) the rendering mask set through setMask.
413
413
  * @name clearMask
414
414
  * @see me.Renderer#setMask
415
- * @memberOf me.Renderer.prototype
415
+ * @memberof me.Renderer.prototype
416
416
  * @function
417
417
  */
418
418
  clearMask() {}
@@ -420,10 +420,10 @@ class Renderer {
420
420
  /**
421
421
  * set a coloring tint for sprite based renderables
422
422
  * @name setTint
423
- * @memberOf me.Renderer.prototype
423
+ * @memberof me.Renderer.prototype
424
424
  * @function
425
425
  * @param {me.Color} tint the tint color
426
- * @param {Number} [alpha] an alpha value to be applied to the tint
426
+ * @param {number} [alpha] an alpha value to be applied to the tint
427
427
  */
428
428
  setTint(tint, alpha = tint.alpha) {
429
429
  // global tint color
@@ -435,7 +435,7 @@ class Renderer {
435
435
  * clear the rendering tint set through setTint.
436
436
  * @name clearTint
437
437
  * @see me.Renderer#setTint
438
- * @memberOf me.Renderer.prototype
438
+ * @memberof me.Renderer.prototype
439
439
  * @function
440
440
  */
441
441
  clearTint() {
@@ -8,62 +8,60 @@ import loader from "./../loader/loader.js";
8
8
  import { ETA } from "./../math/math.js";
9
9
 
10
10
  /**
11
- * @classdesc
12
- * A Texture atlas object, currently supports : <br>
13
- * - [TexturePacker]{@link http://www.codeandweb.com/texturepacker/} : through JSON export (standard and multipack texture atlas) <br>
14
- * - [ShoeBox]{@link http://renderhjs.net/shoebox/} : through JSON export using the
15
- * melonJS setting [file]{@link https://github.com/melonjs/melonJS/raw/master/media/shoebox_JSON_export.sbx} <br>
16
- * - [Free Texture Packer]{@link http://free-tex-packer.com/app/} : through JSON export (standard and multipack texture atlas) <br>
17
- * - Standard (fixed cell size) spritesheet : through a {framewidth:xx, frameheight:xx, anchorPoint:me.Vector2d} object
18
- * @class Texture
19
- * @memberOf me.Renderer
20
- * @constructor
21
- * @param {Object|Object[]} atlas atlas information. See {@link me.loader.getJSON}
22
- * @param {HTMLImageElement|HTMLCanvasElement|String|HTMLImageElement[]|HTMLCanvasElement[]|String[]} [source=atlas.meta.image] Image source
23
- * @param {Boolean} [cached=false] Use true to skip caching this Texture
24
- * @example
25
- * // create a texture atlas from a JSON Object
26
- * game.texture = new me.video.renderer.Texture(
27
- * me.loader.getJSON("texture")
28
- * );
29
- *
30
- * // create a texture atlas from a multipack JSON Object
31
- * game.texture = new me.video.renderer.Texture([
32
- * me.loader.getJSON("texture-0"),
33
- * me.loader.getJSON("texture-1"),
34
- * me.loader.getJSON("texture-2")
35
- * ]);
36
- *
37
- * // create a texture atlas for a spritesheet with an anchorPoint in the center of each frame
38
- * game.texture = new me.video.renderer.Texture(
39
- * {
40
- * framewidth : 32,
41
- * frameheight : 32,
42
- * anchorPoint : new me.Vector2d(0.5, 0.5)
43
- * },
44
- * me.loader.getImage("spritesheet")
45
- * );
46
- */
47
-
48
- /**
49
- * create a simple 1 frame texture atlas based on the given parameters
50
- * @ignore
51
- */
11
+ * create a simple 1 frame texture atlas based on the given parameters
12
+ * @ignore
13
+ */
52
14
  export function createAtlas(width, height, name = "default", repeat = "no-repeat") {
53
- return {
54
- "meta" : {
55
- "app" : "melonJS",
56
- "size" : { "w" : width, "h" : height },
57
- "repeat" : repeat,
58
- "image" : "default"
59
- },
60
- "frames" : [{
61
- "filename" : name,
62
- "frame" : { "x" : 0, "y" : 0, "w" : width, "h" : height }
63
- }]
64
- };
15
+ return {
16
+ "meta" : {
17
+ "app" : "melonJS",
18
+ "size" : { "w" : width, "h" : height },
19
+ "repeat" : repeat,
20
+ "image" : "default"
21
+ },
22
+ "frames" : [{
23
+ "filename" : name,
24
+ "frame" : { "x" : 0, "y" : 0, "w" : width, "h" : height }
25
+ }]
26
+ };
65
27
  }
66
28
 
29
+ /**
30
+ * @classdesc
31
+ * A Texture atlas object, currently supports : <br>
32
+ * - [TexturePacker]{@link http://www.codeandweb.com/texturepacker/} : through JSON export (standard and multipack texture atlas) <br>
33
+ * - [ShoeBox]{@link http://renderhjs.net/shoebox/} : through JSON export using the
34
+ * melonJS setting [file]{@link https://github.com/melonjs/melonJS/raw/master/media/shoebox_JSON_export.sbx} <br>
35
+ * - [Free Texture Packer]{@link http://free-tex-packer.com/app/} : through JSON export (standard and multipack texture atlas) <br>
36
+ * - Standard (fixed cell size) spritesheet : through a {framewidth:xx, frameheight:xx, anchorPoint:me.Vector2d} object
37
+ * @class Texture
38
+ * @memberof me.Renderer
39
+ * @param {object|object[]} atlases atlas information. See {@link me.loader.getJSON}
40
+ * @param {HTMLImageElement|HTMLCanvasElement|string|HTMLImageElement[]|HTMLCanvasElement[]|string[]} [src=atlas.meta.image] Image source
41
+ * @param {boolean} [cache=false] Use true to skip caching this Texture
42
+ * @example
43
+ * // create a texture atlas from a JSON Object
44
+ * game.texture = new me.video.renderer.Texture(
45
+ * me.loader.getJSON("texture")
46
+ * );
47
+ *
48
+ * // create a texture atlas from a multipack JSON Object
49
+ * game.texture = new me.video.renderer.Texture([
50
+ * me.loader.getJSON("texture-0"),
51
+ * me.loader.getJSON("texture-1"),
52
+ * me.loader.getJSON("texture-2")
53
+ * ]);
54
+ *
55
+ * // create a texture atlas for a spritesheet with an anchorPoint in the center of each frame
56
+ * game.texture = new me.video.renderer.Texture(
57
+ * {
58
+ * framewidth : 32,
59
+ * frameheight : 32,
60
+ * anchorPoint : new me.Vector2d(0.5, 0.5)
61
+ * },
62
+ * me.loader.getImage("spritesheet")
63
+ * );
64
+ */
67
65
  export class Texture {
68
66
 
69
67
  constructor (atlases, src, cache) {
@@ -75,14 +73,14 @@ export class Texture {
75
73
 
76
74
  /**
77
75
  * the texture source(s) itself
78
- * @type Map
76
+ * @type {Map}
79
77
  * @ignore
80
78
  */
81
79
  this.sources = new Map();
82
80
 
83
81
  /**
84
82
  * the atlas dictionnaries
85
- * @type Map
83
+ * @type {Map}
86
84
  * @ignore
87
85
  */
88
86
  this.atlases = new Map();
@@ -325,14 +323,14 @@ export class Texture {
325
323
  /**
326
324
  * return the default or specified atlas dictionnary
327
325
  * @name getAtlas
328
- * @memberOf me.Renderer.Texture
326
+ * @memberof me.Renderer.Texture
329
327
  * @function
330
- * @param {String} [name] atlas name in case of multipack textures
331
- * @return {Object}
328
+ * @param {string} [name] atlas name in case of multipack textures
329
+ * @returns {object}
332
330
  */
333
- getAtlas(key) {
334
- if (typeof key === "string") {
335
- return this.atlases.get(key);
331
+ getAtlas(name) {
332
+ if (typeof name === "string") {
333
+ return this.atlases.get(name);
336
334
  } else {
337
335
  return this.atlases.values().next().value;
338
336
  }
@@ -341,9 +339,9 @@ export class Texture {
341
339
  /**
342
340
  * return the format of the atlas dictionnary
343
341
  * @name getFormat
344
- * @memberOf me.Renderer.Texture
342
+ * @memberof me.Renderer.Texture
345
343
  * @function
346
- * @return {String} will return "texturepacker", or "ShoeBox", or "melonJS", or "Spritesheet (fixed cell size)"
344
+ * @returns {string} will return "texturepacker", or "ShoeBox", or "melonJS", or "Spritesheet (fixed cell size)"
347
345
  */
348
346
  getFormat() {
349
347
  return this.format;
@@ -352,10 +350,10 @@ export class Texture {
352
350
  /**
353
351
  * return the source texture for the given region (or default one if none specified)
354
352
  * @name getTexture
355
- * @memberOf me.Renderer.Texture
353
+ * @memberof me.Renderer.Texture
356
354
  * @function
357
- * @param {Object} [region] region name in case of multipack textures
358
- * @return {HTMLImageElement|HTMLCanvasElement}
355
+ * @param {object} [region] region name in case of multipack textures
356
+ * @returns {HTMLImageElement|HTMLCanvasElement}
359
357
  */
360
358
  getTexture(region) {
361
359
  if ((typeof region === "object") && (typeof region.texture === "string")) {
@@ -368,11 +366,11 @@ export class Texture {
368
366
  /**
369
367
  * return a normalized region (or frame) information for the specified sprite name
370
368
  * @name getRegion
371
- * @memberOf me.Renderer.Texture
369
+ * @memberof me.Renderer.Texture
372
370
  * @function
373
- * @param {String} name name of the sprite
374
- * @param {String} [atlas] name of a specific atlas where to search for the region
375
- * @return {Object}
371
+ * @param {string} name name of the sprite
372
+ * @param {string} [atlas] name of a specific atlas where to search for the region
373
+ * @returns {object}
376
374
  */
377
375
  getRegion(name, atlas) {
378
376
  var region;
@@ -393,10 +391,10 @@ export class Texture {
393
391
  /**
394
392
  * return the uvs mapping for the given region
395
393
  * @name getUVs
396
- * @memberOf me.Renderer.Texture
394
+ * @memberof me.Renderer.Texture
397
395
  * @function
398
- * @param {Object} region region (or frame) name
399
- * @return {Float32Array} region Uvs
396
+ * @param {object} name region (or frame) name
397
+ * @returns {Float32Array} region Uvs
400
398
  */
401
399
  getUVs(name) {
402
400
  // Get the source texture region
@@ -417,12 +415,12 @@ export class Texture {
417
415
  /**
418
416
  * Create a sprite object using the first region found using the specified name
419
417
  * @name createSpriteFromName
420
- * @memberOf me.Renderer.Texture
418
+ * @memberof me.Renderer.Texture
421
419
  * @function
422
- * @param {String} name name of the sprite
423
- * @param {Object} [settings] Additional settings passed to the {@link me.Sprite} contructor
424
- * @param {Boolean} [nineSlice=false] if true returns a 9-slice sprite
425
- * @return {me.Sprite|me.NineSliceSprite}
420
+ * @param {string} name name of the sprite
421
+ * @param {object} [settings] Additional settings passed to the {@link me.Sprite} contructor
422
+ * @param {boolean} [nineSlice=false] if true returns a 9-slice sprite
423
+ * @returns {me.Sprite|me.NineSliceSprite}
426
424
  * @example
427
425
  * // create a new texture object under the `game` namespace
428
426
  * game.texture = new me.video.renderer.Texture(
@@ -460,12 +458,12 @@ export class Texture {
460
458
  /**
461
459
  * Create an animation object using the first region found using all specified names
462
460
  * @name createAnimationFromName
463
- * @memberOf me.Renderer.Texture
461
+ * @memberof me.Renderer.Texture
464
462
  * @function
465
- * @param {String[]|Number[]} names list of names for each sprite
463
+ * @param {string[]|number[]} names list of names for each sprite
466
464
  * (when manually creating a Texture out of a spritesheet, only numeric values are authorized)
467
- * @param {Object} [settings] Additional settings passed to the {@link me.Sprite} contructor
468
- * @return {me.Sprite}
465
+ * @param {object} [settings] Additional settings passed to the {@link me.Sprite} contructor
466
+ * @returns {me.Sprite}
469
467
  * @example
470
468
  * // create a new texture object under the `game` namespace
471
469
  * game.texture = new me.video.renderer.Texture(
@@ -60,11 +60,9 @@ class TextureCache {
60
60
  /**
61
61
  * @ignore
62
62
  */
63
- remove(image) {
63
+ delete(image) {
64
64
  if (!this.cache.has(image)) {
65
- if (this.cache.remove(image) === true) {
66
- this.length--;
67
- }
65
+ this.cache.delete(image);
68
66
  }
69
67
  }
70
68