melonjs 10.9.0 → 10.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (96) hide show
  1. package/LICENSE.md +1 -1
  2. package/README.md +32 -25
  3. package/dist/melonjs.js +1635 -2383
  4. package/dist/melonjs.min.js +4 -4
  5. package/dist/melonjs.module.d.ts +929 -1504
  6. package/dist/melonjs.module.js +1581 -2344
  7. package/package.json +18 -18
  8. package/src/audio/audio.js +0 -1
  9. package/src/camera/camera2d.js +1 -16
  10. package/src/entity/entity.js +6 -11
  11. package/src/game.js +2 -2
  12. package/src/geometries/ellipse.js +19 -28
  13. package/src/geometries/line.js +5 -8
  14. package/src/geometries/path2d.js +14 -24
  15. package/src/geometries/poly.js +29 -47
  16. package/src/geometries/rectangle.js +25 -37
  17. package/src/geometries/roundrect.js +8 -12
  18. package/src/index.js +7 -2
  19. package/src/input/gamepad.js +3 -14
  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 +4 -5
  48. package/src/physics/bounds.js +5 -19
  49. package/src/physics/collision.js +1 -13
  50. package/src/physics/detector.js +6 -56
  51. package/src/physics/quadtree.js +0 -7
  52. package/src/physics/response.js +48 -0
  53. package/src/physics/sat.js +4 -4
  54. package/src/physics/world.js +0 -4
  55. package/src/plugin/plugin.js +0 -2
  56. package/src/polyfill/roundrect.js +4 -2
  57. package/src/renderable/GUI.js +11 -14
  58. package/src/renderable/collectable.js +1 -0
  59. package/src/renderable/colorlayer.js +9 -7
  60. package/src/renderable/container.js +38 -64
  61. package/src/renderable/dragndrop.js +1 -10
  62. package/src/renderable/imagelayer.js +8 -12
  63. package/src/renderable/light2d.js +118 -0
  64. package/src/renderable/renderable.js +27 -48
  65. package/src/renderable/sprite.js +17 -29
  66. package/src/renderable/trigger.js +10 -3
  67. package/src/state/stage.js +72 -6
  68. package/src/state/state.js +22 -23
  69. package/src/system/device.js +14 -53
  70. package/src/system/event.js +11 -0
  71. package/src/system/pooling.js +20 -9
  72. package/src/system/save.js +9 -11
  73. package/src/system/timer.js +239 -218
  74. package/src/text/bitmaptextdata.js +1 -4
  75. package/src/text/glyph.js +2 -2
  76. package/src/text/text.js +25 -24
  77. package/src/text/textmetrics.js +0 -2
  78. package/src/tweens/easing.js +1 -1
  79. package/src/tweens/interpolation.js +2 -2
  80. package/src/tweens/tween.js +1 -13
  81. package/src/utils/agent.js +1 -3
  82. package/src/utils/array.js +0 -3
  83. package/src/utils/file.js +0 -2
  84. package/src/utils/function.js +0 -2
  85. package/src/utils/string.js +0 -6
  86. package/src/utils/utils.js +0 -3
  87. package/src/video/canvas/canvas_renderer.js +73 -90
  88. package/src/video/renderer.js +34 -49
  89. package/src/video/{texture.js → texture/atlas.js} +10 -8
  90. package/src/video/{texture_cache.js → texture/cache.js} +4 -5
  91. package/src/video/texture/canvas_texture.js +99 -0
  92. package/src/video/video.js +3 -3
  93. package/src/video/webgl/glshader.js +0 -5
  94. package/src/video/webgl/utils/uniforms.js +3 -6
  95. package/src/video/webgl/webgl_compositor.js +0 -14
  96. package/src/video/webgl/webgl_renderer.js +73 -97
@@ -18,7 +18,7 @@ var globalFloatingCounter = 0;
18
18
 
19
19
  /**
20
20
  * @classdesc
21
- * me.Container represents a collection of child objects
21
+ * Container represents a collection of child objects
22
22
  * @augments Renderable
23
23
  */
