melonjs 10.8.0 → 10.11.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/LICENSE.md +1 -1
  2. package/README.md +32 -25
  3. package/dist/melonjs.js +1833 -2267
  4. package/dist/melonjs.min.js +4 -4
  5. package/dist/melonjs.module.d.ts +642 -1416
  6. package/dist/melonjs.module.js +1778 -2237
  7. package/package.json +16 -16
  8. package/src/audio/audio.js +0 -1
  9. package/src/camera/camera2d.js +1 -16
  10. package/src/entity/entity.js +1 -4
  11. package/src/game.js +2 -2
  12. package/src/geometries/ellipse.js +18 -27
  13. package/src/geometries/line.js +5 -8
  14. package/src/geometries/path2d.js +10 -20
  15. package/src/geometries/poly.js +28 -45
  16. package/src/geometries/rectangle.js +24 -36
  17. package/src/geometries/roundrect.js +96 -3
  18. package/src/index.js +7 -2
  19. package/src/input/gamepad.js +5 -16
  20. package/src/input/keyboard.js +1 -9
  21. package/src/input/pointer.js +0 -1
  22. package/src/input/pointerevent.js +14 -23
  23. package/src/lang/deprecated.js +9 -6
  24. package/src/level/level.js +0 -9
  25. package/src/level/tiled/TMXGroup.js +0 -4
  26. package/src/level/tiled/TMXLayer.js +0 -8
  27. package/src/level/tiled/TMXObject.js +0 -3
  28. package/src/level/tiled/TMXTile.js +4 -5
  29. package/src/level/tiled/TMXTileMap.js +1 -7
  30. package/src/level/tiled/TMXTileset.js +0 -5
  31. package/src/level/tiled/TMXTilesetGroup.js +1 -4
  32. package/src/level/tiled/TMXUtils.js +1 -4
  33. package/src/level/tiled/renderer/TMXHexagonalRenderer.js +2 -3
  34. package/src/level/tiled/renderer/TMXIsometricRenderer.js +0 -1
  35. package/src/level/tiled/renderer/TMXRenderer.js +1 -7
  36. package/src/loader/loader.js +0 -11
  37. package/src/loader/loadingscreen.js +16 -5
  38. package/src/math/color.js +10 -30
  39. package/src/math/math.js +0 -10
  40. package/src/math/matrix2.js +12 -27
  41. package/src/math/matrix3.js +1 -22
  42. package/src/math/observable_vector2.js +0 -29
  43. package/src/math/observable_vector3.js +0 -29
  44. package/src/math/vector2.js +3 -40
  45. package/src/math/vector3.js +4 -41
  46. package/src/particles/emitter.js +11 -12
  47. package/src/physics/body.js +1 -1
  48. package/src/physics/bounds.js +5 -19
  49. package/src/physics/collision.js +0 -1
  50. package/src/physics/detector.js +0 -4
  51. package/src/physics/quadtree.js +0 -7
  52. package/src/physics/sat.js +3 -3
  53. package/src/physics/world.js +0 -4
  54. package/src/plugin/plugin.js +0 -2
  55. package/src/polyfill/index.js +1 -0
  56. package/src/polyfill/roundrect.js +237 -0
  57. package/src/renderable/GUI.js +5 -10
  58. package/src/renderable/collectable.js +1 -0
  59. package/src/renderable/container.js +26 -54
  60. package/src/renderable/dragndrop.js +0 -9
  61. package/src/renderable/imagelayer.js +3 -7
  62. package/src/renderable/light2d.js +114 -0
  63. package/src/renderable/renderable.js +22 -43
  64. package/src/renderable/sprite.js +13 -25
  65. package/src/renderable/trigger.js +1 -1
  66. package/src/state/stage.js +72 -6
  67. package/src/state/state.js +3 -20
  68. package/src/system/device.js +14 -53
  69. package/src/system/event.js +11 -0
  70. package/src/system/pooling.js +19 -8
  71. package/src/system/save.js +9 -11
  72. package/src/system/timer.js +239 -218
  73. package/src/text/bitmaptextdata.js +1 -4
  74. package/src/text/glyph.js +2 -2
  75. package/src/text/text.js +19 -21
  76. package/src/text/textmetrics.js +0 -2
  77. package/src/tweens/easing.js +1 -1
  78. package/src/tweens/interpolation.js +2 -2
  79. package/src/tweens/tween.js +1 -13
  80. package/src/utils/agent.js +1 -3
  81. package/src/utils/array.js +0 -3
  82. package/src/utils/file.js +0 -2
  83. package/src/utils/function.js +0 -2
  84. package/src/utils/string.js +0 -6
  85. package/src/utils/utils.js +2 -5
  86. package/src/video/canvas/canvas_renderer.js +76 -103
  87. package/src/video/renderer.js +43 -50
  88. package/src/video/{texture.js → texture/atlas.js} +8 -8
  89. package/src/video/{texture_cache.js → texture/cache.js} +4 -5
  90. package/src/video/texture/canvas_texture.js +99 -0
  91. package/src/video/video.js +3 -3
  92. package/src/video/webgl/glshader.js +0 -5
  93. package/src/video/webgl/utils/uniforms.js +4 -7
  94. package/src/video/webgl/webgl_compositor.js +0 -14
  95. package/src/video/webgl/webgl_renderer.js +73 -97