24
24
  class Container extends Renderable {
@@ -100,10 +100,9 @@ class Container extends Renderable {
100
100
  * a callback to be extended, triggered after a child has been added or removed
101
101
  * @name onChildChange
102
102
  * @memberof Container#
103
- * @function
104
103
  * @param {number} index added or removed child index
105
104
  */
106
- this.onChildChange = function (/* index */) {
105
+ this.onChildChange = function (index) { // eslint-disable-line no-unused-vars
107
106
  // to be extended
108
107
  };
109
108
 
@@ -157,7 +156,6 @@ class Container extends Renderable {
157
156
  * reset the container, removing all childrens, and reseting transforms.
158
157
  * @name reset
159
158
  * @memberof Container
160
- * @function
161
159
  */
162
160
  reset() {
163
161
  // cancel any sort operation
@@ -189,11 +187,12 @@ class Container extends Renderable {
189
187
  * Adding a child to the container will automatically remove it from its other container.
190
188
  * Meaning a child can only have one parent. This is important if you add a renderable
191
189
  * to a container then add it to the me.game.world container it will move it out of the
192
- * orginal container. Then when the me.game.world.reset() is called the renderable
193
- * will not be in any container.
190
+ * orginal container. Then when the me.game.world.reset() is called the renderable
191
+ * will not be in any container. <br>
192
+ * if the given child implements a onActivateEvent method, that method will be called
193
+ * once the child is added to this container.
194
194
  * @name addChild
195
- * @memberof Container.prototype
196
- * @function
195
+ * @memberof Container
197
196
  * @param {Renderable} child
198
197
  * @param {number} [z] forces the z index of the child to the specified value
199
198
  * @returns {Renderable} the added child
@@ -256,8 +255,7 @@ class Container extends Renderable {
256
255
  * Add a child to the container at the specified index<br>
257
256
  * (the list won't be sorted after insertion)
258
257
  * @name addChildAt
259
- * @memberof Container.prototype
260
- * @function
258
+ * @memberof Container
261
259
  * @param {Renderable} child
262
260
  * @param {number} index
263
261
  * @returns {Renderable} the added child
@@ -315,8 +313,7 @@ class Container extends Renderable {
315
313
  * - The index of element in the array. <br>
316
314
  * - The array forEach() was called upon. <br>
317
315
  * @name forEach
318
- * @memberof Container.prototype
319
- * @function
316
+ * @memberof Container
320
317
  * @param {Function} callback fnction to execute on each element
321
318
  * @param {object} [thisArg] value to use as this(i.e reference Object) when executing callback.
322
319
  * @example
@@ -352,8 +349,7 @@ class Container extends Renderable {
352
349
  /**
353
350
  * Swaps the position (z-index) of 2 children
354
351
  * @name swapChildren
355
- * @memberof Container.prototype
356
- * @function
352
+ * @memberof Container
357
353
  * @param {Renderable} child
358
354
  * @param {Renderable} child2
359
355
  */
@@ -380,8 +376,7 @@ class Container extends Renderable {
380
376
  /**
381
377
  * Returns the Child at the specified index
382
378
  * @name getChildAt
383
- * @memberof Container.prototype
384
- * @function
379
+ * @memberof Container
385
380
  * @param {number} index
386
381
  * @returns {Renderable} the child at the specified index
387
382
  */
@@ -397,8 +392,7 @@ class Container extends Renderable {
397
392
  /**
398
393
  * Returns the index of the given Child
399
394
  * @name getChildIndex
400
- * @memberof Container.prototype
401
- * @function
395
+ * @memberof Container
402
396
  * @param {Renderable} child
403
397
  * @returns {number} index
404
398
  */
@@ -410,7 +404,6 @@ class Container extends Renderable {
410
404
  * Returns the next child within the container or undefined if none
411
405
  * @name getNextChild
412
406
  * @memberof Container
413
- * @function
414
407
  * @param {Renderable} child
415
408
  * @returns {Renderable} child
416
409
  */
@@ -425,8 +418,7 @@ class Container extends Renderable {
425
418
  /**
426
419
  * Returns true if contains the specified Child
427
420
  * @name hasChild
428
- * @memberof Container.prototype
429
- * @function
421
+ * @memberof Container
430
422
  * @param {Renderable} child
431
423
  * @returns {boolean}
432
424
  */
@@ -439,9 +431,8 @@ class Container extends Renderable {
439
431
  * note : avoid calling this function every frame since
440
432
  * it parses the whole object tree each time
441
433
  * @name getChildByProp
442
- * @memberof Container.prototype
434
+ * @memberof Container
443
435
  * @public
444
- * @function
445
436
  * @param {string} prop Property name
446
437
  * @param {string|RegExp|number|boolean} value Value of the property
447
438
  * @returns {Renderable[]} Array of childs
@@ -491,9 +482,8 @@ class Container extends Renderable {
491
482
  /**
492
483
  * returns the list of childs with the specified class type
493
484
  * @name getChildByType
494
- * @memberof Container.prototype
485
+ * @memberof Container
495
486
  * @public
496
- * @function
497
487
  * @param {object} classType
498
488
  * @returns {Renderable[]} Array of children
499
489
  */
@@ -518,9 +508,8 @@ class Container extends Renderable {
518
508
  * note : avoid calling this function every frame since
519
509
  * it parses the whole object list each time
520
510
  * @name getChildByName
521
- * @memberof Container.prototype
511
+ * @memberof Container
522
512
  * @public
523
- * @function
524
513
  * @param {string|RegExp|number|boolean} name child name
525
514
  * @returns {Renderable[]} Array of children
526
515
  */
@@ -533,9 +522,8 @@ class Container extends Renderable {
533
522
  * note : avoid calling this function every frame since
534
523
  * it parses the whole object list each time
535
524
  * @name getChildByGUID
536
- * @memberof Container.prototype
525
+ * @memberof Container
537
526
  * @public
538
- * @function
539
527
  * @param {string|RegExp|number|boolean} guid child GUID
540
528
  * @returns {Renderable} corresponding child or null
541
529
  */
@@ -547,9 +535,8 @@ class Container extends Renderable {
547
535
  /**
548
536
  * return all child in this container
549
537
  * @name getChildren
550
- * @memberof Container.prototype
538
+ * @memberof Container
551
539
  * @public
552
- * @function
553
540
  * @returns {Renderable[]} an array of renderable object
554
541
  */
555
542
  getChildren() {
@@ -563,8 +550,7 @@ class Container extends Renderable {
563
550
  * update the bounding box for this shape.
564
551
  * @ignore
565
552
  * @name updateBounds
566
- * @memberof Renderable.prototype
567
- * @function
553
+ * @memberof Renderable
568
554
  * @returns {Bounds} this shape bounding box Rectangle object
569
555
  */
570
556
  updateBounds(forceUpdateChildBounds = false) {
@@ -592,8 +578,7 @@ class Container extends Renderable {
592
578
  * Checks if this container is root or if it's attached to the root container.
593
579
  * @private
594
580
  * @name isAttachedToRoot
595
- * @memberof Container.prototype
596
- * @function
581
+ * @memberof Container
597
582
  * @returns {boolean}
598
583
  */
599
584
  isAttachedToRoot() {
@@ -615,8 +600,7 @@ class Container extends Renderable {
615
600
  * update the cointainer's bounding rect (private)
616
601
  * @ignore
617
602
  * @name updateBoundsPos
618
- * @memberof Container.prototype
619
- * @function
603
+ * @memberof Container
620
604
  */
621
605
  updateBoundsPos(newX, newY) {
622
606
  // call the parent method
@@ -648,11 +632,11 @@ class Container extends Renderable {
648
632
  }
649
633
 
650
634
  /**
651
- * Invokes the removeChildNow in a defer, to ensure the child is removed safely after the update & draw stack has completed
635
+ * Invokes the removeChildNow in a defer, to ensure the child is removed safely after the update & draw stack has completed. <br>
636
+ * if the given child implements a onDeactivateEvent() method, that method will be called once the child is removed from this container.
652
637
  * @name removeChild
653
- * @memberof Container.prototype
638
+ * @memberof Container
654
639
  * @public
655
- * @function
656
640
  * @param {Renderable} child
657
641
  * @param {boolean} [keepalive=False] True to prevent calling child.destroy()
658
642
  */
@@ -670,8 +654,7 @@ class Container extends Renderable {
670
654
  * (removal is immediate and unconditional)<br>
671
655
  * Never use keepalive=true with objects from {@link pool}. Doing so will create a memory leak.
672
656
  * @name removeChildNow
673
- * @memberof Container.prototype
674
- * @function
657
+ * @memberof Container
675
658
  * @param {Renderable} child
676
659
  * @param {boolean} [keepalive=False] True to prevent calling child.destroy()
677
660
  */
@@ -723,8 +706,7 @@ class Container extends Renderable {
723
706
  /**
724
707
  * Automatically set the specified property of all childs to the given value
725
708
  * @name setChildsProperty
726
- * @memberof Container.prototype
727
- * @function
709
+ * @memberof Container
728
710
  * @param {string} prop property name
729
711
  * @param {object} value property value
730
712
  * @param {boolean} [recursive=false] recursively apply the value to child containers if true
@@ -741,8 +723,7 @@ class Container extends Renderable {
741
723
  /**
742
724
  * Move the child in the group one step forward (z depth).
743
725
  * @name moveUp
744
- * @memberof Container.prototype
745
- * @function
726
+ * @memberof Container
746
727
  * @param {Renderable} child
747
728
  */
748
729
  moveUp(child) {
@@ -758,8 +739,7 @@ class Container extends Renderable {
758
739
  /**
759
740
  * Move the child in the group one step backward (z depth).
760
741
  * @name moveDown
761
- * @memberof Container.prototype
762
- * @function
742
+ * @memberof Container
763
743
  * @param {Renderable} child
764
744
  */
765
745
  moveDown(child) {
@@ -775,8 +755,7 @@ class Container extends Renderable {
775
755
  /**
776
756
  * Move the specified child to the top(z depth).
777
757
  * @name moveToTop
778
- * @memberof Container.prototype
779
- * @function
758
+ * @memberof Container
780
759
  * @param {Renderable} child
781
760
  */
782
761
  moveToTop(child) {
@@ -795,8 +774,7 @@ class Container extends Renderable {
795
774
  /**
796
775
  * Move the specified child the bottom (z depth).
797
776
  * @name moveToBottom
798
- * @memberof Container.prototype
799
- * @function
777
+ * @memberof Container
800
778
  * @param {Renderable} child
801
779
  */
802
780
  moveToBottom(child) {
@@ -815,9 +793,8 @@ class Container extends Renderable {
815
793
  /**
816
794
  * Manually trigger the sort of all the childs in the container</p>
817
795
  * @name sort
818
- * @memberof Container.prototype
796
+ * @memberof Container
819
797
  * @public
820
- * @function
821
798
  * @param {boolean} [recursive=false] recursively sort all containers if true
822
799
  */
823
800
  sort(recursive) {
@@ -910,8 +887,7 @@ class Container extends Renderable {
910
887
  * container update function. <br>
911
888
  * automatically called by the game manager {@link game}
912
889
  * @name update
913
- * @memberof Container.prototype
914
- * @function
890
+ * @memberof Container
915
891
  * @protected
916
892
  * @param {number} dt time since the last update in milliseconds.
917
893
  * @returns {boolean} true if the Container is dirty
@@ -960,16 +936,14 @@ class Container extends Renderable {
960
936
  }
961
937
 
962
938
  /**
963
- * draw the container. <br>
964
- * automatically called by the game manager {@link game}
939
+ * draw this renderable (automatically called by melonJS)
965
940
  * @name draw
966
- * @memberof Container.prototype
967
- * @function
941
+ * @memberof Container
968
942
  * @protected
969
- * @param {CanvasRenderer|WebGLRenderer} renderer a renderer object
970
- * @param {Rect|Bounds} [rect] the area or viewport to (re)draw
943
+ * @param {CanvasRenderer|WebGLRenderer} renderer a renderer instance
944
+ * @param {Camera2d} [viewport] the viewport to (re)draw
971
945
  */
972
- draw(renderer, rect) {
946
+ draw(renderer, viewport) {
973
947
  var isFloating = false;
974
948
  var bounds = this.getBounds();
975
949
 
@@ -1011,7 +985,7 @@ class Container extends Renderable {
1011
985
  obj.preDraw(renderer);
1012
986
 
1013
987
  // draw the object
1014
- obj.draw(renderer, rect);
988
+ obj.draw(renderer, viewport);
1015
989
 
1016
990
  // postdraw (clean-up);
1017
991
  obj.postDraw(renderer);
@@ -33,7 +33,6 @@ export class Draggable extends Renderable {
33
33
  * transformed events.
34
34
  * @name initEvents
35
35
  * @memberof Draggable
36
- * @function
37
36
  * @private
38
37
  */
39
38
  initEvents() {
@@ -57,7 +56,6 @@ export class Draggable extends Renderable {
57
56
  * Gets called when the user starts dragging the entity
58
57
  * @name dragStart
59
58
  * @memberof Draggable
60
- * @function
61
59
  * @param {object} e the pointer event
62
60
  * @returns {boolean} false if the object is being dragged
63
61
  */
@@ -74,7 +72,6 @@ export class Draggable extends Renderable {
74
72
  * Gets called when the user drags this entity around
75
73
  * @name dragMove
76
74
  * @memberof Draggable
77
- * @function
78
75
  * @param {object} e the pointer event
79
76
  */
80
77
  dragMove(e) {
@@ -88,7 +85,6 @@ export class Draggable extends Renderable {
88
85
  * Gets called when the user stops dragging the entity
89
86
  * @name dragEnd
90
87
  * @memberof Draggable
91
- * @function
92
88
  * @returns {boolean} false if the object stopped being dragged
93
89
  */
94
90
  dragEnd() {
@@ -102,7 +98,6 @@ export class Draggable extends Renderable {
102
98
  * Destructor
103
99
  * @name destroy
104
100
  * @memberof Draggable
105
- * @function
106
101
  * @ignore
107
102
  */
108
103
  destroy() {
@@ -173,7 +168,6 @@ export class DropTarget extends Renderable {
173
168
  * Sets the collision method which is going to be used to check a valid drop
174
169
  * @name setCheckMethod
175
170
  * @memberof DropTarget
176
- * @function
177
171
  * @param {string} checkMethod the checkmethod (defaults to CHECKMETHOD_OVERLAP)
178
172
  */
179
173
  setCheckMethod(checkMethod) {
@@ -188,7 +182,6 @@ export class DropTarget extends Renderable {
188
182
  * Checks if a dropped entity is dropped on the current entity
189
183
  * @name checkOnMe
190
184
  * @memberof DropTarget
191
- * @function
192
185
  * @param {object} e the triggering event
193
186
  * @param {Draggable} draggable the draggable object that is dropped
194
187
  */
@@ -203,10 +196,9 @@ export class DropTarget extends Renderable {
203
196
  * Gets called when a draggable entity is dropped on the current entity
204
197
  * @name drop
205
198
  * @memberof DropTarget
206
- * @function
207
199
  * @param {Draggable} draggable the draggable object that is dropped
208
200
  */
209
- drop() {
201
+ drop(draggable) { // eslint-disable-line no-unused-vars
210
202
 
211
203
  }
212
204
 
@@ -214,7 +206,6 @@ export class DropTarget extends Renderable {
214
206
  * Destructor
215
207
  * @name destroy
216
208
  * @memberof DropTarget
217
- * @function
218
209
  * @ignore
219
210
  */
220
211
  destroy() {
@@ -75,7 +75,7 @@ class ImageLayer extends Sprite {
75
75
  * - a number, to change the value for both axis <br>
76
76
  * - a json expression like `json:{"x":0.5,"y":0.5}` if you wish to specify a different value for both x and y
77
77
  * @public
78
- * @type {Vector2d}
78
+ * @member {Vector2d}
79
79
  * @default <0.0,0.0>
80
80
  * @name ImageLayer#anchorPoint
81
81
  */
@@ -159,13 +159,12 @@ class ImageLayer extends Sprite {
159
159
  /**
160
160
  * resize the Image Layer to match the given size
161
161
  * @name resize
162
- * @memberof ImageLayer.prototype
163
- * @function
162
+ * @memberof ImageLayer
164
163
  * @param {number} w new width
165
164
  * @param {number} h new height
166
165
  */
167
166
  resize(w, h) {
168
- super.resize(
167
+ return super.resize(
169
168
  this.repeatX ? Infinity : w,
170
169
  this.repeatY ? Infinity : h
171
170
  );
@@ -174,7 +173,6 @@ class ImageLayer extends Sprite {
174
173
  /**
175
174
  * createPattern function
176
175
  * @ignore
177
- * @function
178
176
  */
179
177
  createPattern() {
180
178
  this._pattern = renderer.createPattern(this.image, this._repeat);
@@ -183,7 +181,6 @@ class ImageLayer extends Sprite {
183
181
  /**
184
182
  * updateLayer function
185
183
  * @ignore
186
- * @function
187
184
  */
188
185
  updateLayer(vpos) {
189
186
  var rx = this.ratio.x,
@@ -246,15 +243,14 @@ class ImageLayer extends Sprite {
246
243
  }
247
244
 
248
245
  /**
249
- * draw the ImageLayer. <br>
250
- * automatically called by the game manager {@link game}
246
+ * draw this ImageLayer (automatically called by melonJS)
251
247
  * @name draw
252
- * @memberof ImageLayer.prototype
253
- * @function
248
+ * @memberof ImageLayer
254
249
  * @protected
255
- * @param {CanvasRenderer|WebGLRenderer} renderer a renderer object
250
+ * @param {CanvasRenderer|WebGLRenderer} renderer a renderer instance
251
+ * @param {Camera2d} [viewport] the viewport to (re)draw
256
252
  */
257
- draw(renderer) {
253
+ draw(renderer, viewport) {
258
254
  var width = this.width,
259
255
  height = this.height,
260
256
  bw = viewport.bounds.width,
@@ -0,0 +1,118 @@
1
+ import pool from "./../system/pooling.js";
2
+ import Renderable from "./renderable.js";
3
+
4
+ /** @ignore */
5
+ function createGradient(light) {
6
+ var context = light.texture.context;
7
+ var x1 = light.texture.width / 2;
8
+ var y1 = light.texture.height / 2;
9
+ var gradient = context.createRadialGradient(x1, y1, 0, x1, y1, light.radius);
10
+
11
+ light.texture.clear();
12
+
13
+ gradient.addColorStop( 0, light.color.toRGBA(light.intensity));
14
+ gradient.addColorStop( 1, light.color.toRGBA(0.0));
15
+
16
+ context.beginPath();
17
+ context.fillStyle = gradient;
18
+ context.arc(x1, y1, light.radius, 0, Math.PI * 2, false);
19
+ context.fill();
20
+ }
21
+
22
+ /**
23
+ * @classdesc
24
+ * A 2D point light.
25
+ * Note: this is a very experimental and work in progress feature, that provides a simple spot light effect.
26
+ * The light effect is best rendered in WebGL, as they are few limitations when using the Canvas Renderer
27
+ * (multiple lights are not supported, alpha component of the ambient light is ignored)
28
+ * @see stage.lights
29
+ */
30
+ class Light2d extends Renderable {
31
+ /**
32
+ * @param {number} x - The horizontal position of the light.
33
+ * @param {number} y - The vertical position of the light.
34
+ * @param {number} radius - The radius of the light.
35
+ * @param {Color|string} [color="#FFF"] the color of the light
36
+ * @param {number} [intensity=0.7] - The intensity of the light.
37
+ */
38
+ constructor(x, y, radius, color = "#FFF", intensity = 0.7) {
39
+ // call the parent constructor
40
+ super(x, y, radius * 2, radius * 2);
41
+
42
+ /**
43
+ * the color of the light
44
+ * @type {Color}
45
+ * @default "#FFF"
46
+ */
47
+ this.color = pool.pull("Color").parseCSS(color);
48
+
49
+ /**
50
+ * The radius of the light
51
+ * @type {number}
52
+ */
53
+ this.radius = radius;
54
+
55
+ /**
56
+ * The intensity of the light
57
+ * @type {number}
58
+ * @default 0.7
59
+ */
60
+ this.intensity = intensity;
61
+
62
+ /**
63
+ * the default blend mode to be applied when rendering this light
64
+ * @type {string}
65
+ * @default "lighter"
66
+ * @see CanvasRenderer#setBlendMode
67
+ * @see WebGLRenderer#setBlendMode
68
+ */
69
+ this.blendMode = "lighter";
70
+
71
+ /** @ignore */
72
+ this.visibleArea = pool.pull("Ellipse", this.centerX, this.centerY, this.width, this.height);
73
+
74
+ /** @ignore */
75
+ this.texture = pool.pull("CanvasTexture", this.width, this.height, { offscreenCanvas: false });
76
+
77
+ this.anchorPoint.set(0, 0);
78
+
79
+ createGradient(this);
80
+ }
81
+
82
+ /**
83
+ * returns a geometry representing the visible area of this light
84
+ * @name getVisibleArea
85
+ * @memberof Light2d
86
+ * @returns {Ellipse} the light visible mask
87
+ */
88
+ getVisibleArea() {
89
+ return this.visibleArea.setShape(this.getBounds().centerX, this.getBounds().centerY, this.width, this.height);
90
+ }
91
+
92
+ /**
93
+ * draw this Light2d (automatically called by melonJS)
94
+ * @name draw
95
+ * @memberof Light2d
96
+ * @protected
97
+ * @param {CanvasRenderer|WebGLRenderer} renderer a renderer instance
98
+ * @param {Camera2d} [viewport] the viewport to (re)draw
99
+ */
100
+ draw(renderer, viewport) { // eslint-disable-line no-unused-vars
101
+ renderer.drawImage(this.texture.canvas, this.getBounds().x, this.getBounds().y);
102
+ }
103
+
104
+ /**
105
+ * Destroy function<br>
106
+ * @ignore
107
+ */
108
+ destroy() {
109
+ pool.push(this.color);
110
+ this.color = undefined;
111
+ pool.push(this.texture);
112
+ this.texture = undefined;
113
+ pool.push(this.visibleArea);
114
+ this.visibleArea = undefined;
115
+ super.destroy();
116
+ }
117
+ };
118
+ export default Light2d;