@@ -9,9 +9,9 @@ import pool from "./../system/pooling.js";
9
9
  * A polygon is convex when all line segments connecting two points in the interior do not cross any edge of the polygon
10
10
  * (which means that all angles are less than 180 degrees), as described here below : <br>
11
11
  * <center><img src="images/convex_polygon.png"/></center><br>
12
+ *
12
13
  * A polygon's `winding` is clockwise iff its vertices (points) are declared turning to the right. The image above shows COUNTERCLOCKWISE winding.
13
14
  */
14
-
15
15
  class Polygon {
16
16
 
17
17
  /**
@@ -25,16 +25,16 @@ class Polygon {
25
25
  * @public
26
26
  * @type {Vector2d}
27
27
  * @name pos
28
- * @memberof Polygon.prototype
28
+ * @memberof Polygon
29
29
  */
30
30
  this.pos = pool.pull("Vector2d");
31
31
 
32
32
  /**
33
33
  * The bounding rectangle for this shape
34
34
  * @ignore
35
- * @type {Bounds}
35
+ * @member {Bounds}
36
36
  * @name _bounds
37
- * @memberof Polygon.prototype
37
+ * @memberof Polygon
38
38
  */
39
39
  this._bounds;
40
40
 
@@ -44,7 +44,7 @@ class Polygon {
44
44
  * @public
45
45
  * @type {Vector2d[]}
46
46
  * @name points
47
- * @memberof Polygon.prototype
47
+ * @memberof Polygon
48
48
  */
49
49
  this.points = [];
50
50
 
@@ -83,8 +83,7 @@ class Polygon {
83
83
  /**
84
84
  * set new value to the Polygon
85
85
  * @name setShape
86
- * @memberof Polygon.prototype
87
- * @function
86
+ * @memberof Polygon
88
87
  * @param {number} x position of the Polygon
89
88
  * @param {number} y position of the Polygon
90
89
  * @param {Vector2d[]|number[]} points array of vector or vertice defining the Polygon
@@ -99,8 +98,7 @@ class Polygon {
99
98
  /**
100
99
  * set the vertices defining this Polygon
101
100
  * @name setVertices
102
- * @memberof Polygon.prototype
103
- * @function
101
+ * @memberof Polygon
104
102
  * @param {Vector2d[]} vertices array of vector or vertice defining the Polygon
105
103
  * @returns {Polygon} this instance for objecf chaining
106
104
  */
@@ -139,8 +137,7 @@ class Polygon {
139
137
  /**
140
138
  * apply the given transformation matrix to this Polygon
141
139
  * @name transform
142
- * @memberof Polygon.prototype
143
- * @function
140
+ * @memberof Polygon
144
141
  * @param {Matrix2d} m the transformation matrix
145
142
  * @returns {Polygon} Reference to this object for method chaining
146
143
  */
@@ -158,8 +155,7 @@ class Polygon {
158
155
  /**
159
156
  * apply an isometric projection to this shape
160
157
  * @name toIso
161
- * @memberof Polygon.prototype
162
- * @function
158
+ * @memberof Polygon
163
159
  * @returns {Polygon} Reference to this object for method chaining
164
160
  */
165
161
  toIso() {
@@ -169,8 +165,7 @@ class Polygon {
169
165
  /**
170
166
  * apply a 2d projection to this shape
171
167
  * @name to2d
172
- * @memberof Polygon.prototype
173
- * @function
168
+ * @memberof Polygon
174
169
  * @returns {Polygon} Reference to this object for method chaining
175
170
  */
176
171
  to2d() {
@@ -180,8 +175,7 @@ class Polygon {
180
175
  /**
181
176
  * Rotate this Polygon (counter-clockwise) by the specified angle (in radians).
182
177
  * @name rotate
183
- * @memberof Polygon.prototype
184
- * @function
178
+ * @memberof Polygon
185
179
  * @param {number} angle The angle to rotate (in radians)
186
180
  * @param {Vector2d|ObservableVector2d} [v] an optional point to rotate around
187
181
  * @returns {Polygon} Reference to this object for method chaining
@@ -202,8 +196,7 @@ class Polygon {
202
196
  /**
203
197
  * Scale this Polygon by the given scalar.
204
198
  * @name scale
205
- * @memberof Polygon.prototype
206
- * @function
199
+ * @memberof Polygon
207
200
  * @param {number} x
208
201
  * @param {number} [y=x]
209
202
  * @returns {Polygon} Reference to this object for method chaining
@@ -224,8 +217,7 @@ class Polygon {
224
217
  /**
225
218
  * Scale this Polygon by the given vector
226
219
  * @name scaleV
227
- * @memberof Polygon.prototype
228
- * @function
220
+ * @memberof Polygon
229
221
  * @param {Vector2d} v
230
222
  * @returns {Polygon} Reference to this object for method chaining
231
223
  */
@@ -237,8 +229,7 @@ class Polygon {
237
229
  * Computes the calculated collision polygon.
238
230
  * This **must** be called if the `points` array, `angle`, or `offset` is modified manually.
239
231
  * @name recalc
240
- * @memberof Polygon.prototype
241
- * @function
232
+ * @memberof Polygon
242
233
  * @returns {Polygon} Reference to this object for method chaining
243
234
  */
244
235
  recalc() {
@@ -281,8 +272,7 @@ class Polygon {
281
272
  /**
282
273
  * returns a list of indices for all triangles defined in this polygon
283
274
  * @name getIndices
284
- * @memberof Polygon.prototype
285
- * @function
275
+ * @memberof Polygon
286
276
  * @returns {Array} an array of vertex indices for all triangles forming this polygon.
287
277
  */
288
278
  getIndices() {
@@ -295,8 +285,7 @@ class Polygon {
295
285
  /**
296
286
  * Returns true if the vertices composing this polygon form a convex shape (vertices must be in clockwise order).
297
287
  * @name isConvex
298
- * @memberof Polygon.prototype
299
- * @function
288
+ * @memberof Polygon
300
289
  * @returns {boolean} true if the vertices are convex, false if not, null if not computable
301
290
  */
302
291
  isConvex() {
@@ -342,8 +331,8 @@ class Polygon {
342
331
  /**
343
332
  * translate the Polygon by the specified offset
344
333
  * @name translate
345
- * @memberof Polygon.prototype
346
- * @function
334
+ * @memberof Polygon
335
+ * @method
347
336
  * @param {number} x x offset
348
337
  * @param {number} y y offset
349
338
  * @returns {Polygon} this Polygon
@@ -351,8 +340,7 @@ class Polygon {
351
340
  /**
352
341
  * translate the Polygon by the specified vector
353
342
  * @name translate
354
- * @memberof Polygon.prototype
355
- * @function
343
+ * @memberof Polygon
356
344
  * @param {Vector2d} v vector offset
357
345
  * @returns {Polygon} Reference to this object for method chaining
358
346
  */
@@ -379,15 +367,14 @@ class Polygon {
379
367
  /**
380
368
  * Shifts the Polygon to the given position vector.
381
369
  * @name shift
382
- * @memberof Polygon.prototype
383
- * @function
370
+ * @memberof Polygon
371
+ * @method
384
372
  * @param {Vector2d} position
385
373
  */
386
374
  /**
387
375
  * Shifts the Polygon to the given x, y position.
388
376
  * @name shift
389
- * @memberof Polygon.prototype
390
- * @function
377
+ * @memberof Polygon
391
378
  * @param {number} x
392
379
  * @param {number} y
393
380
  */
@@ -412,8 +399,8 @@ class Polygon {
412
399
  * (Note: it is highly recommended to first do a hit test on the corresponding <br>
413
400
  * bounding rect, as the function can be highly consuming with complex shapes)
414
401
  * @name contains
415
- * @memberof Polygon.prototype
416
- * @function
402
+ * @memberof Polygon
403
+ * @method
417
404
  * @param {Vector2d} point
418
405
  * @returns {boolean} true if contains
419
406
  */
@@ -423,8 +410,7 @@ class Polygon {
423
410
  * (Note: it is highly recommended to first do a hit test on the corresponding <br>
424
411
  * bounding rect, as the function can be highly consuming with complex shapes)
425
412
  * @name contains
426
- * @memberof Polygon.prototype
427
- * @function
413
+ * @memberof Polygon
428
414
  * @param {number} x x coordinate
429
415
  * @param {number} y y coordinate
430
416
  * @returns {boolean} true if contains
@@ -461,8 +447,7 @@ class Polygon {
461
447
  /**
462
448
  * returns the bounding box for this shape, the smallest Rectangle object completely containing this shape.
463
449
  * @name getBounds
464
- * @memberof Polygon.prototype
465
- * @function
450
+ * @memberof Polygon
466
451
  * @returns {Bounds} this shape bounding box Rectangle object
467
452
  */
468
453
  getBounds() {
@@ -476,8 +461,7 @@ class Polygon {
476
461
  * update the bounding box for this shape.
477
462
  * @ignore
478
463
  * @name updateBounds
479
- * @memberof Polygon.prototype
480
- * @function
464
+ * @memberof Polygon
481
465
  * @returns {Bounds} this shape bounding box Rectangle object
482
466
  */
483
467
  updateBounds() {
@@ -492,8 +476,7 @@ class Polygon {
492
476
  /**
493
477
  * clone this Polygon
494
478
  * @name clone
495
- * @memberof Polygon.prototype
496
- * @function
479
+ * @memberof Polygon
497
480
  * @returns {Polygon} new Polygon
498
481
  */
499
482
  clone() {
@@ -32,8 +32,7 @@ class Rect extends Polygon {
32
32
  /**
33
33
  * set new value to the rectangle shape
34
34
  * @name setShape
35
- * @memberof Rect.prototype
36
- * @function
35
+ * @memberof Rect
37
36
  * @param {number} x position of the Rectangle
38
37
  * @param {number} y position of the Rectangle
39
38
  * @param {number|Vector2d[]} w width of the rectangle, or an array of vector defining the rectangle
@@ -63,7 +62,7 @@ class Rect extends Polygon {
63
62
  * @public
64
63
  * @type {number}
65
64
  * @name left
66
- * @memberof Rect.prototype
65
+ * @memberof Rect
67
66
  */
68
67
  get left() {
69
68
  return this.pos.x;
@@ -74,7 +73,7 @@ class Rect extends Polygon {
74
73
  * @public
75
74
  * @type {number}
76
75
  * @name right
77
- * @memberof Rect.prototype
76
+ * @memberof Rect
78
77
  */
79
78
  get right() {
80
79
  var w = this.width;
@@ -86,7 +85,7 @@ class Rect extends Polygon {
86
85
  * @public
87
86
  * @type {number}
88
87
  * @name top
89
- * @memberof Rect.prototype
88
+ * @memberof Rect
90
89
  */
91
90
  get top() {
92
91
  return this.pos.y;
@@ -97,7 +96,7 @@ class Rect extends Polygon {
97
96
  * @public
98
97
  * @type {number}
99
98
  * @name bottom
100
- * @memberof Rect.prototype
99
+ * @memberof Rect
101
100
  */
102
101
  get bottom() {
103
102
  var h = this.height;
@@ -109,7 +108,7 @@ class Rect extends Polygon {
109
108
  * @public
110
109
  * @type {number}
111
110
  * @name width
112
- * @memberof Rect.prototype
111
+ * @memberof Rect
113
112
  */
114
113
  get width() {
115
114
  return this.points[2].x;
@@ -125,7 +124,7 @@ class Rect extends Polygon {
125
124
  * @public
126
125
  * @type {number}
127
126
  * @name height
128
- * @memberof Rect.prototype
127
+ * @memberof Rect
129
128
  */
130
129
  get height() {
131
130
  return this.points[2].y;
@@ -141,7 +140,7 @@ class Rect extends Polygon {
141
140
  * @public
142
141
  * @type {number}
143
142
  * @name centerX
144
- * @memberof Rect.prototype
143
+ * @memberof Rect
145
144
  */
146
145
  get centerX() {
147
146
  if (isFinite(this.width)) {
@@ -159,7 +158,7 @@ class Rect extends Polygon {
159
158
  * @public
160
159
  * @type {number}
161
160
  * @name centerY
162
- * @memberof Rect.prototype
161
+ * @memberof Rect
163
162
  */
164
163
  get centerY() {
165
164
  if (isFinite(this.height)) {
@@ -175,8 +174,7 @@ class Rect extends Polygon {
175
174
  /**
176
175
  * center the rectangle position around the given coordinates
177
176
  * @name centerOn
178
- * @memberof Rect.prototype
179
- * @function
177
+ * @memberof Rect
180
178
  * @param {number} x the x coordinate around which to center this rectangle
181
179
  * @param {number} x the y coordinate around which to center this rectangle
182
180
  * @returns {Rect} this rectangle
@@ -190,8 +188,7 @@ class Rect extends Polygon {
190
188
  /**
191
189
  * resize the rectangle
192
190
  * @name resize
193
- * @memberof Rect.prototype
194
- * @function
191
+ * @memberof Rect
195
192
  * @param {number} w new width of the rectangle
196
193
  * @param {number} h new height of the rectangle
197
194
  * @returns {Rect} this rectangle
@@ -205,8 +202,7 @@ class Rect extends Polygon {
205
202
  /**
206
203
  * scale the rectangle
207
204
  * @name scale
208
- * @memberof Rect.prototype
209
- * @function
205
+ * @memberof Rect
210
206
  * @param {number} x a number representing the abscissa of the scaling vector.
211
207
  * @param {number} [y=x] a number representing the ordinate of the scaling vector.
212
208
  * @returns {Rect} this rectangle
@@ -220,8 +216,7 @@ class Rect extends Polygon {
220
216
  /**
221
217
  * clone this rectangle
222
218
  * @name clone
223
- * @memberof Rect.prototype
224
- * @function
219
+ * @memberof Rect
225
220
  * @returns {Rect} new rectangle
226
221
  */
227
222
  clone() {
@@ -231,8 +226,7 @@ class Rect extends Polygon {
231
226
  /**
232
227
  * copy the position and size of the given rectangle into this one
233
228
  * @name copy
234
- * @memberof Rect.prototype
235
- * @function
229
+ * @memberof Rect
236
230
  * @param {Rect} rect Source rectangle
237
231
  * @returns {Rect} new rectangle
238
232
  */
@@ -243,8 +237,7 @@ class Rect extends Polygon {
243
237
  /**
244
238
  * merge this rectangle with another one
245
239
  * @name union
246
- * @memberof Rect.prototype
247
- * @function
240
+ * @memberof Rect
248
241
  * @param {Rect} rect other rectangle to union with
249
242
  * @returns {Rect} the union(ed) rectangle
250
243
  */
@@ -265,8 +258,7 @@ class Rect extends Polygon {
265
258
  /**
266
259
  * check if this rectangle is intersecting with the specified one
267
260
  * @name overlaps
268
- * @memberof Rect.prototype
269
- * @function
261
+ * @memberof Rect
270
262
  * @param {Rect} rect
271
263
  * @returns {boolean} true if overlaps
272
264
  */
@@ -282,8 +274,8 @@ class Rect extends Polygon {
282
274
  /**
283
275
  * Returns true if the rectangle contains the given rectangle
284
276
  * @name contains
285
- * @memberof Rect.prototype
286
- * @function
277
+ * @memberof Rect
278
+ * @method
287
279
  * @param {Rect} rect
288
280
  * @returns {boolean} true if contains
289
281
  */
@@ -291,8 +283,8 @@ class Rect extends Polygon {
291
283
  /**
292
284
  * Returns true if the rectangle contains the given point
293
285
  * @name contains
294
- * @memberof Rect.prototype
295
- * @function
286
+ * @memberof Rect
287
+ * @method
296
288
  * @param {number} x x coordinate
297
289
  * @param {number} y y coordinate
298
290
  * @returns {boolean} true if contains
@@ -301,8 +293,7 @@ class Rect extends Polygon {
301
293
  /**
302
294
  * Returns true if the rectangle contains the given point
303
295
  * @name contains
304
- * @memberof Rect.prototype
305
- * @function
296
+ * @memberof Rect
306
297
  * @param {Vector2d} point
307
298
  * @returns {boolean} true if contains
308
299
  */
@@ -337,8 +328,7 @@ class Rect extends Polygon {
337
328
  /**
338
329
  * check if this rectangle is identical to the specified one
339
330
  * @name equals
340
- * @memberof Rect.prototype
341
- * @function
331
+ * @memberof Rect
342
332
  * @param {Rect} rect
343
333
  * @returns {boolean} true if equals
344
334
  */
@@ -354,8 +344,7 @@ class Rect extends Polygon {
354
344
  /**
355
345
  * determines whether all coordinates of this rectangle are finite numbers.
356
346
  * @name isFinite
357
- * @memberof Rect.prototype
358
- * @function
347
+ * @memberof Rect
359
348
  * @returns {boolean} false if all coordinates are positive or negative Infinity or NaN; otherwise, true.
360
349
  */
361
350
  isFinite() {
@@ -365,8 +354,7 @@ class Rect extends Polygon {
365
354
  /**
366
355
  * Returns a polygon whose edges are the same as this box.
367
356
  * @name toPolygon
368
- * @memberof Rect.prototype
369
- * @function
357
+ * @memberof Rect
370
358
  * @returns {Polygon} a new Polygon that represents this rectangle.
371
359
  */
372
360
  toPolygon() {
@@ -36,7 +36,7 @@ class RoundRect extends Rect {
36
36
  * @type {number}
37
37
  * @default 20
38
38
  * @name radius
39
- * @memberof RoundRect.prototype
39
+ * @memberof RoundRect
40
40
  */
41
41
  get radius() {
42
42
  return this._radius;
@@ -52,11 +52,104 @@ class RoundRect extends Rect {
52
52
  this._radius = value;
53
53
  }
54
54
 
55
+ /**
56
+ * copy the position, size and radius of the given rounded rectangle into this one
57
+ * @name copy
58
+ * @memberof RoundRect
59
+ * @param {RoundRect} rrect source rounded rectangle
60
+ * @returns {RoundRect} new rectangle
61
+ */
62
+ copy(rrect) {
63
+ super.setShape(rrect.pos.x, rrect.pos.y, rrect.width, rrect.height);
64
+ this.radius = rrect.radius;
65
+ return this;
66
+ }
67
+
68
+ /**
69
+ * Returns true if the rounded rectangle contains the given point
70
+ * @name contains
71
+ * @memberof RoundRect
72
+ * @method
73
+ * @param {number} x x coordinate
74
+ * @param {number} y y coordinate
75
+ * @returns {boolean} true if contains
76
+ */
77
+
78
+ /**
79
+ * Returns true if the rounded rectangle contains the given point
80
+ * @name contains
81
+ * @memberof RoundRect
82
+ * @param {Vector2d} point
83
+ * @returns {boolean} true if contains
84
+ */
85
+ contains() {
86
+ var arg0 = arguments[0];
87
+ var _x, _y;
88
+ if (arguments.length === 2) {
89
+ // x, y
90
+ _x = arg0;
91
+ _y = arguments[1];
92
+ } else {
93
+ if (arg0 instanceof Rect) {
94
+ // good enough
95
+ return super.contains(arg0);
96
+ } else {
97
+ // vector
98
+ _x = arg0.x;
99
+ _y = arg0.y;
100
+ }
101
+ }
102
+
103
+ // check whether point is outside the bounding box
104
+ if (_x < this.left || _x >= this.right || _y < this.top || _y >= this.bottom) {
105
+ return false; // outside bounding box
106
+ }
107
+
108
+ // check whether point is within the bounding box minus radius
109
+ if ((_x >= this.left + this.radius && _x <= this.right - this.radius) || (_y >= this.top + this.radius && _y <= this.bottom - this.radius)) {
110
+ return true;
111
+ }
112
+
113
+ // check whether point is in one of the rounded corner areas
114
+ var tx, ty;
115
+ var radiusX = Math.max(0, Math.min(this.radius, this.width / 2));
116
+ var radiusY = Math.max(0, Math.min(this.radius, this.height / 2));
117
+
118
+ if (_x < this.left + radiusX && _y < this.top + radiusY) {
119
+ tx = _x - this.left - radiusX;
120
+ ty = _y - this.top - radiusY;
121
+ } else if (_x > this.right - radiusX && _y < this.top + radiusY) {
122
+ tx = _x - this.right + radiusX;
123
+ ty = _y - this.top - radiusY;
124
+ } else if (_x > this.right - radiusX && _y > this.bottom - radiusY) {
125
+ tx = _x - this.right + radiusX;
126
+ ty = _y - this.bottom + radiusY;
127
+ } else if (_x < this.left + radiusX && _y > this.bottom - radiusY) {
128
+ tx = _x - this.left - radiusX;
129
+ ty = _y - this.bottom + radiusY;
130
+ } else {
131
+ return false; // inside and not within the rounded corner area
132
+ }
133
+
134
+ // Pythagorean theorem.
135
+ return ((tx * tx) + (ty * ty) <= (radiusX * radiusY));
136
+ }
137
+
138
+ /**
139
+ * check if this RoundRect is identical to the specified one
140
+ * @name equals
141
+ * @memberof RoundRect
142
+ * @param {RoundRect} rrect
143
+ * @returns {boolean} true if equals
144
+ */
145
+ equals(rrect) {
146
+ return super.equals(rrect) && this.radius === rrect.radius;
147
+ }
148
+
55
149
  /**
56
150
  * clone this RoundRect
57
151
  * @name clone
58
- * @memberof RoundRect.prototype
59
- * @function
152
+ * @memberof RoundRect
60
153
  * @returns {RoundRect} new RoundRect
61
154
  */
62
155
  clone() {
package/src/index.js CHANGED
@@ -41,7 +41,8 @@ import WebGLCompositor from "./video/webgl/webgl_compositor.js";
41
41
  import Renderer from "./video/renderer.js";
42
42
  import WebGLRenderer from "./video/webgl/webgl_renderer.js";
43
43
  import CanvasRenderer from "./video/canvas/canvas_renderer.js";
44
- import { TextureAtlas } from "./video/texture.js";
44
+ import CanvasTexture from "./video/texture/canvas_texture.js";
45
+ import { TextureAtlas } from "./video/texture/atlas.js";
45
46
  import Renderable from "./renderable/renderable.js";
46
47
  import Text from "./text/text.js";
47
48
  import BitmapText from "./text/bitmaptext.js";
@@ -53,6 +54,7 @@ import NineSliceSprite from "./renderable/nineslicesprite.js";
53
54
  import GUI_Object from "./renderable/GUI.js";
54
55
  import Collectable from "./renderable/collectable.js";
55
56
  import Trigger from "./renderable/trigger.js";
57
+ import Light2d from "./renderable/light2d.js";
56
58
  import { Draggable, DropTarget } from "./renderable/dragndrop.js";
57
59
  import TMXRenderer from "./level/tiled/renderer/TMXRenderer.js";
58
60
  import TMXOrthogonalRenderer from "./level/tiled/renderer/TMXOrthogonalRenderer.js";
@@ -140,6 +142,7 @@ export {
140
142
  GUI_Object,
141
143
  Collectable,
142
144
  Trigger,
145
+ Light2d,
143
146
  Draggable,
144
147
  DropTarget,
145
148
  TMXRenderer,
@@ -190,7 +193,6 @@ export var skipAutoInit = false;
190
193
  * @name boot
191
194
  * @see skipAutoInit
192
195
  * @public
193
- * @function
194
196
  */
195
197
  export function boot() {
196
198
  // don't do anything if already initialized (should not happen anyway)
@@ -202,6 +204,7 @@ export function boot() {
202
204
  pool.register("me.Entity", Entity);
203
205
  pool.register("me.Collectable", Collectable);
204
206
  pool.register("me.Trigger", Trigger);
207
+ pool.register("me.Light2d", Light2d);
205
208
  pool.register("me.Tween", Tween, true);
206
209
  pool.register("me.Color", Color, true);
207
210
  pool.register("me.Particle", Particle, true);
@@ -230,6 +233,7 @@ export function boot() {
230
233
  pool.register("Entity", Entity);
231
234
  pool.register("Collectable", Collectable);
232
235
  pool.register("Trigger", Trigger);
236
+ pool.register("Light2d", Light2d);
233
237
  pool.register("Tween", Tween, true);
234
238
  pool.register("Color", Color, true);
235
239
  pool.register("Particle", Particle, true);
@@ -253,6 +257,7 @@ export function boot() {
253
257
  pool.register("Line", Line, true);
254
258
  pool.register("Ellipse", Ellipse, true);
255
259
  pool.register("Bounds", Bounds, true);
260
+ pool.register("CanvasTexture", CanvasTexture, true);
256
261
 
257
262
  // publish Boot notification
258
263
  event.emit(event.BOOT);
@@ -57,8 +57,8 @@ var leadingZeroRE = /^0+/;
57
57
  function addMapping(id, mapping) {
58
58
  var expanded_id = id.replace(vendorProductRE, function (_, a, b) {
59
59
  return (
60
- "000".substr(a.length - 1) + a + "-" +
61
- "000".substr(b.length - 1) + b + "-"
60
+ "000".slice(a.length - 1) + a + "-" +
61
+ "000".slice(b.length - 1) + b + "-"
62
62
  );
63
63
  });
64
64
  var sparse_id = id.replace(vendorProductRE, function (_, a, b) {
@@ -86,10 +86,7 @@ var remap = new Map();
86
86
 
87
87
  var updateEventHandler;
88
88
 
89
- /**
90
- * Default gamepad mappings
91
- * @ignore
92
- */
89
+ // Default gamepad mappings
93
90
  [
94
91
  // Firefox mappings
95
92
  [
@@ -261,18 +258,14 @@ var updateGamepads = function () {
261
258
  });
262
259
  };
263
260
 
264
- /**
265
- * gamepad connected callback
266
- * @ignore
267
- */
261
+ // gamepad connected callback
268
262
  if (globalThis.navigator && typeof globalThis.navigator.getGamepads === "function") {
269
263
  globalThis.addEventListener("gamepadconnected", function (e) {
270
264
  event.emit(event.GAMEPAD_CONNECTED, e.gamepad);
271
265
  }, false);
272
266
 
273
- /**
267
+ /*
274
268
  * gamepad disconnected callback
275
- * @ignore
276
269
  */
277
270
  globalThis.addEventListener("gamepaddisconnected", function (e) {
278
271
  event.emit(event.GAMEPAD_DISCONNECTED, e.gamepad);
@@ -362,7 +355,6 @@ export var GAMEPAD = {
362
355
  * @name bindGamepad
363
356
  * @memberof input
364
357
  * @public
365
- * @function
366
358
  * @param {number} index Gamepad index
367
359
  * @param {object} button Button/Axis definition
368
360
  * @param {string} button.type "buttons" or "axes"
@@ -437,7 +429,6 @@ export function bindGamepad(index, button, keyCode) {
437
429
  * @name unbindGamepad
438
430
  * @memberof input
439
431
  * @public
440
- * @function
441
432
  * @param {number} index Gamepad index
442
433
  * @param {number} button (See {@link input.GAMEPAD.BUTTONS})
443
434
  * @example
@@ -456,7 +447,6 @@ export function unbindGamepad(index, button) {
456
447
  * @name setGamepadDeadzone
457
448
  * @memberof input
458
449
  * @public
459
- * @function
460
450
  * @param {number} value Deadzone value
461
451
  */
462
452
  export function setGamepadDeadzone(value) {
@@ -470,7 +460,6 @@ export function setGamepadDeadzone(value) {
470
460
  * @name setGamepadMapping
471
461
  * @memberof input
472
462
  * @public
473
- * @function
474
463
  * @param {string} id Gamepad id string
475
464
  * @param {object} mapping A hash table
476
465
  * @param {number[]} mapping.axes Standard analog control stick axis locations