melonjs 13.0.0 → 13.2.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.
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * melonJS Game Engine - v13.0.0
2
+ * melonJS Game Engine - v13.2.0
3
3
  * http://www.melonjs.org
4
4
  * melonjs is licensed under the MIT License.
5
5
  * http://www.opensource.org/licenses/mit-license
@@ -309,10 +309,10 @@ var store$2 = sharedStore;
309
309
  (shared$3.exports = function (key, value) {
310
310
  return store$2[key] || (store$2[key] = value !== undefined ? value : {});
311
311
  })('versions', []).push({
312
- version: '3.23.5',
312
+ version: '3.24.1',
313
313
  mode: 'global',
314
314
  copyright: '© 2014-2022 Denis Pushkarev (zloirock.ru)',
315
- license: 'https://github.com/zloirock/core-js/blob/v3.23.5/LICENSE',
315
+ license: 'https://github.com/zloirock/core-js/blob/v3.24.1/LICENSE',
316
316
  source: 'https://github.com/zloirock/core-js'
317
317
  });
318
318
 
@@ -2350,6 +2350,29 @@ class Vector2d {
2350
2350
  return this;
2351
2351
  }
2352
2352
 
2353
+ /**
2354
+ * interpolate the position of this vector towards the given one by the given maximum step.
2355
+ * @name moveTowards
2356
+ * @memberof Vector2d
2357
+ * @param {Vector2d} target
2358
+ * @param {number} step the maximum step per iteration (Negative values will push the vector away from the target)
2359
+ * @returns {Vector2d} Reference to this object for method chaining
2360
+ */
2361
+ moveTowards(target, step) {
2362
+ var angle = Math.atan2(target.y - this.y, target.x - this.x);
2363
+
2364
+ var distance = this.distance(target);
2365
+
2366
+ if (distance === 0 || (step >= 0 && distance <= step * step)) {
2367
+ return target;
2368
+ }
2369
+
2370
+ this.x += Math.cos(angle) * step;
2371
+ this.y += Math.sin(angle) * step;
2372
+
2373
+ return this;
2374
+ }
2375
+
2353
2376
  /**
2354
2377
  * return the distance between this vector and the passed one
2355
2378
  * @name distance
@@ -2418,9 +2441,17 @@ class Vector2d {
2418
2441
  }
2419
2442
 
2420
2443
  // convert a give color component to it hexadecimal value
2421
- var toHex = function (component) {
2444
+ function toHex(component) {
2422
2445
  return "0123456789ABCDEF".charAt((component - (component % 16)) >> 4) + "0123456789ABCDEF".charAt(component % 16);
2423
- };
2446
+ }
2447
+ function hue2rgb(p, q, t) {
2448
+ if (t < 0) t += 1;
2449
+ if (t > 1) t -= 1;
2450
+ if (t < 1/6) return p + (q - p) * 6 * t;
2451
+ if (t < 1/2) return q;
2452
+ if (t < 2/3) return p + (q - p) * (2/3 - t) * 6;
2453
+ return p;
2454
+ }
2424
2455
 
2425
2456
  const rgbaRx = /^rgba?\((\d+), ?(\d+), ?(\d+)(, ?([\d\.]+))?\)$/;
2426
2457
  const hex3Rx = /^#([\da-fA-F])([\da-fA-F])([\da-fA-F])$/;
@@ -2615,7 +2646,6 @@ class Color {
2615
2646
  /**
2616
2647
  * Color Red Component [0 .. 255]
2617
2648
  * @type {number}
2618
- * @memberof Color
2619
2649
  */
2620
2650
  get r() {
2621
2651
  return ~~(this.glArray[0] * 255);
@@ -2629,7 +2659,6 @@ class Color {
2629
2659
  /**
2630
2660
  * Color Green Component [0 .. 255]
2631
2661
  * @type {number}
2632
- * @memberof Color
2633
2662
  */
2634
2663
  get g() {
2635
2664
  return ~~(this.glArray[1] * 255);
@@ -2643,7 +2672,6 @@ class Color {
2643
2672
  /**
2644
2673
  * Color Blue Component [0 .. 255]
2645
2674
  * @type {number}
2646
- * @memberof Color
2647
2675
  */
2648
2676
  get b() {
2649
2677
  return ~~(this.glArray[2] * 255);
@@ -2655,7 +2683,6 @@ class Color {
2655
2683
  /**
2656
2684
  * Color Alpha Component [0.0 .. 1.0]
2657
2685
  * @type {number}
2658
- * @memberof Color
2659
2686
  */
2660
2687
  get alpha() {
2661
2688
  return this.glArray[3];
@@ -2668,8 +2695,6 @@ class Color {
2668
2695
 
2669
2696
  /**
2670
2697
  * Set this color to the specified value.
2671
- * @name setColor
2672
- * @memberof Color
2673
2698
  * @param {number} r red component [0 .. 255]
2674
2699
  * @param {number} g green component [0 .. 255]
2675
2700
  * @param {number} b blue component [0 .. 255]
@@ -2684,10 +2709,59 @@ class Color {
2684
2709
  return this;
2685
2710
  }
2686
2711
 
2712
+ /**
2713
+ * set this color to the specified HSV value
2714
+ * @param {number} h hue (a value from 0 to 1)
2715
+ * @param {number} s saturation (a value from 0 to 1)
2716
+ * @param {number} v value (a value from 0 to 1)
2717
+ * @returns {Color} Reference to this object for method chaining
2718
+ */
2719
+ setHSV(h, s, v) {
2720
+ var r, g, b;
2721
+
2722
+ var i = Math.floor(h * 6);
2723
+ var f = h * 6 - i;
2724
+ var p = v * (1 - s);
2725
+ var q = v * (1 - f * s);
2726
+ var t = v * (1 - (1 - f) * s);
2727
+
2728
+ switch (i % 6) {
2729
+ case 0: r = v, g = t, b = p; break;
2730
+ case 1: r = q, g = v, b = p; break;
2731
+ case 2: r = p, g = v, b = t; break;
2732
+ case 3: r = p, g = q, b = v; break;
2733
+ case 4: r = t, g = p, b = v; break;
2734
+ case 5: r = v, g = p, b = q; break;
2735
+ }
2736
+ return this.setColor(r * 255, g * 255, b * 255);
2737
+ }
2738
+
2739
+ /**
2740
+ * set this color to the specified HSL value
2741
+ * @param {number} h hue (a value from 0 to 1)
2742
+ * @param {number} s saturation (a value from 0 to 1)
2743
+ * @param {number} l lightness (a value from 0 to 1)
2744
+ * @returns {Color} Reference to this object for method chaining
2745
+ */
2746
+ setHSL(h, s, l) {
2747
+ var r, g, b;
2748
+
2749
+ if (s === 0) {
2750
+ r = g = b = l; // achromatic
2751
+ } else {
2752
+ var q = l < 0.5 ? l * (1 + s) : l + s - l * s;
2753
+ var p = 2 * l - q;
2754
+
2755
+ r = hue2rgb(p, q, h + 1/3);
2756
+ g = hue2rgb(p, q, h);
2757
+ b = hue2rgb(p, q, h - 1/3);
2758
+ }
2759
+
2760
+ return this.setColor(r * 255, g * 255, b * 255);
2761
+ }
2762
+
2687
2763
  /**
2688
2764
  * Create a new copy of this color object.
2689
- * @name clone
2690
- * @memberof Color
2691
2765
  * @returns {Color} Reference to the newly cloned object
2692
2766
  */
2693
2767
  clone() {
@@ -2696,8 +2770,6 @@ class Color {
2696
2770
 
2697
2771
  /**
2698
2772
  * Copy a color object or CSS color into this one.
2699
- * @name copy
2700
- * @memberof Color
2701
2773
  * @param {Color|string} color
2702
2774
  * @returns {Color} Reference to this object for method chaining
2703
2775
  */
@@ -2712,8 +2784,6 @@ class Color {
2712
2784
 
2713
2785
  /**
2714
2786
  * Blend this color with the given one using addition.
2715
- * @name add
2716
- * @memberof Color
2717
2787
  * @param {Color} color
2718
2788
  * @returns {Color} Reference to this object for method chaining
2719
2789
  */
@@ -2728,8 +2798,6 @@ class Color {
2728
2798
 
2729
2799
  /**
2730
2800
  * Darken this color value by 0..1
2731
- * @name darken
2732
- * @memberof Color
2733
2801
  * @param {number} scale
2734
2802
  * @returns {Color} Reference to this object for method chaining
2735
2803
  */
@@ -2744,8 +2812,6 @@ class Color {
2744
2812
 
2745
2813
  /**
2746
2814
  * Linearly interpolate between this color and the given one.
2747
- * @name lerp
2748
- * @memberof Color
2749
2815
  * @param {Color} color
2750
2816
  * @param {number} alpha with alpha = 0 being this color, and alpha = 1 being the given one.
2751
2817
  * @returns {Color} Reference to this object for method chaining
@@ -2761,8 +2827,6 @@ class Color {
2761
2827
 
2762
2828
  /**
2763
2829
  * Lighten this color value by 0..1
2764
- * @name lighten
2765
- * @memberof Color
2766
2830
  * @param {number} scale
2767
2831
  * @returns {Color} Reference to this object for method chaining
2768
2832
  */
@@ -2777,8 +2841,6 @@ class Color {
2777
2841
 
2778
2842
  /**
2779
2843
  * Generate random r,g,b values for this color object
2780
- * @name random
2781
- * @memberof Color
2782
2844
  * @param {number} [min=0] minimum value for the random range
2783
2845
  * @param {number} [max=255] maxmium value for the random range
2784
2846
  * @returns {Color} Reference to this object for method chaining
@@ -2802,8 +2864,6 @@ class Color {
2802
2864
  /**
2803
2865
  * Return true if the r,g,b,a values of this color are equal with the
2804
2866
  * given one.
2805
- * @name equals
2806
- * @memberof Color
2807
2867
  * @param {Color} color
2808
2868
  * @returns {boolean}
2809
2869
  */
@@ -2819,8 +2879,6 @@ class Color {
2819
2879
  /**
2820
2880
  * Parse a CSS color string and set this color to the corresponding
2821
2881
  * r,g,b values
2822
- * @name parseCSS
2823
- * @memberof Color
2824
2882
  * @param {string} cssColor
2825
2883
  * @returns {Color} Reference to this object for method chaining
2826
2884
  */
@@ -2836,8 +2894,6 @@ class Color {
2836
2894
 
2837
2895
  /**
2838
2896
  * Parse an RGB or RGBA CSS color string
2839
- * @name parseRGB
2840
- * @memberof Color
2841
2897
  * @param {string} rgbColor
2842
2898
  * @returns {Color} Reference to this object for method chaining
2843
2899
  */
@@ -2855,8 +2911,6 @@ class Color {
2855
2911
  /**
2856
2912
  * Parse a Hex color ("#RGB", "#RGBA" or "#RRGGBB", "#RRGGBBAA" format) and set this color to
2857
2913
  * the corresponding r,g,b,a values
2858
- * @name parseHex
2859
- * @memberof Color
2860
2914
  * @param {string} hexColor
2861
2915
  * @param {boolean} [argb = false] true if format is #ARGB, or #AARRGGBB (as opposed to #RGBA or #RGGBBAA)
2862
2916
  * @returns {Color} Reference to this object for method chaining
@@ -2914,12 +2968,10 @@ class Color {
2914
2968
 
2915
2969
  /**
2916
2970
  * Pack this color into a Uint32 ARGB representation
2917
- * @name toUint32
2918
- * @memberof Color
2919
2971
  * @param {number} [alpha=1.0] alpha value [0.0 .. 1.0]
2920
2972
  * @returns {number}
2921
2973
  */
2922
- toUint32(alpha = this.alpha) {
2974
+ toUint32(alpha = 1.0) {
2923
2975
  var ur = this.r & 0xff;
2924
2976
  var ug = this.g & 0xff;
2925
2977
  var ub = this.b & 0xff;
@@ -2930,8 +2982,6 @@ class Color {
2930
2982
 
2931
2983
  /**
2932
2984
  * return an array representation of this object
2933
- * @name toArray
2934
- * @memberof Color
2935
2985
  * @returns {Float32Array}
2936
2986
  */
2937
2987
  toArray() {
@@ -2940,9 +2990,7 @@ class Color {
2940
2990
 
2941
2991
 
2942
2992
  /**
2943
- * Get the color in "#RRGGBB" format
2944
- * @name toHex
2945
- * @memberof Color
2993
+ * return the color in "#RRGGBB" format
2946
2994
  * @returns {string}
2947
2995
  */
2948
2996
  toHex() {
@@ -2954,8 +3002,6 @@ class Color {
2954
3002
 
2955
3003
  /**
2956
3004
  * Get the color in "#RRGGBBAA" format
2957
- * @name toHex8
2958
- * @memberof Color
2959
3005
  * @returns {string}
2960
3006
  */
2961
3007
  toHex8(alpha = this.alpha) {
@@ -2967,8 +3013,6 @@ class Color {
2967
3013
 
2968
3014
  /**
2969
3015
  * Get the color in "rgb(R,G,B)" format
2970
- * @name toRGB
2971
- * @memberof Color
2972
3016
  * @returns {string}
2973
3017
  */
2974
3018
  toRGB() {
@@ -2984,8 +3028,6 @@ class Color {
2984
3028
 
2985
3029
  /**
2986
3030
  * Get the color in "rgba(R,G,B,A)" format
2987
- * @name toRGBA
2988
- * @memberof Color
2989
3031
  * @param {number} [alpha=1.0] alpha value [0.0 .. 1.0]
2990
3032
  * @returns {string}
2991
3033
  */
@@ -6482,56 +6524,38 @@ class GLShader {
6482
6524
 
6483
6525
  /**
6484
6526
  * the active gl rendering context
6485
- * @public
6486
6527
  * @type {WebGLRenderingContext}
6487
- * @name gl
6488
- * @memberof GLShader
6489
6528
  */
6490
6529
  this.gl = gl;
6491
6530
 
6492
6531
  /**
6493
6532
  * the vertex shader source code
6494
- * @public
6495
6533
  * @type {string}
6496
- * @name vertex
6497
- * @memberof GLShader
6498
6534
  */
6499
6535
  this.vertex = setPrecision(minify(vertex), precision || getMaxShaderPrecision(this.gl));
6500
6536
 
6501
6537
  /**
6502
6538
  * the fragment shader source code
6503
- * @public
6504
6539
  * @type {string}
6505
- * @name vertex
6506
- * @memberof GLShader
6507
6540
  */
6508
6541
  this.fragment = setPrecision(minify(fragment), precision || getMaxShaderPrecision(this.gl));
6509
6542
 
6510
6543
  /**
6511
6544
  * the location attributes of the shader
6512
- * @public
6513
6545
  * @type {GLint[]}
6514
- * @name attributes
6515
- * @memberof GLShader
6516
6546
  */
6517
6547
  this.attributes = extractAttributes(this.gl, this);
6518
6548
 
6519
6549
 
6520
6550
  /**
6521
6551
  * a reference to the shader program (once compiled)
6522
- * @public
6523
6552
  * @type {WebGLProgram}
6524
- * @name program
6525
- * @memberof GLShader
6526
6553
  */
6527
6554
  this.program = compileProgram(this.gl, this.vertex, this.fragment, this.attributes);
6528
6555
 
6529
6556
  /**
6530
6557
  * the uniforms of the shader
6531
- * @public
6532
6558
  * @type {object}
6533
- * @name uniforms
6534
- * @memberof GLShader
6535
6559
  */
6536
6560
  this.uniforms = extractUniforms(this.gl, this);
6537
6561
 
@@ -6541,8 +6565,6 @@ class GLShader {
6541
6565
 
6542
6566
  /**
6543
6567
  * Installs this shader program as part of current rendering state
6544
- * @name bind
6545
- * @memberof GLShader
6546
6568
  */
6547
6569
  bind() {
6548
6570
  this.gl.useProgram(this.program);
@@ -6550,8 +6572,6 @@ class GLShader {
6550
6572
 
6551
6573
  /**
6552
6574
  * returns the location of an attribute variable in this shader program
6553
- * @name getAttribLocation
6554
- * @memberof GLShader
6555
6575
  * @param {string} name the name of the attribute variable whose location to get.
6556
6576
  * @returns {GLint} number indicating the location of the variable name if found. Returns -1 otherwise
6557
6577
  */
@@ -6566,8 +6586,6 @@ class GLShader {
6566
6586
 
6567
6587
  /**
6568
6588
  * Set the uniform to the given value
6569
- * @name setUniform
6570
- * @memberof GLShader
6571
6589
  * @param {string} name the uniform name
6572
6590
  * @param {object|Float32Array} value the value to assign to that uniform
6573
6591
  * @example
@@ -6588,8 +6606,6 @@ class GLShader {
6588
6606
 
6589
6607
  /**
6590
6608
  * activate the given vertex attribute for this shader
6591
- * @name setVertexAttributes
6592
- * @memberof GLShader
6593
6609
  * @param {WebGLRenderingContext} gl the current WebGL rendering context
6594
6610
  * @param {object[]} attributes an array of vertex attributes
6595
6611
  * @param {number} vertexByteSize the size of a single vertex in bytes
@@ -6611,8 +6627,6 @@ class GLShader {
6611
6627
 
6612
6628
  /**
6613
6629
  * destroy this shader objects resources (program, attributes, uniforms)
6614
- * @name destroy
6615
- * @memberof GLShader
6616
6630
  */
6617
6631
  destroy() {
6618
6632
  this.uniforms = null;
@@ -6814,44 +6828,37 @@ class WebGLCompositor {
6814
6828
 
6815
6829
  /**
6816
6830
  * a reference to the active WebGL shader
6817
- * @name activeShader
6818
- * @memberof WebGLCompositor
6819
6831
  * @type {GLShader}
6820
6832
  */
6821
6833
  this.activeShader = null;
6822
6834
 
6823
6835
  /**
6824
6836
  * primitive type to render (gl.POINTS, gl.LINE_STRIP, gl.LINE_LOOP, gl.LINES, gl.TRIANGLE_STRIP, gl.TRIANGLE_FAN, gl.TRIANGLES)
6825
- * @name mode
6826
- * @see WebGLCompositor
6827
- * @memberof WebGLCompositor
6837
+ * @type {number}
6828
6838
  * @default gl.TRIANGLES
6829
6839
  */
6830
6840
  this.mode = gl.TRIANGLES;
6831
6841
 
6832
6842
  /**
6833
6843
  * an array of vertex attribute properties
6834
- * @name attributes
6835
6844
  * @see WebGLCompositor.addAttribute
6836
- * @memberof WebGLCompositor
6845
+ * @type {Array}
6837
6846
  */
6838
6847
  this.attributes = [];
6839
6848
 
6840
6849
  /**
6841
6850
  * the size of a single vertex in bytes
6842
6851
  * (will automatically be calculated as attributes definitions are added)
6843
- * @name vertexByteSize
6844
6852
  * @see WebGLCompositor.addAttribute
6845
- * @memberof WebGLCompositor
6853
+ * @type {number}
6846
6854
  */
6847
6855
  this.vertexByteSize = 0;
6848
6856
 
6849
6857
  /**
6850
6858
  * the size of a single vertex in floats
6851
6859
  * (will automatically be calculated as attributes definitions are added)
6852
- * @name vertexSize
6853
6860
  * @see WebGLCompositor.addAttribute
6854
- * @memberof WebGLCompositor
6861
+ * @type {number}
6855
6862
  */
6856
6863
  this.vertexSize = 0;
6857
6864
 
@@ -6890,8 +6897,8 @@ class WebGLCompositor {
6890
6897
  // initial viewport size
6891
6898
  this.setViewport(
6892
6899
  0, 0,
6893
- this.renderer.getScreenCanvas().width,
6894
- this.renderer.getScreenCanvas().height
6900
+ this.renderer.getCanvas().width,
6901
+ this.renderer.getCanvas().height
6895
6902
  );
6896
6903
 
6897
6904
  // Initialize clear color
@@ -6912,8 +6919,6 @@ class WebGLCompositor {
6912
6919
 
6913
6920
  /**
6914
6921
  * add vertex attribute property definition to the compositor
6915
- * @name addAttribute
6916
- * @memberof WebGLCompositor
6917
6922
  * @param {string} name name of the attribute in the vertex shader
6918
6923
  * @param {number} size number of components per vertex attribute. Must be 1, 2, 3, or 4.
6919
6924
  * @param {GLenum} type data type of each component in the array
@@ -6959,8 +6964,6 @@ class WebGLCompositor {
6959
6964
 
6960
6965
  /**
6961
6966
  * Sets the viewport
6962
- * @name setViewport
6963
- * @memberof WebGLCompositor
6964
6967
  * @param {number} x x position of viewport
6965
6968
  * @param {number} y y position of viewport
6966
6969
  * @param {number} w width of viewport
@@ -6972,8 +6975,6 @@ class WebGLCompositor {
6972
6975
 
6973
6976
  /**
6974
6977
  * Create a WebGL texture from an image
6975
- * @name createTexture2D
6976
- * @memberof WebGLCompositor
6977
6978
  * @param {number} unit Destination texture unit
6978
6979
  * @param {Image|HTMLCanvasElement|ImageData|Uint8Array[]|Float32Array[]} image Source image
6979
6980
  * @param {number} filter gl.LINEAR or gl.NEAREST
@@ -7016,8 +7017,6 @@ class WebGLCompositor {
7016
7017
 
7017
7018
  /**
7018
7019
  * delete the given WebGL texture
7019
- * @name bindTexture2D
7020
- * @memberof WebGLCompositor
7021
7020
  * @param {WebGLTexture} [texture] a WebGL texture to delete
7022
7021
  * @param {number} [unit] Texture unit to delete
7023
7022
  */
@@ -7028,8 +7027,6 @@ class WebGLCompositor {
7028
7027
 
7029
7028
  /**
7030
7029
  * returns the WebGL texture associated to the given texture unit
7031
- * @name bindTexture2D
7032
- * @memberof WebGLCompositor
7033
7030
  * @param {number} unit Texture unit to which a texture is bound
7034
7031
  * @returns {WebGLTexture} texture a WebGL texture
7035
7032
  */
@@ -7039,8 +7036,6 @@ class WebGLCompositor {
7039
7036
 
7040
7037
  /**
7041
7038
  * assign the given WebGL texture to the current batch
7042
- * @name bindTexture2D
7043
- * @memberof WebGLCompositor
7044
7039
  * @param {WebGLTexture} texture a WebGL texture
7045
7040
  * @param {number} unit Texture unit to which the given texture is bound
7046
7041
  */
@@ -7066,8 +7061,6 @@ class WebGLCompositor {
7066
7061
 
7067
7062
  /**
7068
7063
  * unbind the given WebGL texture, forcing it to be reuploaded
7069
- * @name unbindTexture2D
7070
- * @memberof WebGLCompositor
7071
7064
  * @param {WebGLTexture} [texture] a WebGL texture
7072
7065
  * @param {number} [unit] a WebGL texture
7073
7066
  * @returns {number} unit the unit number that was associated with the given texture
@@ -7112,8 +7105,6 @@ class WebGLCompositor {
7112
7105
 
7113
7106
  /**
7114
7107
  * set/change the current projection matrix
7115
- * @name setProjection
7116
- * @memberof WebGLCompositor
7117
7108
  * @param {Matrix3d} matrix
7118
7109
  */
7119
7110
  setProjection(matrix) {
@@ -7122,9 +7113,7 @@ class WebGLCompositor {
7122
7113
 
7123
7114
  /**
7124
7115
  * Select the shader to use for compositing
7125
- * @name useShader
7126
7116
  * @see GLShader
7127
- * @memberof WebGLCompositor
7128
7117
  * @param {GLShader} shader a reference to a GLShader instance
7129
7118
  */
7130
7119
  useShader(shader) {
@@ -7139,8 +7128,6 @@ class WebGLCompositor {
7139
7128
 
7140
7129
  /**
7141
7130
  * Add a textured quad
7142
- * @name addQuad
7143
- * @memberof WebGLCompositor
7144
7131
  * @param {TextureAtlas} texture Source texture atlas
7145
7132
  * @param {number} x Destination x-coordinate
7146
7133
  * @param {number} y Destination y-coordinate
@@ -7196,7 +7183,6 @@ class WebGLCompositor {
7196
7183
  /**
7197
7184
  * Flush batched texture operations to the GPU
7198
7185
  * @param {number} [mode=gl.TRIANGLES] the GL drawing mode
7199
- * @memberof WebGLCompositor
7200
7186
  */
7201
7187
  flush(mode = this.mode) {
7202
7188
  var vertex = this.vertexBuffer;
@@ -7222,8 +7208,6 @@ class WebGLCompositor {
7222
7208
 
7223
7209
  /**
7224
7210
  * Draw an array of vertices
7225
- * @name drawVertices
7226
- * @memberof WebGLCompositor
7227
7211
  * @param {GLenum} mode primitive type to render (gl.POINTS, gl.LINE_STRIP, gl.LINE_LOOP, gl.LINES, gl.TRIANGLE_STRIP, gl.TRIANGLE_FAN, gl.TRIANGLES)
7228
7212
  * @param {Vector2d[]} verts vertices
7229
7213
  * @param {number} [vertexCount=verts.length] amount of points defined in the points array
@@ -7250,25 +7234,26 @@ class WebGLCompositor {
7250
7234
  }
7251
7235
 
7252
7236
  /**
7253
- * Specify the color values used when clearing color buffers. The values are clamped between 0 and 1.
7254
- * @name clearColor
7255
- * @memberof WebGLCompositor
7256
- * @param {number} [r=0] - the red color value used when the color buffers are cleared
7257
- * @param {number} [g=0] - the green color value used when the color buffers are cleared
7258
- * @param {number} [b=0] - the blue color value used when the color buffers are cleared
7259
- * @param {number} [a=0] - the alpha color value used when the color buffers are cleared
7237
+ * Clear the frame buffer
7238
+ * @param {number} [alpha = 0.0] - the alpha value used when clearing the framebuffer
7260
7239
  */
7261
- clearColor(r, g, b, a) {
7262
- this.gl.clearColor(r, g, b, a);
7240
+ clear(alpha = 0) {
7241
+ var gl = this.gl;
7242
+ gl.clearColor(0, 0, 0, alpha);
7243
+ gl.clear(gl.COLOR_BUFFER_BIT | gl.STENCIL_BUFFER_BIT);
7263
7244
  }
7264
7245
 
7265
7246
  /**
7266
- * Clear the frame buffer
7267
- * @name clear
7268
- * @memberof WebGLCompositor
7247
+ * Specify the color values used when clearing color buffers. The values are clamped between 0 and 1.
7248
+ * @param {number} [r = 0] - the red color value used when the color buffers are cleared
7249
+ * @param {number} [g = 0] - the green color value used when the color buffers are cleared
7250
+ * @param {number} [b = 0] - the blue color value used when the color buffers are cleared
7251
+ * @param {number} [a = 0] - the alpha color value used when the color buffers are cleared
7269
7252
  */
7270
- clear() {
7271
- this.gl.clear(this.gl.COLOR_BUFFER_BIT);
7253
+ clearColor(r = 0, g = 0, b = 0, a = 0) {
7254
+ var gl = this.gl;
7255
+ gl.clearColor(r, g, b, a);
7256
+ gl.clear(gl.COLOR_BUFFER_BIT);
7272
7257
  }
7273
7258
  }
7274
7259
 
@@ -9577,17 +9562,18 @@ class Bounds {
9577
9562
  * add the given point to the bounds definition.
9578
9563
  * @name addPoint
9579
9564
  * @memberof Bounds
9580
- * @param {Vector2d} v
9581
- * @param {Matrix2d} [m] an optional transform to apply to the given point
9565
+ * @param {Vector2d|Point} point the point to be added to the bounds
9566
+ * @param {Matrix2d} [m] an optional transform to apply to the given point (only if the given point is a vector)
9582
9567
  */
9583
- addPoint(v, m) {
9584
- if (typeof m !== "undefined") {
9585
- v = m.apply(v);
9568
+ addPoint(point, m) {
9569
+ if ((typeof m !== "undefined") && (typeof point.rotate === "function")) {
9570
+ // only Vectors object have a rotate function
9571
+ point = m.apply(point);
9586
9572
  }
9587
- this.min.x = Math.min(this.min.x, v.x);
9588
- this.max.x = Math.max(this.max.x, v.x);
9589
- this.min.y = Math.min(this.min.y, v.y);
9590
- this.max.y = Math.max(this.max.y, v.y);
9573
+ this.min.x = Math.min(this.min.x, point.x);
9574
+ this.max.x = Math.max(this.max.x, point.x);
9575
+ this.min.y = Math.min(this.min.y, point.y);
9576
+ this.max.y = Math.max(this.max.y, point.y);
9591
9577
  }
9592
9578
 
9593
9579
  /**
@@ -10076,6 +10062,86 @@ class Path2D {
10076
10062
  }
10077
10063
  }
10078
10064
 
10065
+ /**
10066
+ * @classdesc
10067
+ * represents a point in a 2d space
10068
+ */
10069
+ class Point {
10070
+ constructor(x = 0, y = 0) {
10071
+ /**
10072
+ * the position of the point on the horizontal axis
10073
+ * @public
10074
+ * @type {Number}
10075
+ * @default 0
10076
+ */
10077
+ this.x = x;
10078
+
10079
+ /**
10080
+ * the position of the point on the vertical axis
10081
+ * @public
10082
+ * @type {Number}
10083
+ * @default 0
10084
+ */
10085
+ this.y = y;
10086
+ }
10087
+
10088
+ /** @ignore */
10089
+ onResetEvent(x = 0, y = 0) {
10090
+ this.set(x, y);
10091
+ }
10092
+
10093
+ /**
10094
+ * set the Point x and y properties to the given values
10095
+ * @param {number} x
10096
+ * @param {number} y
10097
+ * @returns {Point} Reference to this object for method chaining
10098
+ */
10099
+ set(x = 0, y = 0) {
10100
+ this.x = x;
10101
+ this.y = y;
10102
+ return this;
10103
+ }
10104
+
10105
+ /**
10106
+ * return true if the two points are the same
10107
+ * @name equals
10108
+ * @memberof Point
10109
+ * @method
10110
+ * @param {Point} point
10111
+ * @returns {boolean}
10112
+ */
10113
+ /**
10114
+ * return true if this point is equal to the given values
10115
+ * @name equals
10116
+ * @memberof Point
10117
+ * @param {number} x
10118
+ * @param {number} y
10119
+ * @returns {boolean}
10120
+ */
10121
+ equals() {
10122
+ var _x, _y;
10123
+ if (arguments.length === 2) {
10124
+ // x, y
10125
+ _x = arguments[0];
10126
+ _y = arguments[1];
10127
+ } else {
10128
+ // point
10129
+ _x = arguments[0].x;
10130
+ _y = arguments[0].y;
10131
+ }
10132
+ return ((this.x === _x) && (this.y === _y));
10133
+ }
10134
+
10135
+ /**
10136
+ * clone this Point
10137
+ * @name clone
10138
+ * @returns {Point} new Point
10139
+ */
10140
+ clone() {
10141
+ return new Point(this.x, this.y);
10142
+ }
10143
+ }
10144
+
10079
10145
  /**
10080
10146
  * @classdesc
10081
10147
  * a base renderer object
@@ -10086,10 +10152,10 @@ class Renderer {
10086
10152
  * @param {number} options.width The width of the canvas without scaling
10087
10153
  * @param {number} options.height The height of the canvas without scaling
10088
10154
  * @param {HTMLCanvasElement} [options.canvas] The html canvas to draw to on screen
10089
- * @param {boolean} [options.doubleBuffering=false] Whether to enable double buffering (not applicable when using the WebGL Renderer)
10090
10155
  * @param {boolean} [options.antiAlias=false] Whether to enable anti-aliasing, use false (default) for a pixelated effect.
10091
10156
  * @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.
10092
- * @param {boolean} [options.transparent=false] Whether to enable transparency on the canvas (performance hit when enabled)
10157
+ * @param {boolean} [options.transparent=false] Whether to enable transparency on the canvas
10158
+ * @param {boolean} [options.premultipliedAlpha=true] in WebGL, whether the renderer will assume that colors have premultiplied alpha when canvas transparency is enabled
10093
10159
  * @param {boolean} [options.blendMode="normal"] the default blend mode to use ("normal", "multiply")
10094
10160
  * @param {boolean} [options.subPixel=false] Whether to enable subpixel rendering (performance hit when enabled)
10095
10161
  * @param {boolean} [options.verbose=false] Enable the verbose mode that provides additional details as to what the renderer is doing
@@ -10100,26 +10166,20 @@ class Renderer {
10100
10166
  /**
10101
10167
  * The given constructor options
10102
10168
  * @public
10103
- * @name settings
10104
- * @memberof Renderer#
10105
10169
  * @type {object}
10106
10170
  */
10107
10171
  this.settings = options;
10108
10172
 
10109
10173
  /**
10110
10174
  * true if the current rendering context is valid
10111
- * @name isContextValid
10112
- * @memberof Renderer#
10113
10175
  * @default true
10114
- * type {boolean}
10176
+ * @type {boolean}
10115
10177
  */
10116
10178
  this.isContextValid = true;
10117
10179
 
10118
10180
  /**
10119
10181
  * The Path2D instance used by the renderer to draw primitives
10120
- * @name path2D
10121
10182
  * @type {Path2D}
10122
- * @memberof Renderer#
10123
10183
  */
10124
10184
  this.path2D = new Path2D();
10125
10185
 
@@ -10148,13 +10208,9 @@ class Renderer {
10148
10208
  } else if (typeof this.settings.canvas !== "undefined") {
10149
10209
  this.canvas = this.settings.canvas;
10150
10210
  } else {
10151
- this.canvas = createCanvas(this.settings.zoomX, this.settings.zoomY);
10211
+ this.canvas = createCanvas(this.settings.width, this.settings.height);
10152
10212
  }
10153
10213
 
10154
- // canvas object and context
10155
- this.backBufferCanvas = this.canvas;
10156
- this.context = null;
10157
-
10158
10214
  // global color
10159
10215
  this.currentColor = new Color(0, 0, 0, 1.0);
10160
10216
 
@@ -10175,15 +10231,16 @@ class Renderer {
10175
10231
 
10176
10232
  /**
10177
10233
  * prepare the framebuffer for drawing a new frame
10178
- * @name clear
10179
- * @memberof Renderer
10180
10234
  */
10181
10235
  clear() {}
10182
10236
 
10237
+ /**
10238
+ * render the main framebuffer on screen
10239
+ */
10240
+ flush() {}
10241
+
10183
10242
  /**
10184
10243
  * Reset context state
10185
- * @name reset
10186
- * @memberof Renderer
10187
10244
  */
10188
10245
  reset() {
10189
10246
  this.resetTransform();
@@ -10193,46 +10250,30 @@ class Renderer {
10193
10250
  this.cache.clear();
10194
10251
  this.currentScissor[0] = 0;
10195
10252
  this.currentScissor[1] = 0;
10196
- this.currentScissor[2] = this.backBufferCanvas.width;
10197
- this.currentScissor[3] = this.backBufferCanvas.height;
10253
+ this.currentScissor[2] = this.getCanvas().width;
10254
+ this.currentScissor[3] = this.getCanvas().height;
10198
10255
  this.clearMask();
10199
10256
  }
10200
10257
 
10201
10258
  /**
10202
- * return a reference to the system canvas
10203
- * @name getCanvas
10204
- * @memberof Renderer
10259
+ * return a reference to the canvas which this renderer draws to
10205
10260
  * @returns {HTMLCanvasElement}
10206
10261
  */
10207
10262
  getCanvas() {
10208
- return this.backBufferCanvas;
10209
- }
10210
-
10211
- /**
10212
- * return a reference to the screen canvas
10213
- * @name getScreenCanvas
10214
- * @memberof Renderer
10215
- * @returns {HTMLCanvasElement}
10216
- */
10217
- getScreenCanvas() {
10218
10263
  return this.canvas;
10219
10264
  }
10220
10265
 
10266
+
10221
10267
  /**
10222
- * return a reference to the screen canvas corresponding 2d Context<br>
10223
- * (will return buffered context if double buffering is enabled, or a reference to the Screen Context)
10224
- * @name getScreenContext
10225
- * @memberof Renderer
10226
- * @returns {CanvasRenderingContext2D}
10268
+ * return a reference to this renderer canvas corresponding Context
10269
+ * @returns {CanvasRenderingContext2D|WebGLRenderingContext}
10227
10270
  */
10228
- getScreenContext() {
10271
+ getContext() {
10229
10272
  return this.context;
10230
10273
  }
10231
10274
 
10232
10275
  /**
10233
10276
  * returns the current blend mode for this renderer
10234
- * @name getBlendMode
10235
- * @memberof Renderer
10236
10277
  * @returns {string} blend mode
10237
10278
  */
10238
10279
  getBlendMode() {
@@ -10242,8 +10283,6 @@ class Renderer {
10242
10283
  /**
10243
10284
  * Returns the 2D Context object of the given Canvas<br>
10244
10285
  * Also configures anti-aliasing and blend modes based on constructor options.
10245
- * @name getContext2d
10246
- * @memberof Renderer
10247
10286
  * @param {HTMLCanvasElement} canvas
10248
10287
  * @param {boolean} [transparent=true] use false to disable transparency
10249
10288
  * @returns {CanvasRenderingContext2D}
@@ -10279,28 +10318,22 @@ class Renderer {
10279
10318
 
10280
10319
  /**
10281
10320
  * return the width of the system Canvas
10282
- * @name getWidth
10283
- * @memberof Renderer
10284
10321
  * @returns {number}
10285
10322
  */
10286
10323
  getWidth() {
10287
- return this.backBufferCanvas.width;
10324
+ return this.getCanvas().width;
10288
10325
  }
10289
10326
 
10290
10327
  /**
10291
10328
  * return the height of the system Canvas
10292
- * @name getHeight
10293
- * @memberof Renderer
10294
10329
  * @returns {number} height of the system Canvas
10295
10330
  */
10296
10331
  getHeight() {
10297
- return this.backBufferCanvas.height;
10332
+ return this.getCanvas().height;
10298
10333
  }
10299
10334
 
10300
10335
  /**
10301
10336
  * get the current fill & stroke style color.
10302
- * @name getColor
10303
- * @memberof Renderer
10304
10337
  * @returns {Color} current global color
10305
10338
  */
10306
10339
  getColor() {
@@ -10309,8 +10342,6 @@ class Renderer {
10309
10342
 
10310
10343
  /**
10311
10344
  * return the current global alpha
10312
- * @name globalAlpha
10313
- * @memberof Renderer
10314
10345
  * @returns {number}
10315
10346
  */
10316
10347
  globalAlpha() {
@@ -10319,8 +10350,6 @@ class Renderer {
10319
10350
 
10320
10351
  /**
10321
10352
  * check if the given rect or bounds overlaps with the renderer screen coordinates
10322
- * @name overlaps
10323
- * @memberof Renderer
10324
10353
  * @param {Rect|Bounds} bounds
10325
10354
  * @returns {boolean} true if overlaps
10326
10355
  */
@@ -10334,15 +10363,14 @@ class Renderer {
10334
10363
 
10335
10364
  /**
10336
10365
  * resizes the system canvas
10337
- * @name resize
10338
- * @memberof Renderer
10339
10366
  * @param {number} width new width of the canvas
10340
10367
  * @param {number} height new height of the canvas
10341
10368
  */
10342
10369
  resize(width, height) {
10343
- if (width !== this.backBufferCanvas.width || height !== this.backBufferCanvas.height) {
10344
- this.canvas.width = this.backBufferCanvas.width = width;
10345
- this.canvas.height = this.backBufferCanvas.height = height;
10370
+ var canvas = this.getCanvas();
10371
+ if (width !== canvas.width || height !== canvas.height) {
10372
+ canvas.width = width;
10373
+ canvas.height = height;
10346
10374
  this.currentScissor[0] = 0;
10347
10375
  this.currentScissor[1] = 0;
10348
10376
  this.currentScissor[2] = width;
@@ -10354,8 +10382,6 @@ class Renderer {
10354
10382
 
10355
10383
  /**
10356
10384
  * enable/disable image smoothing (scaling interpolation) for the given context
10357
- * @name setAntiAlias
10358
- * @memberof Renderer
10359
10385
  * @param {CanvasRenderingContext2D} context
10360
10386
  * @param {boolean} [enable=false]
10361
10387
  */
@@ -10383,8 +10409,6 @@ class Renderer {
10383
10409
 
10384
10410
  /**
10385
10411
  * set/change the current projection matrix (WebGL only)
10386
- * @name setProjection
10387
- * @memberof Renderer
10388
10412
  * @param {Matrix3d} matrix
10389
10413
  */
10390
10414
  setProjection(matrix) {
@@ -10393,8 +10417,6 @@ class Renderer {
10393
10417
 
10394
10418
  /**
10395
10419
  * stroke the given shape
10396
- * @name stroke
10397
- * @memberof Renderer
10398
10420
  * @param {Rect|RoundRect|Polygon|Line|Ellipse} shape a shape object to stroke
10399
10421
  * @param {boolean} [fill=false] fill the shape with the current color if true
10400
10422
  */
@@ -10421,6 +10443,10 @@ class Renderer {
10421
10443
  );
10422
10444
  return;
10423
10445
  }
10446
+ if (shape instanceof Point) {
10447
+ this.strokePoint(shape.x, shape.y);
10448
+ return;
10449
+ }
10424
10450
  throw new Error("Invalid geometry for fill/stroke");
10425
10451
  }
10426
10452
 
@@ -10436,8 +10462,6 @@ class Renderer {
10436
10462
 
10437
10463
  /**
10438
10464
  * tint the given image or canvas using the given color
10439
- * @name tint
10440
- * @memberof Renderer
10441
10465
  * @param {HTMLImageElement|HTMLCanvasElement|OffscreenCanvas} src the source image to be tinted
10442
10466
  * @param {Color|string} color the color that will be used to tint the image
10443
10467
  * @param {string} [mode="multiply"] the composition mode used to tint the image
@@ -10466,8 +10490,6 @@ class Renderer {
10466
10490
  * A mask limits rendering elements to the shape and position of the given mask object.
10467
10491
  * So, if the renderable is larger than the mask, only the intersecting part of the renderable will be visible.
10468
10492
  * Mask are not preserved through renderer context save and restore.
10469
- * @name setMask
10470
- * @memberof Renderer
10471
10493
  * @param {Rect|RoundRect|Polygon|Line|Ellipse} [mask] the shape defining the mask to be applied
10472
10494
  * @param {boolean} [invert=false] either the given shape should define what is visible (default) or the opposite
10473
10495
  */
@@ -10476,16 +10498,12 @@ class Renderer {
10476
10498
 
10477
10499
  /**
10478
10500
  * disable (remove) the rendering mask set through setMask.
10479
- * @name clearMask
10480
10501
  * @see Renderer#setMask
10481
- * @memberof Renderer
10482
10502
  */
10483
10503
  clearMask() {}
10484
10504
 
10485
10505
  /**
10486
10506
  * set a coloring tint for sprite based renderables
10487
- * @name setTint
10488
- * @memberof Renderer
10489
10507
  * @param {Color} tint the tint color
10490
10508
  * @param {number} [alpha] an alpha value to be applied to the tint
10491
10509
  */
@@ -10497,9 +10515,7 @@ class Renderer {
10497
10515
 
10498
10516
  /**
10499
10517
  * clear the rendering tint set through setTint.
10500
- * @name clearTint
10501
10518
  * @see Renderer#setTint
10502
- * @memberof Renderer
10503
10519
  */
10504
10520
  clearTint() {
10505
10521
  // reset to default
@@ -14660,8 +14676,32 @@ class ObservableVector2d extends Vector2d {
14660
14676
  * @returns {ObservableVector2d} Reference to this object for method chaining
14661
14677
  */
14662
14678
  lerp(v, alpha) {
14663
- this._x += ( v.x - this._x ) * alpha;
14664
- this._y += ( v.y - this._y ) * alpha;
14679
+ return this._set(
14680
+ this._x + ( v.x - this._x ) * alpha,
14681
+ this._y + ( v.y - this._y ) * alpha
14682
+ );
14683
+ }
14684
+
14685
+ /**
14686
+ * interpolate the position of this vector towards the given one while nsure that the distance never exceeds the given step.
14687
+ * @name moveTowards
14688
+ * @memberof ObservableVector2d
14689
+ * @param {Vector2d|ObservableVector2d} target
14690
+ * @param {number} step the maximum step per iteration (Negative values will push the vector away from the target)
14691
+ * @returns {ObservableVector2d} Reference to this object for method chaining
14692
+ */
14693
+ moveTowards(target, step) {
14694
+ var angle = Math.atan2(target.y - this._y, target.x - this._x);
14695
+
14696
+ var distance = this.distance(target);
14697
+
14698
+ if (distance === 0 || (step >= 0 && distance <= step * step)) {
14699
+ return target;
14700
+ }
14701
+
14702
+ this._x += Math.cos(angle) * step;
14703
+ this._y += Math.sin(angle) * step;
14704
+
14665
14705
  return this;
14666
14706
  }
14667
14707
 
@@ -15166,6 +15206,32 @@ class Vector3d {
15166
15206
  return this;
15167
15207
  }
15168
15208
 
15209
+ /**
15210
+ * interpolate the position of this vector on the x and y axis towards the given one by the given maximum step.
15211
+ * @name moveTowards
15212
+ * @memberof Vector3d
15213
+ * @param {Vector2d|Vector3d} target
15214
+ * @param {number} step the maximum step per iteration (Negative values will push the vector away from the target)
15215
+ * @returns {Vector3d} Reference to this object for method chaining
15216
+ */
15217
+ moveTowards(target, step) {
15218
+ var angle = Math.atan2(target.y - this.y, target.x - this.x);
15219
+
15220
+ var dx = this.x - target.x;
15221
+ var dy = this.y - target.y;
15222
+
15223
+ var distance = Math.sqrt(dx * dx + dy * dy);
15224
+
15225
+ if (distance === 0 || (step >= 0 && distance <= step * step)) {
15226
+ return target;
15227
+ }
15228
+
15229
+ this.x += Math.cos(angle) * step;
15230
+ this.y += Math.sin(angle) * step;
15231
+
15232
+ return this;
15233
+ }
15234
+
15169
15235
  /**
15170
15236
  * return the distance between this vector and the passed one
15171
15237
  * @name distance
@@ -15700,10 +15766,38 @@ class ObservableVector3d extends Vector3d {
15700
15766
  * @returns {ObservableVector3d} Reference to this object for method chaining
15701
15767
  */
15702
15768
  lerp(v, alpha) {
15703
- this._x += ( v.x - this._x ) * alpha;
15704
- this._y += ( v.y - this._y ) * alpha;
15705
- this._z += ( v.z - this._z ) * alpha;
15706
- return this;
15769
+ return this._set(
15770
+ this._x + ( v.x - this._x ) * alpha,
15771
+ this._y + ( v.y - this._y ) * alpha,
15772
+ this._z + ( v.z - this._z ) * alpha
15773
+ );
15774
+ }
15775
+
15776
+ /**
15777
+ * interpolate the position of this vector on the x and y axis towards the given one while ensure that the distance never exceeds the given step.
15778
+ * @name moveTowards
15779
+ * @memberof ObservableVector3d
15780
+ * @param {Vector2d|ObservableVector2d|Vector3d|ObservableVector3d} target
15781
+ * @param {number} step the maximum step per iteration (Negative values will push the vector away from the target)
15782
+ * @returns {ObservableVector3d} Reference to this object for method chaining
15783
+ */
15784
+ moveTowards(target, step) {
15785
+ var angle = Math.atan2(target.y - this._y, target.x - this._x);
15786
+
15787
+ var dx = this._x - target.x;
15788
+ var dy = this._y - target.y;
15789
+
15790
+ var distance = Math.sqrt(dx * dx + dy * dy);
15791
+
15792
+ if (distance === 0 || (step >= 0 && distance <= step * step)) {
15793
+ return target;
15794
+ }
15795
+
15796
+ return this._set(
15797
+ this._x + Math.cos(angle) * step,
15798
+ this._y + Math.sin(angle) * step,
15799
+ this._z
15800
+ );
15707
15801
  }
15708
15802
 
15709
15803
  /**
@@ -16698,7 +16792,7 @@ function enablePointerEvent() {
16698
16792
 
16699
16793
  if (pointerEventTarget === null) {
16700
16794
  // default pointer event target
16701
- pointerEventTarget = renderer.getScreenCanvas();
16795
+ pointerEventTarget = renderer.getCanvas();
16702
16796
  }
16703
16797
 
16704
16798
  if (pointerEvent) {
@@ -17129,7 +17223,7 @@ var throttlingInterval;
17129
17223
  */
17130
17224
  function globalToLocal(x, y, v) {
17131
17225
  v = v || pool.pull("Vector2d");
17132
- var rect = getElementBounds(renderer.getScreenCanvas());
17226
+ var rect = getElementBounds(renderer.getCanvas());
17133
17227
  var pixelRatio = globalThis.devicePixelRatio || 1;
17134
17228
  x -= rect.left + (globalThis.pageXOffset || 0);
17135
17229
  y -= rect.top + (globalThis.pageYOffset || 0);
@@ -17932,21 +18026,14 @@ class Renderable extends Rect {
17932
18026
 
17933
18027
  /**
17934
18028
  * If true then physic collision and input events will not impact this renderable
17935
- * @public
17936
18029
  * @type {boolean}
17937
18030
  * @default true
17938
- * @name isKinematic
17939
- * @memberof Renderable
17940
18031
  */
17941
18032
  this.isKinematic = true;
17942
18033
 
17943
18034
  /**
17944
18035
  * the renderable physic body
17945
- * @public
17946
18036
  * @type {Body}
17947
- * @see Body
17948
- * @name body
17949
- * @memberof Renderable#
17950
18037
  * @example
17951
18038
  * // define a new Player Class
17952
18039
  * class PlayerEntity extends me.Sprite {
@@ -17984,10 +18071,7 @@ class Renderable extends Rect {
17984
18071
  if (typeof this.currentTransform === "undefined") {
17985
18072
  /**
17986
18073
  * the renderable default transformation matrix
17987
- * @public
17988
18074
  * @type {Matrix2d}
17989
- * @name currentTransform
17990
- * @memberof Renderable#
17991
18075
  */
17992
18076
  this.currentTransform = pool.pull("Matrix2d");
17993
18077
  }
@@ -17997,20 +18081,14 @@ class Renderable extends Rect {
17997
18081
  * (G)ame (U)nique (Id)entifier" <br>
17998
18082
  * a GUID will be allocated for any renderable object added <br>
17999
18083
  * to an object container (including the `me.game.world` container)
18000
- * @public
18001
18084
  * @type {string}
18002
- * @name GUID
18003
- * @memberof Renderable
18004
18085
  */
18005
18086
  this.GUID = undefined;
18006
18087
 
18007
18088
  /**
18008
18089
  * an event handler that is called when the renderable leave or enter a camera viewport
18009
- * @public
18010
18090
  * @type {Function}
18011
18091
  * @default undefined
18012
- * @name onVisibilityChange
18013
- * @memberof Renderable#
18014
18092
  * @example
18015
18093
  * this.onVisibilityChange = function(inViewport) {
18016
18094
  * if (inViewport === true) {
@@ -18022,42 +18100,30 @@ class Renderable extends Rect {
18022
18100
 
18023
18101
  /**
18024
18102
  * Whether the renderable object will always update, even when outside of the viewport<br>
18025
- * @public
18026
18103
  * @type {boolean}
18027
18104
  * @default false
18028
- * @name alwaysUpdate
18029
- * @memberof Renderable
18030
18105
  */
18031
18106
  this.alwaysUpdate = false;
18032
18107
 
18033
18108
  /**
18034
18109
  * Whether to update this object when the game is paused.
18035
- * @public
18036
18110
  * @type {boolean}
18037
18111
  * @default false
18038
- * @name updateWhenPaused
18039
- * @memberof Renderable
18040
18112
  */
18041
18113
  this.updateWhenPaused = false;
18042
18114
 
18043
18115
  /**
18044
18116
  * make the renderable object persistent over level changes<br>
18045
- * @public
18046
18117
  * @type {boolean}
18047
18118
  * @default false
18048
- * @name isPersistent
18049
- * @memberof Renderable
18050
18119
  */
18051
18120
  this.isPersistent = false;
18052
18121
 
18053
18122
  /**
18054
18123
  * If true, this renderable will be rendered using screen coordinates,
18055
18124
  * as opposed to world coordinates. Use this, for example, to define UI elements.
18056
- * @public
18057
18125
  * @type {boolean}
18058
18126
  * @default false
18059
- * @name floating
18060
- * @memberof Renderable
18061
18127
  */
18062
18128
  this.floating = false;
18063
18129
 
@@ -18072,11 +18138,8 @@ class Renderable extends Rect {
18072
18138
  * <br>
18073
18139
  * <i><b>Note:</b> Object created through Tiled will have their anchorPoint set to (0, 0) to match Tiled Level editor implementation.
18074
18140
  * To specify a value through Tiled, use a json expression like `json:{"x":0.5,"y":0.5}`. </i>
18075
- * @public
18076
18141
  * @type {ObservableVector2d}
18077
18142
  * @default <0.5,0.5>
18078
- * @name anchorPoint
18079
- * @memberof Renderable#
18080
18143
  */
18081
18144
  this.anchorPoint = pool.pull("ObservableVector2d", 0.5, 0.5, { onUpdate: this.onAnchorUpdate, scope: this });
18082
18145
  }
@@ -18084,11 +18147,8 @@ class Renderable extends Rect {
18084
18147
  /**
18085
18148
  * When enabled, an object container will automatically apply
18086
18149
  * any defined transformation before calling the child draw method.
18087
- * @public
18088
18150
  * @type {boolean}
18089
18151
  * @default true
18090
- * @name autoTransform
18091
- * @memberof Renderable
18092
18152
  * @example
18093
18153
  * // enable "automatic" transformation when the object is activated
18094
18154
  * onActivateEvent: function () {
@@ -18108,30 +18168,23 @@ class Renderable extends Rect {
18108
18168
  * Set to zero if you do not wish an object to be drawn
18109
18169
  * @see Renderable#setOpacity
18110
18170
  * @see Renderable#getOpacity
18111
- * @public
18112
18171
  * @type {number}
18113
18172
  * @default 1.0
18114
- * @name Renderable#alpha
18115
18173
  */
18116
18174
  this.alpha = 1.0;
18117
18175
 
18118
18176
  /**
18119
18177
  * a reference to the parent object that contains this renderable
18120
- * @public
18121
18178
  * @type {Container|Entity}
18122
18179
  * @default undefined
18123
- * @name Renderable#ancestor
18124
18180
  */
18125
18181
  this.ancestor = undefined;
18126
18182
 
18127
18183
  /**
18128
18184
  * A mask limits rendering elements to the shape and position of the given mask object.
18129
18185
  * So, if the renderable is larger than the mask, only the intersecting part of the renderable will be visible.
18130
- * @public
18131
18186
  * @type {Rect|RoundRect|Polygon|Line|Ellipse}
18132
- * @name mask
18133
18187
  * @default undefined
18134
- * @memberof Renderable#
18135
18188
  * @example
18136
18189
  * // apply a mask in the shape of a Star
18137
18190
  * myNPCSprite.mask = new me.Polygon(myNPCSprite.width / 2, 0, [
@@ -18150,40 +18203,19 @@ class Renderable extends Rect {
18150
18203
  */
18151
18204
  this.mask = undefined;
18152
18205
 
18153
- /**
18154
- * define a tint for this renderable. a (255, 255, 255) r, g, b value will remove the tint effect.
18155
- * @public
18156
- * @type {Color}
18157
- * @name tint
18158
- * @default (255, 255, 255)
18159
- * @memberof Renderable#
18160
- * @example
18161
- * // add a red tint to this renderable
18162
- * this.tint.setColor(255, 128, 128);
18163
- * // remove the tint
18164
- * this.tint.setColor(255, 255, 255);
18165
- */
18166
- this.tint = pool.pull("Color", 255, 255, 255, 1.0);
18167
-
18168
18206
  /**
18169
18207
  * the blend mode to be applied to this renderable (see renderer setBlendMode for available blend mode)
18170
- * @public
18171
18208
  * @type {string}
18172
- * @name blendMode
18173
18209
  * @default "normal"
18174
18210
  * @see CanvasRenderer#setBlendMode
18175
18211
  * @see WebGLRenderer#setBlendMode
18176
- * @memberof Renderable#
18177
18212
  */
18178
18213
  this.blendMode = "normal";
18179
18214
 
18180
18215
  /**
18181
18216
  * The name of the renderable
18182
- * @public
18183
18217
  * @type {string}
18184
- * @name name
18185
18218
  * @default ""
18186
- * @memberof Renderable
18187
18219
  */
18188
18220
  this.name = "";
18189
18221
 
@@ -18194,8 +18226,6 @@ class Renderable extends Rect {
18194
18226
  * Position of the Renderable relative to its parent container
18195
18227
  * @public
18196
18228
  * @type {ObservableVector3d}
18197
- * @name pos
18198
- * @memberof Renderable#
18199
18229
  */
18200
18230
  this.pos = pool.pull("ObservableVector3d", x, y, 0, { onUpdate: this.updateBoundsPos, scope: this});
18201
18231
  }
@@ -18203,9 +18233,7 @@ class Renderable extends Rect {
18203
18233
  /**
18204
18234
  * when true the renderable will be redrawn during the next update cycle
18205
18235
  * @type {boolean}
18206
- * @name isDirty
18207
18236
  * @default false
18208
- * @memberof Renderable#
18209
18237
  */
18210
18238
  this.isDirty = false;
18211
18239
 
@@ -18224,23 +18252,45 @@ class Renderable extends Rect {
18224
18252
 
18225
18253
  /**
18226
18254
  * Whether the renderable object is floating, or contained in a floating container
18227
- * @public
18228
18255
  * @see Renderable#floating
18229
18256
  * @type {boolean}
18230
- * @name isFloating
18231
- * @memberof Renderable
18232
18257
  */
18233
18258
  get isFloating() {
18234
18259
  return this.floating === true || (typeof this.ancestor !== "undefined" && this.ancestor.floating === true);
18235
18260
  }
18236
18261
 
18262
+ /**
18263
+ * define a tint for this renderable. a (255, 255, 255) r, g, b value will remove the tint effect.
18264
+ * @type {Color}
18265
+ * @default (255, 255, 255)
18266
+ * @example
18267
+ * // add a red tint to this renderable
18268
+ * this.tint.setColor(255, 128, 128);
18269
+ * // remove the tint
18270
+ * this.tint.setColor(255, 255, 255);
18271
+ */
18272
+ get tint() {
18273
+ if (typeof this._tint === "undefined") {
18274
+ this._tint = pool.pull("Color", 255, 255, 255, 1.0);
18275
+ }
18276
+ return this._tint;
18277
+ }
18278
+ set tint(value) {
18279
+ if (typeof this._tint === "undefined") {
18280
+ this._tint = pool.pull("Color", 255, 255, 255, 1.0);
18281
+ }
18282
+ if (value instanceof Color) {
18283
+ this._tint.copy(value);
18284
+ } else {
18285
+ // string (#RGB, #ARGB, #RRGGBB, #AARRGGBB)
18286
+ this._tint.parseCSS(value);
18287
+ }
18288
+ }
18289
+
18237
18290
  /**
18238
18291
  * Whether the renderable object is visible and within the viewport
18239
- * @public
18240
18292
  * @type {boolean}
18241
18293
  * @default false
18242
- * @name inViewport
18243
- * @memberof Renderable
18244
18294
  */
18245
18295
  get inViewport() {
18246
18296
  return this._inViewport;
@@ -18259,8 +18309,6 @@ class Renderable extends Rect {
18259
18309
  * @public
18260
18310
  * @see Renderable#flipX
18261
18311
  * @type {boolean}
18262
- * @name isFlippedX
18263
- * @memberof Renderable
18264
18312
  */
18265
18313
  get isFlippedX() {
18266
18314
  return this._flip.x === true;
@@ -18271,8 +18319,6 @@ class Renderable extends Rect {
18271
18319
  * @public
18272
18320
  * @see Renderable#flipY
18273
18321
  * @type {boolean}
18274
- * @name isFlippedY
18275
- * @memberof Renderable
18276
18322
  */
18277
18323
  get isFlippedY() {
18278
18324
  return this._flip.y === true;
@@ -18280,8 +18326,6 @@ class Renderable extends Rect {
18280
18326
 
18281
18327
  /**
18282
18328
  * returns the bounding box for this renderable
18283
- * @name getBounds
18284
- * @memberof Renderable
18285
18329
  * @returns {Bounds} bounding box Rectangle object
18286
18330
  */
18287
18331
  getBounds() {
@@ -18300,8 +18344,6 @@ class Renderable extends Rect {
18300
18344
 
18301
18345
  /**
18302
18346
  * get the renderable alpha channel value<br>
18303
- * @name getOpacity
18304
- * @memberof Renderable
18305
18347
  * @returns {number} current opacity value between 0 and 1
18306
18348
  */
18307
18349
  getOpacity() {
@@ -18310,8 +18352,6 @@ class Renderable extends Rect {
18310
18352
 
18311
18353
  /**
18312
18354
  * set the renderable alpha channel value<br>
18313
- * @name setOpacity
18314
- * @memberof Renderable
18315
18355
  * @param {number} alpha opacity value between 0.0 and 1.0
18316
18356
  */
18317
18357
  setOpacity(alpha) {
@@ -18328,8 +18368,6 @@ class Renderable extends Rect {
18328
18368
  /**
18329
18369
  * flip the renderable on the horizontal axis (around the center of the renderable)
18330
18370
  * @see Matrix2d#scaleX
18331
- * @name flipX
18332
- * @memberof Renderable
18333
18371
  * @param {boolean} [flip=true] `true` to flip this renderable.
18334
18372
  * @returns {Renderable} Reference to this object for method chaining
18335
18373
  */
@@ -18342,8 +18380,6 @@ class Renderable extends Rect {
18342
18380
  /**
18343
18381
  * flip the renderable on the vertical axis (around the center of the renderable)
18344
18382
  * @see Matrix2d#scaleY
18345
- * @name flipY
18346
- * @memberof Renderable
18347
18383
  * @param {boolean} [flip=true] `true` to flip this renderable.
18348
18384
  * @returns {Renderable} Reference to this object for method chaining
18349
18385
  */
@@ -18355,8 +18391,6 @@ class Renderable extends Rect {
18355
18391
 
18356
18392
  /**
18357
18393
  * multiply the renderable currentTransform with the given matrix
18358
- * @name transform
18359
- * @memberof Renderable
18360
18394
  * @see Renderable#currentTransform
18361
18395
  * @param {Matrix2d} m the transformation matrix
18362
18396
  * @returns {Renderable} Reference to this object for method chaining
@@ -18371,8 +18405,6 @@ class Renderable extends Rect {
18371
18405
 
18372
18406
  /**
18373
18407
  * return the angle to the specified target
18374
- * @name angleTo
18375
- * @memberof Renderable
18376
18408
  * @param {Renderable|Vector2d|Vector3d} target
18377
18409
  * @returns {number} angle in radians
18378
18410
  */
@@ -18394,8 +18426,6 @@ class Renderable extends Rect {
18394
18426
 
18395
18427
  /**
18396
18428
  * return the distance to the specified target
18397
- * @name distanceTo
18398
- * @memberof Renderable
18399
18429
  * @param {Renderable|Vector2d|Vector3d} target
18400
18430
  * @returns {number} distance
18401
18431
  */
@@ -18417,8 +18447,6 @@ class Renderable extends Rect {
18417
18447
 
18418
18448
  /**
18419
18449
  * Rotate this renderable towards the given target.
18420
- * @name lookAt
18421
- * @memberof Renderable
18422
18450
  * @param {Renderable|Vector2d|Vector3d} target the renderable or position to look at
18423
18451
  * @returns {Renderable} Reference to this object for method chaining
18424
18452
  */
@@ -18440,8 +18468,6 @@ class Renderable extends Rect {
18440
18468
 
18441
18469
  /**
18442
18470
  * Rotate this renderable by the specified angle (in radians).
18443
- * @name rotate
18444
- * @memberof Renderable
18445
18471
  * @param {number} angle The angle to rotate (in radians)
18446
18472
  * @param {Vector2d|ObservableVector2d} [v] an optional point to rotate around
18447
18473
  * @returns {Renderable} Reference to this object for method chaining
@@ -18461,8 +18487,6 @@ class Renderable extends Rect {
18461
18487
  * when rendering. It does not scale the object itself. For example if the renderable
18462
18488
  * is an image, the image.width and image.height properties are unaltered but the currentTransform
18463
18489
  * member will be changed.
18464
- * @name scale
18465
- * @memberof Renderable
18466
18490
  * @param {number} x a number representing the abscissa of the scaling vector.
18467
18491
  * @param {number} [y=x] a number representing the ordinate of the scaling vector.
18468
18492
  * @returns {Renderable} Reference to this object for method chaining
@@ -18476,8 +18500,6 @@ class Renderable extends Rect {
18476
18500
 
18477
18501
  /**
18478
18502
  * scale the renderable around his anchor point
18479
- * @name scaleV
18480
- * @memberof Renderable
18481
18503
  * @param {Vector2d} v scaling vector
18482
18504
  * @returns {Renderable} Reference to this object for method chaining
18483
18505
  */
@@ -18487,11 +18509,7 @@ class Renderable extends Rect {
18487
18509
  }
18488
18510
 
18489
18511
  /**
18490
- * update function. <br>
18491
- * automatically called by the game manager {@link game}
18492
- * @name update
18493
- * @memberof Renderable
18494
- * @protected
18512
+ * update function (automatically called by melonJS).
18495
18513
  * @param {number} dt time since the last update in milliseconds.
18496
18514
  * @returns {boolean} true if the renderable is dirty
18497
18515
  */
@@ -18502,8 +18520,6 @@ class Renderable extends Rect {
18502
18520
  /**
18503
18521
  * update the bounding box for this shape.
18504
18522
  * @ignore
18505
- * @name updateBounds
18506
- * @memberof Renderable
18507
18523
  * @returns {Bounds} this shape bounding box Rectangle object
18508
18524
  */
18509
18525
  updateBounds() {
@@ -18515,8 +18531,6 @@ class Renderable extends Rect {
18515
18531
  /**
18516
18532
  * update the renderable's bounding rect (private)
18517
18533
  * @ignore
18518
- * @name updateBoundsPos
18519
- * @memberof Renderable
18520
18534
  */
18521
18535
  updateBoundsPos(newX, newY) {
18522
18536
  var bounds = this.getBounds();
@@ -18547,8 +18561,6 @@ class Renderable extends Rect {
18547
18561
 
18548
18562
  /**
18549
18563
  * return the renderable absolute position in the game world
18550
- * @name getAbsolutePosition
18551
- * @memberof Renderable
18552
18564
  * @returns {Vector2d}
18553
18565
  */
18554
18566
  getAbsolutePosition() {
@@ -18566,8 +18578,6 @@ class Renderable extends Rect {
18566
18578
  /**
18567
18579
  * called when the anchor point value is changed
18568
18580
  * @private
18569
- * @name onAnchorUpdate
18570
- * @memberof Renderable
18571
18581
  * @param {number} x the new X value to be set for the anchor
18572
18582
  * @param {number} y the new Y value to be set for the anchor
18573
18583
  */
@@ -18580,12 +18590,10 @@ class Renderable extends Rect {
18580
18590
  }
18581
18591
 
18582
18592
  /**
18583
- * prepare the rendering context before drawing
18584
- * (apply defined transforms, anchor point). <br>
18585
- * automatically called by the game manager {@link game}
18586
- * @name preDraw
18587
- * @memberof Renderable
18588
- * @protected
18593
+ * Prepare the rendering context before drawing (automatically called by melonJS).
18594
+ * This will apply any defined transforms, anchor point, tint or blend mode and translate the context accordingly to this renderable position.
18595
+ * @see Renderable#draw
18596
+ * @see Renderable#postDraw
18589
18597
  * @param {CanvasRenderer|WebGLRenderer} renderer a renderer object
18590
18598
  */
18591
18599
  preDraw(renderer) {
@@ -18636,10 +18644,15 @@ class Renderable extends Rect {
18636
18644
  }
18637
18645
 
18638
18646
  /**
18639
- * draw this renderable (automatically called by melonJS)
18640
- * @name draw
18641
- * @memberof Renderable
18642
- * @protected
18647
+ * Draw this renderable (automatically called by melonJS).
18648
+ * All draw operations for renderable are made respectively
18649
+ * to the position or transforms set or applied by the preDraw method.
18650
+ * The main draw loop will first call preDraw() to prepare the context for drawing the renderable,
18651
+ * then draw() to draw the renderable, and finally postDraw() to clear the context.
18652
+ * If you override this method, be mindful about the drawing logic; for example if you draw a shape
18653
+ * from the draw method, you should make sure that your draw it at the 0, 0 coordinates.
18654
+ * @see Renderable#preDraw
18655
+ * @see Renderable#postDraw
18643
18656
  * @param {CanvasRenderer|WebGLRenderer} renderer a renderer instance
18644
18657
  * @param {Camera2d} [viewport] the viewport to (re)draw
18645
18658
  */
@@ -18648,11 +18661,9 @@ class Renderable extends Rect {
18648
18661
  }
18649
18662
 
18650
18663
  /**
18651
- * restore the rendering context after drawing. <br>
18652
- * automatically called by the game manager {@link game}
18653
- * @name postDraw
18654
- * @memberof Renderable
18655
- * @protected
18664
+ * restore the rendering context after drawing (automatically called by melonJS).
18665
+ * @see Renderable#preDraw
18666
+ * @see Renderable#draw
18656
18667
  * @param {CanvasRenderer|WebGLRenderer} renderer a renderer object
18657
18668
  */
18658
18669
  postDraw(renderer) {
@@ -18674,8 +18685,6 @@ class Renderable extends Rect {
18674
18685
  /**
18675
18686
  * onCollision callback, triggered in case of collision,
18676
18687
  * when this renderable body is colliding with another one
18677
- * @name onCollision
18678
- * @memberof Renderable
18679
18688
  * @param {ResponseObject} response the collision response object
18680
18689
  * @param {Renderable} other the other renderable touching this one (a reference to response.a or response.b)
18681
18690
  * @returns {boolean} true if the object should respond to the collision (its position and velocity will be corrected)
@@ -18727,9 +18736,9 @@ class Renderable extends Rect {
18727
18736
  this.mask = undefined;
18728
18737
  }
18729
18738
 
18730
- if (typeof this.tint !== "undefined") {
18731
- pool.push(this.tint);
18732
- this.tint = undefined;
18739
+ if (typeof this._tint !== "undefined") {
18740
+ pool.push(this._tint);
18741
+ this._tint = undefined;
18733
18742
  }
18734
18743
 
18735
18744
  this.ancestor = undefined;
@@ -18750,8 +18759,6 @@ class Renderable extends Rect {
18750
18759
  /**
18751
18760
  * OnDestroy Notification function<br>
18752
18761
  * Called by engine before deleting the object
18753
- * @name onDestroyEvent
18754
- * @memberof Renderable
18755
18762
  */
18756
18763
  onDestroyEvent() {
18757
18764
  // to be extended !
@@ -19594,7 +19601,7 @@ var collision = {
19594
19601
  class Body {
19595
19602
  /**
19596
19603
  * @param {Renderable} ancestor the parent object this body is attached to
19597
- * @param {Rect|Rect[]|Polygon|Polygon[]|Line|Line[]|Ellipse|Ellipse[]|Bounds|Bounds[]|object} [shapes] a initial shape, list of shapes, or JSON object defining the body
19604
+ * @param {Rect|Rect[]|Polygon|Polygon[]|Line|Line[]|Ellipse|Ellipse[]|Point|Point[]|Bounds|Bounds[]|object} [shapes] a initial shape, list of shapes, or JSON object defining the body
19598
19605
  * @param {Function} [onBodyUpdate] callback for when the body is updated (e.g. add/remove shapes)
19599
19606
  */
19600
19607
  constructor(ancestor, shapes, onBodyUpdate) {
@@ -19621,7 +19628,7 @@ class Body {
19621
19628
  /**
19622
19629
  * The collision shapes of the body
19623
19630
  * @ignore
19624
- * @type {Polygon[]|Line[]|Ellipse[]}
19631
+ * @type {Polygon[]|Line[]|Ellipse[]|Point|Point[]}
19625
19632
  */
19626
19633
  this.shapes = [];
19627
19634
  }
@@ -19813,7 +19820,7 @@ class Body {
19813
19820
  /**
19814
19821
  * add a collision shape to this body <br>
19815
19822
  * (note: me.Rect objects will be converted to me.Polygon before being added)
19816
- * @param {Rect|Polygon|Line|Ellipse|Bounds|object} shape a shape or JSON object
19823
+ * @param {Rect|Polygon|Line|Ellipse|Point|Point[]|Bounds|object} shape a shape or JSON object
19817
19824
  * @returns {number} the shape array length
19818
19825
  * @example
19819
19826
  * // add a rectangle shape
@@ -19848,6 +19855,12 @@ class Body {
19848
19855
  // update the body bounds
19849
19856
  this.bounds.add(shape.points);
19850
19857
  this.bounds.translate(shape.pos);
19858
+ } else if (shape instanceof Point) {
19859
+ if (!this.shapes.includes(shape)) {
19860
+ // see removeShape
19861
+ this.shapes.push(shape);
19862
+ }
19863
+ this.bounds.addPoint(shape);
19851
19864
  } else {
19852
19865
  // JSON object
19853
19866
  this.fromJSON(shape);
@@ -24227,7 +24240,6 @@ class CanvasRenderer extends Renderer {
24227
24240
  * @param {number} options.width The width of the canvas without scaling
24228
24241
  * @param {number} options.height The height of the canvas without scaling
24229
24242
  * @param {HTMLCanvasElement} [options.canvas] The html canvas to draw to on screen
24230
- * @param {boolean} [options.doubleBuffering=false] Whether to enable double buffering
24231
24243
  * @param {boolean} [options.antiAlias=false] Whether to enable anti-aliasing
24232
24244
  * @param {boolean} [options.transparent=false] Whether to enable transparency on the canvas (performance hit when enabled)
24233
24245
  * @param {boolean} [options.subPixel=false] Whether to enable subpixel renderering (performance hit when enabled)
@@ -24240,17 +24252,7 @@ class CanvasRenderer extends Renderer {
24240
24252
  super(options);
24241
24253
 
24242
24254
  // defined the 2d context
24243
- this.context = this.getContext2d(this.getScreenCanvas(), this.settings.transparent);
24244
-
24245
- // create the back buffer if we use double buffering
24246
- if (this.settings.doubleBuffering) {
24247
- this.backBufferCanvas = createCanvas(this.settings.width, this.settings.height, true);
24248
- this.backBufferContext2D = this.getContext2d(this.backBufferCanvas);
24249
- }
24250
- else {
24251
- this.backBufferCanvas = this.getScreenCanvas();
24252
- this.backBufferContext2D = this.context;
24253
- }
24255
+ this.context = this.getContext2d(this.getCanvas(), this.settings.transparent);
24254
24256
 
24255
24257
  this.setBlendMode(this.settings.blendMode);
24256
24258
 
@@ -24266,13 +24268,13 @@ class CanvasRenderer extends Renderer {
24266
24268
  }
24267
24269
 
24268
24270
  // context lost & restore event for canvas
24269
- this.getScreenCanvas().addEventListener("contextlost", (e) => {
24271
+ this.getCanvas().addEventListener("contextlost", (e) => {
24270
24272
  e.preventDefault();
24271
24273
  this.isContextValid = false;
24272
24274
  emit(ONCONTEXT_LOST, this);
24273
24275
  }, false );
24274
24276
  // ctx.restoreContext()
24275
- this.getScreenCanvas().addEventListener("contextrestored", () => {
24277
+ this.getCanvas().addEventListener("contextrestored", () => {
24276
24278
  this.isContextValid = true;
24277
24279
  emit(ONCONTEXT_RESTORED, this);
24278
24280
  }, false );
@@ -24294,7 +24296,7 @@ class CanvasRenderer extends Renderer {
24294
24296
  * @memberof CanvasRenderer
24295
24297
  */
24296
24298
  resetTransform() {
24297
- this.backBufferContext2D.setTransform(1, 0, 0, 1, 0, 0);
24299
+ this.getContext().setTransform(1, 0, 0, 1, 0, 0);
24298
24300
  }
24299
24301
 
24300
24302
  /**
@@ -24336,12 +24338,6 @@ class CanvasRenderer extends Renderer {
24336
24338
  this.currentBlendMode = "normal";
24337
24339
  break;
24338
24340
  }
24339
-
24340
- // transparent setting will override the given blendmode for this.context
24341
- if (this.settings.doubleBuffering && this.settings.transparent) {
24342
- // Clears the front buffer for each frame blit
24343
- this.context.globalCompositeOperation = "copy";
24344
- }
24345
24341
  }
24346
24342
 
24347
24343
  /**
@@ -24350,19 +24346,10 @@ class CanvasRenderer extends Renderer {
24350
24346
  * @memberof CanvasRenderer
24351
24347
  */
24352
24348
  clear() {
24353
- if (this.settings.transparent) {
24354
- this.clearColor("rgba(0,0,0,0)", true);
24355
- }
24356
- }
24357
-
24358
- /**
24359
- * render the main framebuffer on screen
24360
- * @name flush
24361
- * @memberof CanvasRenderer
24362
- */
24363
- flush() {
24364
- if (this.settings.doubleBuffering) {
24365
- this.context.drawImage(this.backBufferCanvas, 0, 0);
24349
+ if (this.settings.transparent === false) {
24350
+ var canvas = this.getCanvas();
24351
+ var context = this.getContext();
24352
+ context.clearRect(0, 0, canvas.width, canvas.height);
24366
24353
  }
24367
24354
  }
24368
24355
 
@@ -24373,12 +24360,16 @@ class CanvasRenderer extends Renderer {
24373
24360
  * @param {Color|string} [color="#000000"] CSS color.
24374
24361
  * @param {boolean} [opaque=false] Allow transparency [default] or clear the surface completely [true]
24375
24362
  */
24376
- clearColor(color = "#000000", opaque) {
24363
+ clearColor(color = "#000000", opaque = false) {
24364
+ var canvas = this.getCanvas();
24365
+ var context = this.getContext();
24366
+
24377
24367
  this.save();
24378
24368
  this.resetTransform();
24379
- this.backBufferContext2D.globalCompositeOperation = opaque ? "copy" : "source-over";
24380
- this.backBufferContext2D.fillStyle = (color instanceof Color) ? color.toRGBA() : color;
24381
- this.fillRect(0, 0, this.backBufferCanvas.width, this.backBufferCanvas.height);
24369
+ context.globalAlpha = 1;
24370
+ context.globalCompositeOperation = opaque === true ? "copy" : "source-over";
24371
+ context.fillStyle = (color instanceof Color) ? color.toRGBA() : color;
24372
+ this.fillRect(0, 0, canvas.width, canvas.height);
24382
24373
  this.restore();
24383
24374
  }
24384
24375
 
@@ -24738,15 +24729,28 @@ class CanvasRenderer extends Renderer {
24738
24729
  this.strokeRoundRect(x, y, width, height, radius, true);
24739
24730
  }
24740
24731
 
24732
+ /**
24733
+ * Stroke a Point at the specified coordinates
24734
+ * @name strokePoint
24735
+ * @memberof CanvasRenderer
24736
+ * @param {number} x
24737
+ * @param {number} y
24738
+ */
24739
+ strokePoint(x, y) {
24740
+ this.strokeLine(x, y, x + 1, y + 1);
24741
+ }
24741
24742
 
24742
24743
  /**
24743
- * return a reference to the system 2d Context
24744
- * @name getContext
24744
+ * Draw a a point at the specified coordinates
24745
+ * @name fillPoint
24745
24746
  * @memberof CanvasRenderer
24746
- * @returns {CanvasRenderingContext2D}
24747
+ * @param {number} x
24748
+ * @param {number} y
24749
+ * @param {number} width
24750
+ * @param {number} height
24747
24751
  */
24748
- getContext() {
24749
- return this.backBufferContext2D;
24752
+ fillPoint(x, y) {
24753
+ this.strokePoint(x, y);
24750
24754
  }
24751
24755
 
24752
24756
  /**
@@ -24764,7 +24768,7 @@ class CanvasRenderer extends Renderer {
24764
24768
  * @memberof CanvasRenderer
24765
24769
  */
24766
24770
  save() {
24767
- this.backBufferContext2D.save();
24771
+ this.getContext().save();
24768
24772
  }
24769
24773
 
24770
24774
  /**
@@ -24773,12 +24777,12 @@ class CanvasRenderer extends Renderer {
24773
24777
  * @memberof CanvasRenderer
24774
24778
  */
24775
24779
  restore() {
24776
- this.backBufferContext2D.restore();
24780
+ this.getContext().restore();
24777
24781
  this.currentColor.glArray[3] = this.getGlobalAlpha();
24778
24782
  this.currentScissor[0] = 0;
24779
24783
  this.currentScissor[1] = 0;
24780
- this.currentScissor[2] = this.backBufferCanvas.width;
24781
- this.currentScissor[3] = this.backBufferCanvas.height;
24784
+ this.currentScissor[2] = this.getCanvas().width;
24785
+ this.currentScissor[3] = this.getCanvas().height;
24782
24786
  }
24783
24787
 
24784
24788
  /**
@@ -24788,7 +24792,7 @@ class CanvasRenderer extends Renderer {
24788
24792
  * @param {number} angle in radians
24789
24793
  */
24790
24794
  rotate(angle) {
24791
- this.backBufferContext2D.rotate(angle);
24795
+ this.getContext().rotate(angle);
24792
24796
  }
24793
24797
 
24794
24798
  /**
@@ -24799,7 +24803,7 @@ class CanvasRenderer extends Renderer {
24799
24803
  * @param {number} y
24800
24804
  */
24801
24805
  scale(x, y) {
24802
- this.backBufferContext2D.scale(x, y);
24806
+ this.getContext().scale(x, y);
24803
24807
  }
24804
24808
 
24805
24809
  /**
@@ -24810,8 +24814,9 @@ class CanvasRenderer extends Renderer {
24810
24814
  * @param {Color|string} color css color value
24811
24815
  */
24812
24816
  setColor(color) {
24813
- this.backBufferContext2D.strokeStyle =
24814
- this.backBufferContext2D.fillStyle = (
24817
+ var context = this.getContext();
24818
+ context.strokeStyle =
24819
+ context.fillStyle = (
24815
24820
  color instanceof Color ?
24816
24821
  color.toRGBA() :
24817
24822
  color
@@ -24825,7 +24830,7 @@ class CanvasRenderer extends Renderer {
24825
24830
  * @param {number} alpha 0.0 to 1.0 values accepted.
24826
24831
  */
24827
24832
  setGlobalAlpha(alpha) {
24828
- this.backBufferContext2D.globalAlpha = this.currentColor.glArray[3] = alpha;
24833
+ this.getContext().globalAlpha = this.currentColor.glArray[3] = alpha;
24829
24834
  }
24830
24835
 
24831
24836
  /**
@@ -24835,7 +24840,7 @@ class CanvasRenderer extends Renderer {
24835
24840
  * @returns {number} global alpha value
24836
24841
  */
24837
24842
  getGlobalAlpha() {
24838
- return this.backBufferContext2D.globalAlpha;
24843
+ return this.getContext().globalAlpha;
24839
24844
  }
24840
24845
 
24841
24846
  /**
@@ -24845,7 +24850,7 @@ class CanvasRenderer extends Renderer {
24845
24850
  * @param {number} width Line width
24846
24851
  */
24847
24852
  setLineWidth(width) {
24848
- this.backBufferContext2D.lineWidth = width;
24853
+ this.getContext().lineWidth = width;
24849
24854
  }
24850
24855
 
24851
24856
  /**
@@ -24880,7 +24885,7 @@ class CanvasRenderer extends Renderer {
24880
24885
  f |= 0;
24881
24886
  }
24882
24887
 
24883
- this.backBufferContext2D.transform(a, b, c, d, e, f);
24888
+ this.getContext().transform(a, b, c, d, e, f);
24884
24889
  }
24885
24890
 
24886
24891
  /**
@@ -24892,9 +24897,9 @@ class CanvasRenderer extends Renderer {
24892
24897
  */
24893
24898
  translate(x, y) {
24894
24899
  if (this.settings.subPixel === false) {
24895
- this.backBufferContext2D.translate(~~x, ~~y);
24900
+ this.getContext().translate(~~x, ~~y);
24896
24901
  } else {
24897
- this.backBufferContext2D.translate(x, y);
24902
+ this.getContext().translate(x, y);
24898
24903
  }
24899
24904
  }
24900
24905
 
@@ -24912,14 +24917,14 @@ class CanvasRenderer extends Renderer {
24912
24917
  * @param {number} height
24913
24918
  */
24914
24919
  clipRect(x, y, width, height) {
24915
- var canvas = this.backBufferCanvas;
24920
+ var canvas = this.getCanvas();
24916
24921
  // if requested box is different from the current canvas size;
24917
24922
  if (x !== 0 || y !== 0 || width !== canvas.width || height !== canvas.height) {
24918
24923
  var currentScissor = this.currentScissor;
24919
24924
  // if different from the current scissor box
24920
24925
  if (currentScissor[0] !== x || currentScissor[1] !== y ||
24921
24926
  currentScissor[2] !== width || currentScissor[3] !== height) {
24922
- var context = this.backBufferContext2D;
24927
+ var context = this.getContext();
24923
24928
  context.beginPath();
24924
24929
  context.rect(x, y, width, height);
24925
24930
  context.clip();
@@ -25145,6 +25150,15 @@ class TMXLayer extends Renderable {
25145
25150
  */
25146
25151
  this.renderorder = data.renderorder || "right-down";
25147
25152
 
25153
+ /**
25154
+ * the layer class
25155
+ * @public
25156
+ * @type {string}
25157
+ * @name class
25158
+ * @name TMXLayer#class
25159
+ */
25160
+ this.class = data.class;
25161
+
25148
25162
  // for displaying order
25149
25163
  this.pos.z = z;
25150
25164
 
@@ -26535,6 +26549,14 @@ class TMXTileset {
26535
26549
  */
26536
26550
  this.isCollection = false;
26537
26551
 
26552
+ /**
26553
+ * the tileset class
26554
+ * @public
26555
+ * @type {boolean}
26556
+ * @name TMXTileset#class
26557
+ */
26558
+ this.class = tileset.class;
26559
+
26538
26560
  /**
26539
26561
  * Tileset animations
26540
26562
  * @private
@@ -26933,20 +26955,31 @@ class TMXObject {
26933
26955
  * object type
26934
26956
  * @public
26935
26957
  * @type {string}
26958
+ * @deprecated since Tiled 1.9
26959
+ * @see https://docs.mapeditor.org/en/stable/reference/tmx-changelog/#tiled-1-9
26936
26960
  * @name type
26937
26961
  * @memberof TMXObject
26938
26962
  */
26939
26963
  this.type = settings.type;
26940
26964
 
26965
+ /**
26966
+ * the object class
26967
+ * @public
26968
+ * @type {string}
26969
+ * @name class
26970
+ * @memberof TMXObject
26971
+ */
26972
+ this.class = typeof settings.class !== "undefined" ? settings.class : settings.type;
26973
+
26941
26974
  /**
26942
26975
  * object text
26943
26976
  * @public
26944
26977
  * @type {object}
26945
26978
  * @see http://docs.mapeditor.org/en/stable/reference/tmx-map-format/#text
26946
- * @name type
26979
+ * @name text
26947
26980
  * @memberof TMXObject
26948
26981
  */
26949
- this.type = settings.type;
26982
+ this.text = undefined;
26950
26983
 
26951
26984
  /**
26952
26985
  * The rotation of the object in radians clockwise (defaults to 0)
@@ -26993,6 +27026,15 @@ class TMXObject {
26993
27026
  */
26994
27027
  this.isEllipse = false;
26995
27028
 
27029
+ /**
27030
+ * if true, the object is a Point
27031
+ * @public
27032
+ * @type {boolean}
27033
+ * @name isPoint
27034
+ * @memberof TMXObject
27035
+ */
27036
+ this.isPoint = false;
27037
+
26996
27038
  /**
26997
27039
  * if true, the object is a Polygon
26998
27040
  * @public
@@ -27016,12 +27058,14 @@ class TMXObject {
27016
27058
  this.setTile(map.tilesets);
27017
27059
  }
27018
27060
  else {
27019
- if (typeof(settings.ellipse) !== "undefined") {
27061
+ if (typeof settings.ellipse !== "undefined") {
27020
27062
  this.isEllipse = true;
27021
- } else if (typeof(settings.polygon) !== "undefined") {
27063
+ } else if (typeof settings.point !== "undefined") {
27064
+ this.isPoint = true;
27065
+ } else if (typeof settings.polygon !== "undefined") {
27022
27066
  this.points = settings.polygon;
27023
27067
  this.isPolygon = true;
27024
- } else if (typeof(settings.polyline) !== "undefined") {
27068
+ } else if (typeof settings.polyline !== "undefined") {
27025
27069
  this.points = settings.polyline;
27026
27070
  this.isPolyLine = true;
27027
27071
  }
@@ -27095,8 +27139,9 @@ class TMXObject {
27095
27139
  this.width,
27096
27140
  this.height
27097
27141
  )).rotate(this.rotation));
27142
+ } else if (this.isPoint === true) {
27143
+ shapes.push(pool.pull("Point", this.x, this.y));
27098
27144
  } else {
27099
-
27100
27145
  // add a polygon
27101
27146
  if (this.isPolygon === true) {
27102
27147
  var _polygon = pool.pull("Polygon", 0, 0, this.points);
@@ -27105,10 +27150,8 @@ class TMXObject {
27105
27150
  throw new Error("collision polygones in Tiled should be defined as Convex");
27106
27151
  }
27107
27152
  shapes.push(_polygon.rotate(this.rotation));
27108
- }
27109
27153
 
27110
- // add a polyline
27111
- else if (this.isPolyLine === true) {
27154
+ } else if (this.isPolyLine === true) {
27112
27155
  var p = this.points;
27113
27156
  var p1, p2;
27114
27157
  var segments = p.length - 1;
@@ -27140,7 +27183,9 @@ class TMXObject {
27140
27183
  // Apply isometric projection
27141
27184
  if (this.orientation === "isometric") {
27142
27185
  for (i = 0; i < shapes.length; i++) {
27143
- shapes[i].toIso();
27186
+ if (typeof shapes[i].toIso === "function") {
27187
+ shapes[i].toIso();
27188
+ }
27144
27189
  }
27145
27190
  }
27146
27191
 
@@ -27202,6 +27247,16 @@ class TMXGroup {
27202
27247
  */
27203
27248
  this.tintcolor = data.tintcolor;
27204
27249
 
27250
+
27251
+ /**
27252
+ * the group class
27253
+ * @public
27254
+ * @type {string}
27255
+ * @name class
27256
+ * @memberof TMXGroup
27257
+ */
27258
+ this.class = data.class;
27259
+
27205
27260
  /**
27206
27261
  * group z order
27207
27262
  * @public
@@ -27463,6 +27518,16 @@ class TMXTileMap {
27463
27518
  */
27464
27519
  this.tiledversion = data.tiledversion;
27465
27520
 
27521
+
27522
+ /**
27523
+ * The map class.
27524
+ * @public
27525
+ * @type {string}
27526
+ * @name TMXTileMap#class
27527
+ */
27528
+ this.class = data.class;
27529
+
27530
+
27466
27531
  // tilesets for this map
27467
27532
  this.tilesets = null;
27468
27533
 
@@ -27800,6 +27865,8 @@ class TMXTileMap {
27800
27865
  obj.anchorPoint.set(0, 0);
27801
27866
  obj.name = settings.name;
27802
27867
  obj.type = settings.type;
27868
+ // for backward compatibility
27869
+ obj.class = settings.class || settings.type;
27803
27870
  obj.id = settings.id;
27804
27871
  obj.body = new Body(obj, shape);
27805
27872
  obj.body.setStatic(true);
@@ -29105,7 +29172,12 @@ class Sprite extends Renderable {
29105
29172
  }
29106
29173
 
29107
29174
  if (typeof (settings.tint) !== "undefined") {
29108
- this.tint.setColor(settings.tint);
29175
+ if (settings.tint instanceof Color) {
29176
+ this.tint.copy(settings.tint);
29177
+ } else {
29178
+ // string (#RGB, #ARGB, #RRGGBB, #AARRGGBB)
29179
+ this.tint.parseCSS(settings.tint);
29180
+ }
29109
29181
  }
29110
29182
 
29111
29183
  // set the sprite name if specified
@@ -30647,10 +30719,10 @@ class WebGLRenderer extends Renderer {
30647
30719
  * @param {number} options.width The width of the canvas without scaling
30648
30720
  * @param {number} options.height The height of the canvas without scaling
30649
30721
  * @param {HTMLCanvasElement} [options.canvas] The html canvas to draw to on screen
30650
- * @param {boolean} [options.doubleBuffering=false] Whether to enable double buffering (not applicable when using the WebGL Renderer)
30651
30722
  * @param {boolean} [options.antiAlias=false] Whether to enable anti-aliasing
30652
30723
  * @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.
30653
- * @param {boolean} [options.transparent=false] Whether to enable transparency on the canvas (performance hit when enabled)
30724
+ * @param {boolean} [options.transparent=false] Whether to enable transparency on the canvas
30725
+ * @param {boolean} [options.premultipliedAlpha=true] in WebGL, whether the renderer will assume that colors have premultiplied alpha when canvas transparency is enabled
30654
30726
  * @param {boolean} [options.subPixel=false] Whether to enable subpixel renderering (performance hit when enabled)
30655
30727
  * @param {boolean} [options.preferWebGL1=false] if true the renderer will only use WebGL 1
30656
30728
  * @param {string} [options.powerPreference="default"] a hint to the user agent indicating what configuration of GPU is suitable for the WebGL context ("default", "high-performance", "low-power"). To be noted that Safari and Chrome (since version 80) both default to "low-power" to save battery life and improve the user experience on these dual-GPU machines.
@@ -30665,8 +30737,6 @@ class WebGLRenderer extends Renderer {
30665
30737
 
30666
30738
  /**
30667
30739
  * The WebGL version used by this renderer (1 or 2)
30668
- * @name WebGLVersion
30669
- * @memberof WebGLRenderer#
30670
30740
  * @type {number}
30671
30741
  * @default 1
30672
30742
  * @readonly
@@ -30675,8 +30745,6 @@ class WebGLRenderer extends Renderer {
30675
30745
 
30676
30746
  /**
30677
30747
  * The vendor string of the underlying graphics driver.
30678
- * @name GPUVendor
30679
- * @memberof WebGLRenderer#
30680
30748
  * @type {string}
30681
30749
  * @default null
30682
30750
  * @readonly
@@ -30685,8 +30753,6 @@ class WebGLRenderer extends Renderer {
30685
30753
 
30686
30754
  /**
30687
30755
  * The renderer string of the underlying graphics driver.
30688
- * @name GPURenderer
30689
- * @memberof WebGLRenderer#
30690
30756
  * @type {string}
30691
30757
  * @default null
30692
30758
  * @readonly
@@ -30696,15 +30762,12 @@ class WebGLRenderer extends Renderer {
30696
30762
  /**
30697
30763
  * The WebGL context
30698
30764
  * @name gl
30699
- * @memberof WebGLRenderer
30700
30765
  * @type {WebGLRenderingContext}
30701
30766
  */
30702
- this.context = this.gl = this.getContextGL(this.getScreenCanvas(), options.transparent);
30767
+ this.context = this.gl = this.getContextGL(this.getCanvas(), options.transparent);
30703
30768
 
30704
30769
  /**
30705
30770
  * Maximum number of texture unit supported under the current context
30706
- * @name maxTextures
30707
- * @memberof WebGLRenderer#
30708
30771
  * @type {number}
30709
30772
  * @readonly
30710
30773
  */
@@ -30732,25 +30795,19 @@ class WebGLRenderer extends Renderer {
30732
30795
 
30733
30796
  /**
30734
30797
  * The current transformation matrix used for transformations on the overall scene
30735
- * @name currentTransform
30736
30798
  * @type {Matrix2d}
30737
- * @memberof WebGLRenderer#
30738
30799
  */
30739
30800
  this.currentTransform = new Matrix2d();
30740
30801
 
30741
30802
  /**
30742
30803
  * The current compositor used by the renderer
30743
- * @name currentCompositor
30744
30804
  * @type {WebGLCompositor}
30745
- * @memberof WebGLRenderer#
30746
30805
  */
30747
30806
  this.currentCompositor = null;
30748
30807
 
30749
30808
  /**
30750
30809
  * The list of active compositors
30751
- * @name compositors
30752
30810
  * @type {Map<WebGLCompositor>}
30753
- * @memberof WebGLRenderer#
30754
30811
  */
30755
30812
  this.compositors = new Map();
30756
30813
 
@@ -30781,13 +30838,13 @@ class WebGLRenderer extends Renderer {
30781
30838
  // to simulate context lost and restore in WebGL:
30782
30839
  // var ctx = me.video.renderer.context.getExtension('WEBGL_lose_context');
30783
30840
  // ctx.loseContext()
30784
- this.getScreenCanvas().addEventListener("webglcontextlost", (e) => {
30841
+ this.getCanvas().addEventListener("webglcontextlost", (e) => {
30785
30842
  e.preventDefault();
30786
30843
  this.isContextValid = false;
30787
30844
  emit(ONCONTEXT_LOST, this);
30788
30845
  }, false );
30789
30846
  // ctx.restoreContext()
30790
- this.getScreenCanvas().addEventListener("webglcontextrestored", () => {
30847
+ this.getCanvas().addEventListener("webglcontextrestored", () => {
30791
30848
  this.reset();
30792
30849
  this.isContextValid = true;
30793
30850
  emit(ONCONTEXT_RESTORED, this);
@@ -30796,8 +30853,6 @@ class WebGLRenderer extends Renderer {
30796
30853
 
30797
30854
  /**
30798
30855
  * Reset context state
30799
- * @name reset
30800
- * @memberof WebGLRenderer
30801
30856
  */
30802
30857
  reset() {
30803
30858
  super.reset();
@@ -30820,9 +30875,7 @@ class WebGLRenderer extends Renderer {
30820
30875
 
30821
30876
  /**
30822
30877
  * set the active compositor for this renderer
30823
- * @name setCompositor
30824
30878
  * @param {WebGLCompositor|string} compositor a compositor name or instance
30825
- * @memberof WebGLRenderer
30826
30879
  */
30827
30880
  setCompositor(compositor = "default") {
30828
30881
 
@@ -30846,8 +30899,6 @@ class WebGLRenderer extends Renderer {
30846
30899
 
30847
30900
  /**
30848
30901
  * Reset the gl transform to identity
30849
- * @name resetTransform
30850
- * @memberof WebGLRenderer
30851
30902
  */
30852
30903
  resetTransform() {
30853
30904
  this.currentTransform.identity();
@@ -30858,7 +30909,7 @@ class WebGLRenderer extends Renderer {
30858
30909
  */
30859
30910
  createFontTexture(cache) {
30860
30911
  if (typeof this.fontTexture === "undefined") {
30861
- var canvas = this.backBufferCanvas;
30912
+ var canvas = this.getCanvas();
30862
30913
  var width = canvas.width;
30863
30914
  var height = canvas.height;
30864
30915
 
@@ -30892,8 +30943,6 @@ class WebGLRenderer extends Renderer {
30892
30943
 
30893
30944
  /**
30894
30945
  * Create a pattern with the specified repetition
30895
- * @name createPattern
30896
- * @memberof WebGLRenderer
30897
30946
  * @param {Image} image Source image
30898
30947
  * @param {string} repeat Define how the pattern should be repeated
30899
30948
  * @returns {TextureAtlas}
@@ -30924,8 +30973,6 @@ class WebGLRenderer extends Renderer {
30924
30973
 
30925
30974
  /**
30926
30975
  * Flush the compositor to the frame buffer
30927
- * @name flush
30928
- * @memberof WebGLRenderer
30929
30976
  */
30930
30977
  flush() {
30931
30978
  this.currentCompositor.flush();
@@ -30933,8 +30980,6 @@ class WebGLRenderer extends Renderer {
30933
30980
 
30934
30981
  /**
30935
30982
  * set/change the current projection matrix (WebGL only)
30936
- * @name setProjection
30937
- * @memberof WebGLRenderer
30938
30983
  * @param {Matrix3d} matrix
30939
30984
  */
30940
30985
  setProjection(matrix) {
@@ -30942,10 +30987,15 @@ class WebGLRenderer extends Renderer {
30942
30987
  this.currentCompositor.setProjection(matrix);
30943
30988
  }
30944
30989
 
30990
+ /**
30991
+ * prepare the framebuffer for drawing a new frame
30992
+ */
30993
+ clear() {
30994
+ this.currentCompositor.clear(this.settings.transparent ? 0.0 : 1.0);
30995
+ }
30996
+
30945
30997
  /**
30946
30998
  * Clears the gl context with the given color.
30947
- * @name clearColor
30948
- * @memberof WebGLRenderer
30949
30999
  * @param {Color|string} [color="#000000"] CSS color.
30950
31000
  * @param {boolean} [opaque=false] Allow transparency [default] or clear the surface completely [true]
30951
31001
  */
@@ -30962,17 +31012,10 @@ class WebGLRenderer extends Renderer {
30962
31012
  }
30963
31013
  // clear gl context with the specified color
30964
31014
  this.currentCompositor.clearColor(glArray[0], glArray[1], glArray[2], (opaque === true) ? 1.0 : glArray[3]);
30965
- this.currentCompositor.clear();
30966
-
30967
- // restore default clear Color black
30968
- this.currentCompositor.clearColor(0.0, 0.0, 0.0, 0.0);
30969
-
30970
31015
  }
30971
31016
 
30972
31017
  /**
30973
31018
  * Erase the pixels in the given rectangular area by setting them to transparent black (rgba(0,0,0,0)).
30974
- * @name clearRect
30975
- * @memberof WebGLRenderer
30976
31019
  * @param {number} x x axis of the coordinate for the rectangle starting point.
30977
31020
  * @param {number} y y axis of the coordinate for the rectangle starting point.
30978
31021
  * @param {number} width The rectangle's width.
@@ -31006,7 +31049,7 @@ class WebGLRenderer extends Renderer {
31006
31049
  uvs[1],
31007
31050
  uvs[2],
31008
31051
  uvs[3],
31009
- this.currentTint.toUint32()
31052
+ this.currentTint.toUint32(this.getGlobalAlpha())
31010
31053
  );
31011
31054
 
31012
31055
  // Clear font context2D
@@ -31020,8 +31063,6 @@ class WebGLRenderer extends Renderer {
31020
31063
 
31021
31064
  /**
31022
31065
  * Draw an image to the gl context
31023
- * @name drawImage
31024
- * @memberof WebGLRenderer
31025
31066
  * @param {Image} image An element to draw into the context. The specification permits any canvas image source (CanvasImageSource), specifically, a CSSImageValue, an HTMLImageElement, an SVGImageElement, an HTMLVideoElement, an HTMLCanvasElement, an ImageBitmap, or an OffscreenCanvas.
31026
31067
  * @param {number} sx The X coordinate of the top left corner of the sub-rectangle of the source image to draw into the destination context.
31027
31068
  * @param {number} sy The Y coordinate of the top left corner of the sub-rectangle of the source image to draw into the destination context.
@@ -31067,13 +31108,11 @@ class WebGLRenderer extends Renderer {
31067
31108
 
31068
31109
  var texture = this.cache.get(image);
31069
31110
  var uvs = texture.getUVs(sx + "," + sy + "," + sw + "," + sh);
31070
- this.currentCompositor.addQuad(texture, dx, dy, dw, dh, uvs[0], uvs[1], uvs[2], uvs[3], this.currentTint.toUint32());
31111
+ this.currentCompositor.addQuad(texture, dx, dy, dw, dh, uvs[0], uvs[1], uvs[2], uvs[3], this.currentTint.toUint32(this.getGlobalAlpha()));
31071
31112
  }
31072
31113
 
31073
31114
  /**
31074
31115
  * Draw a pattern within the given rectangle.
31075
- * @name drawPattern
31076
- * @memberof WebGLRenderer
31077
31116
  * @param {TextureAtlas} pattern Pattern object
31078
31117
  * @param {number} x
31079
31118
  * @param {number} y
@@ -31083,29 +31122,16 @@ class WebGLRenderer extends Renderer {
31083
31122
  */
31084
31123
  drawPattern(pattern, x, y, width, height) {
31085
31124
  var uvs = pattern.getUVs("0,0," + width + "," + height);
31086
- this.currentCompositor.addQuad(pattern, x, y, width, height, uvs[0], uvs[1], uvs[2], uvs[3], this.currentTint.toUint32());
31087
- }
31088
-
31089
-
31090
- /**
31091
- * return a reference to the screen canvas corresponding WebGL Context
31092
- * @name getScreenContext
31093
- * @memberof WebGLRenderer
31094
- * @returns {WebGLRenderingContext}
31095
- */
31096
- getScreenContext() {
31097
- return this.gl;
31125
+ this.currentCompositor.addQuad(pattern, x, y, width, height, uvs[0], uvs[1], uvs[2], uvs[3], this.currentTint.toUint32(this.getGlobalAlpha()));
31098
31126
  }
31099
31127
 
31100
31128
  /**
31101
- * Returns the WebGL Context object of the given Canvas
31102
- * @name getContextGL
31103
- * @memberof WebGLRenderer
31129
+ * Returns the WebGL Context object of the given canvas element
31104
31130
  * @param {HTMLCanvasElement} canvas
31105
- * @param {boolean} [transparent=true] use false to disable transparency
31131
+ * @param {boolean} [transparent=false] use true to enable transparency
31106
31132
  * @returns {WebGLRenderingContext}
31107
31133
  */
31108
- getContextGL(canvas, transparent) {
31134
+ getContextGL(canvas, transparent = false) {
31109
31135
  if (typeof canvas === "undefined" || canvas === null) {
31110
31136
  throw new Error(
31111
31137
  "You must pass a canvas element in order to create " +
@@ -31113,17 +31139,13 @@ class WebGLRenderer extends Renderer {
31113
31139
  );
31114
31140
  }
31115
31141
 
31116
- if (typeof transparent !== "boolean") {
31117
- transparent = true;
31118
- }
31119
-
31120
31142
  var attr = {
31121
31143
  alpha : transparent,
31122
31144
  antialias : this.settings.antiAlias,
31123
31145
  depth : false,
31124
31146
  stencil: true,
31125
31147
  preserveDrawingBuffer : false,
31126
- premultipliedAlpha: transparent,
31148
+ premultipliedAlpha: transparent ? this.settings.premultipliedAlpha : false,
31127
31149
  powerPreference: this.settings.powerPreference,
31128
31150
  failIfMajorPerformanceCaveat : this.settings.failIfMajorPerformanceCaveat
31129
31151
  };
@@ -31156,8 +31178,6 @@ class WebGLRenderer extends Renderer {
31156
31178
  /**
31157
31179
  * Returns the WebGLContext instance for the renderer
31158
31180
  * return a reference to the system 2d Context
31159
- * @name getContext
31160
- * @memberof WebGLRenderer
31161
31181
  * @returns {WebGLRenderingContext}
31162
31182
  */
31163
31183
  getContext() {
@@ -31175,9 +31195,7 @@ class WebGLRenderer extends Renderer {
31175
31195
  * <img src="images/lighter-blendmode.png" width="510"/> <br>
31176
31196
  * - "screen" : The pixels are inverted, multiplied, and inverted again. A lighter picture is the result (opposite of multiply) <br>
31177
31197
  * <img src="images/screen-blendmode.png" width="510"/> <br>
31178
- * @name setBlendMode
31179
31198
  * @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/globalCompositeOperation
31180
- * @memberof WebGLRenderer
31181
31199
  * @param {string} [mode="normal"] blend mode : "normal", "multiply", "lighter", "additive", "screen"
31182
31200
  * @param {WebGLRenderingContext} [gl]
31183
31201
  */
@@ -31226,8 +31244,6 @@ class WebGLRenderer extends Renderer {
31226
31244
 
31227
31245
  /**
31228
31246
  * restores the canvas context
31229
- * @name restore
31230
- * @memberof WebGLRenderer
31231
31247
  */
31232
31248
  restore() {
31233
31249
  // do nothing if there is no saved states
@@ -31254,15 +31270,13 @@ class WebGLRenderer extends Renderer {
31254
31270
  this.gl.disable(this.gl.SCISSOR_TEST);
31255
31271
  this.currentScissor[0] = 0;
31256
31272
  this.currentScissor[1] = 0;
31257
- this.currentScissor[2] = this.backBufferCanvas.width;
31258
- this.currentScissor[3] = this.backBufferCanvas.height;
31273
+ this.currentScissor[2] = this.getCanvas().width;
31274
+ this.currentScissor[3] = this.getCanvas().height;
31259
31275
  }
31260
31276
  }
31261
31277
 
31262
31278
  /**
31263
31279
  * saves the canvas context
31264
- * @name save
31265
- * @memberof WebGLRenderer
31266
31280
  */
31267
31281
  save() {
31268
31282
  this._colorStack.push(this.currentColor.clone());
@@ -31278,8 +31292,6 @@ class WebGLRenderer extends Renderer {
31278
31292
 
31279
31293
  /**
31280
31294
  * rotates the uniform matrix
31281
- * @name rotate
31282
- * @memberof WebGLRenderer
31283
31295
  * @param {number} angle in radians
31284
31296
  */
31285
31297
  rotate(angle) {
@@ -31288,8 +31300,6 @@ class WebGLRenderer extends Renderer {
31288
31300
 
31289
31301
  /**
31290
31302
  * scales the uniform matrix
31291
- * @name scale
31292
- * @memberof WebGLRenderer
31293
31303
  * @param {number} x
31294
31304
  * @param {number} y
31295
31305
  */
@@ -31308,8 +31318,6 @@ class WebGLRenderer extends Renderer {
31308
31318
 
31309
31319
  /**
31310
31320
  * Set the global alpha
31311
- * @name setGlobalAlpha
31312
- * @memberof WebGLRenderer
31313
31321
  * @param {number} alpha 0.0 to 1.0 values accepted.
31314
31322
  */
31315
31323
  setGlobalAlpha(alpha) {
@@ -31318,8 +31326,6 @@ class WebGLRenderer extends Renderer {
31318
31326
 
31319
31327
  /**
31320
31328
  * Return the global alpha
31321
- * @name getGlobalAlpha
31322
- * @memberof WebGLRenderer
31323
31329
  * @returns {number} global alpha value
31324
31330
  */
31325
31331
  getGlobalAlpha() {
@@ -31329,8 +31335,6 @@ class WebGLRenderer extends Renderer {
31329
31335
  /**
31330
31336
  * Set the current fill & stroke style color.
31331
31337
  * By default, or upon reset, the value is set to #000000.
31332
- * @name setColor
31333
- * @memberof WebGLRenderer
31334
31338
  * @param {Color|string} color css color string.
31335
31339
  */
31336
31340
  setColor(color) {
@@ -31341,18 +31345,14 @@ class WebGLRenderer extends Renderer {
31341
31345
 
31342
31346
  /**
31343
31347
  * Set the line width
31344
- * @name setLineWidth
31345
- * @memberof WebGLRenderer
31346
31348
  * @param {number} width Line width
31347
31349
  */
31348
31350
  setLineWidth(width) {
31349
- this.getScreenContext().lineWidth(width);
31351
+ this.getContext().lineWidth(width);
31350
31352
  }
31351
31353
 
31352
31354
  /**
31353
31355
  * Stroke an arc at the specified coordinates with given radius, start and end points
31354
- * @name strokeArc
31355
- * @memberof WebGLRenderer
31356
31356
  * @param {number} x arc center point x-axis
31357
31357
  * @param {number} y arc center point y-axis
31358
31358
  * @param {number} radius
@@ -31378,8 +31378,6 @@ class WebGLRenderer extends Renderer {
31378
31378
 
31379
31379
  /**
31380
31380
  * Fill an arc at the specified coordinates with given radius, start and end points
31381
- * @name fillArc
31382
- * @memberof WebGLRenderer
31383
31381
  * @param {number} x arc center point x-axis
31384
31382
  * @param {number} y arc center point y-axis
31385
31383
  * @param {number} radius
@@ -31393,8 +31391,6 @@ class WebGLRenderer extends Renderer {
31393
31391
 
31394
31392
  /**
31395
31393
  * Stroke an ellipse at the specified coordinates with given radius
31396
- * @name strokeEllipse
31397
- * @memberof WebGLRenderer
31398
31394
  * @param {number} x ellipse center point x-axis
31399
31395
  * @param {number} y ellipse center point y-axis
31400
31396
  * @param {number} w horizontal radius of the ellipse
@@ -31418,8 +31414,6 @@ class WebGLRenderer extends Renderer {
31418
31414
 
31419
31415
  /**
31420
31416
  * Fill an ellipse at the specified coordinates with given radius
31421
- * @name fillEllipse
31422
- * @memberof WebGLRenderer
31423
31417
  * @param {number} x ellipse center point x-axis
31424
31418
  * @param {number} y ellipse center point y-axis
31425
31419
  * @param {number} w horizontal radius of the ellipse
@@ -31431,8 +31425,6 @@ class WebGLRenderer extends Renderer {
31431
31425
 
31432
31426
  /**
31433
31427
  * Stroke a line of the given two points
31434
- * @name strokeLine
31435
- * @memberof WebGLRenderer
31436
31428
  * @param {number} startX the start x coordinate
31437
31429
  * @param {number} startY the start y coordinate
31438
31430
  * @param {number} endX the end x coordinate
@@ -31452,8 +31444,6 @@ class WebGLRenderer extends Renderer {
31452
31444
 
31453
31445
  /**
31454
31446
  * Fill a line of the given two points
31455
- * @name fillLine
31456
- * @memberof WebGLRenderer
31457
31447
  * @param {number} startX the start x coordinate
31458
31448
  * @param {number} startY the start y coordinate
31459
31449
  * @param {number} endX the end x coordinate
@@ -31465,8 +31455,6 @@ class WebGLRenderer extends Renderer {
31465
31455
 
31466
31456
  /**
31467
31457
  * Stroke a me.Polygon on the screen with a specified color
31468
- * @name strokePolygon
31469
- * @memberof WebGLRenderer
31470
31458
  * @param {Polygon} poly the shape to draw
31471
31459
  * @param {boolean} [fill=false] also fill the shape with the current color if true
31472
31460
  */
@@ -31496,8 +31484,6 @@ class WebGLRenderer extends Renderer {
31496
31484
 
31497
31485
  /**
31498
31486
  * Fill a me.Polygon on the screen
31499
- * @name fillPolygon
31500
- * @memberof WebGLRenderer
31501
31487
  * @param {Polygon} poly the shape to draw
31502
31488
  */
31503
31489
  fillPolygon(poly) {
@@ -31506,8 +31492,6 @@ class WebGLRenderer extends Renderer {
31506
31492
 
31507
31493
  /**
31508
31494
  * Draw a stroke rectangle at the specified coordinates
31509
- * @name strokeRect
31510
- * @memberof WebGLRenderer
31511
31495
  * @param {number} x
31512
31496
  * @param {number} y
31513
31497
  * @param {number} width
@@ -31530,8 +31514,6 @@ class WebGLRenderer extends Renderer {
31530
31514
 
31531
31515
  /**
31532
31516
  * Draw a filled rectangle at the specified coordinates
31533
- * @name fillRect
31534
- * @memberof WebGLRenderer
31535
31517
  * @param {number} x
31536
31518
  * @param {number} y
31537
31519
  * @param {number} width
@@ -31543,8 +31525,6 @@ class WebGLRenderer extends Renderer {
31543
31525
 
31544
31526
  /**
31545
31527
  * Stroke a rounded rectangle at the specified coordinates
31546
- * @name strokeRoundRect
31547
- * @memberof WebGLRenderer
31548
31528
  * @param {number} x
31549
31529
  * @param {number} y
31550
31530
  * @param {number} width
@@ -31569,8 +31549,6 @@ class WebGLRenderer extends Renderer {
31569
31549
 
31570
31550
  /**
31571
31551
  * Draw a rounded filled rectangle at the specified coordinates
31572
- * @name fillRoundRect
31573
- * @memberof WebGLRenderer
31574
31552
  * @param {number} x
31575
31553
  * @param {number} y
31576
31554
  * @param {number} width
@@ -31581,11 +31559,29 @@ class WebGLRenderer extends Renderer {
31581
31559
  this.strokeRoundRect(x, y, width, height, radius, true);
31582
31560
  }
31583
31561
 
31562
+ /**
31563
+ * Stroke a Point at the specified coordinates
31564
+ * @param {number} x
31565
+ * @param {number} y
31566
+ */
31567
+ strokePoint(x, y) {
31568
+ this.strokeLine(x, y, x + 1, y + 1);
31569
+ }
31570
+
31571
+ /**
31572
+ * Draw a a point at the specified coordinates
31573
+ * @param {number} x
31574
+ * @param {number} y
31575
+ * @param {number} width
31576
+ * @param {number} height
31577
+ */
31578
+ fillPoint(x, y) {
31579
+ this.strokePoint(x, y);
31580
+ }
31581
+
31584
31582
  /**
31585
31583
  * Reset (overrides) the renderer transformation matrix to the
31586
31584
  * identity one, and then apply the given transformation matrix.
31587
- * @name setTransform
31588
- * @memberof WebGLRenderer
31589
31585
  * @param {Matrix2d} mat2d Matrix to transform by
31590
31586
  */
31591
31587
  setTransform(mat2d) {
@@ -31595,8 +31591,6 @@ class WebGLRenderer extends Renderer {
31595
31591
 
31596
31592
  /**
31597
31593
  * Multiply given matrix into the renderer tranformation matrix
31598
- * @name transform
31599
- * @memberof WebGLRenderer
31600
31594
  * @param {Matrix2d} mat2d Matrix to transform by
31601
31595
  */
31602
31596
  transform(mat2d) {
@@ -31612,8 +31606,6 @@ class WebGLRenderer extends Renderer {
31612
31606
 
31613
31607
  /**
31614
31608
  * Translates the uniform matrix by the given coordinates
31615
- * @name translate
31616
- * @memberof WebGLRenderer
31617
31609
  * @param {number} x
31618
31610
  * @param {number} y
31619
31611
  */
@@ -31634,15 +31626,13 @@ class WebGLRenderer extends Renderer {
31634
31626
  * You can however save the current region using the save(),
31635
31627
  * and restore it (with the restore() method) any time in the future.
31636
31628
  * (<u>this is an experimental feature !</u>)
31637
- * @name clipRect
31638
- * @memberof WebGLRenderer
31639
31629
  * @param {number} x
31640
31630
  * @param {number} y
31641
31631
  * @param {number} width
31642
31632
  * @param {number} height
31643
31633
  */
31644
31634
  clipRect(x, y, width, height) {
31645
- var canvas = this.backBufferCanvas;
31635
+ var canvas = this.getCanvas();
31646
31636
  var gl = this.gl;
31647
31637
  // if requested box is different from the current canvas size
31648
31638
  if (x !== 0 || y !== 0 || width !== canvas.width || height !== canvas.height) {
@@ -31681,8 +31671,6 @@ class WebGLRenderer extends Renderer {
31681
31671
  * A mask limits rendering elements to the shape and position of the given mask object.
31682
31672
  * So, if the renderable is larger than the mask, only the intersecting part of the renderable will be visible.
31683
31673
  * Mask are not preserved through renderer context save and restore.
31684
- * @name setMask
31685
- * @memberof WebGLRenderer
31686
31674
  * @param {Rect|RoundRect|Polygon|Line|Ellipse} [mask] a shape defining the mask to be applied
31687
31675
  * @param {boolean} [invert=false] either the given shape should define what is visible (default) or the opposite
31688
31676
  */
@@ -31696,8 +31684,6 @@ class WebGLRenderer extends Renderer {
31696
31684
  // Enable and setup GL state to write to stencil buffer
31697
31685
  gl.enable(gl.STENCIL_TEST);
31698
31686
  gl.clear(gl.STENCIL_BUFFER_BIT);
31699
-
31700
-
31701
31687
  }
31702
31688
 
31703
31689
  this.maskLevel++;
@@ -31726,9 +31712,7 @@ class WebGLRenderer extends Renderer {
31726
31712
 
31727
31713
  /**
31728
31714
  * disable (remove) the rendering mask set through setMask.
31729
- * @name clearMask
31730
31715
  * @see WebGLRenderer#setMask
31731
- * @memberof WebGLRenderer
31732
31716
  */
31733
31717
  clearMask() {
31734
31718
  if (this.maskLevel > 0) {
@@ -31753,11 +31737,11 @@ var designHeight = 0;
31753
31737
  var settings = {
31754
31738
  parent : undefined,
31755
31739
  renderer : 2, // AUTO
31756
- doubleBuffering : false,
31757
31740
  autoScale : false,
31758
31741
  scale : 1.0,
31759
- scaleMethod : "fit",
31742
+ scaleMethod : "manual",
31760
31743
  transparent : false,
31744
+ premultipliedAlpha: true,
31761
31745
  blendMode : "normal",
31762
31746
  antiAlias : false,
31763
31747
  failIfMajorPerformanceCaveat : true,
@@ -31797,7 +31781,7 @@ function onresize() {
31797
31781
  var canvasMaxHeight = Infinity;
31798
31782
 
31799
31783
  if (globalThis.getComputedStyle) {
31800
- var style = globalThis.getComputedStyle(renderer.getScreenCanvas(), null);
31784
+ var style = globalThis.getComputedStyle(renderer.getCanvas(), null);
31801
31785
  canvasMaxWidth = parseInt(style.maxWidth, 10) || Infinity;
31802
31786
  canvasMaxHeight = parseInt(style.maxHeight, 10) || Infinity;
31803
31787
  }
@@ -31851,6 +31835,9 @@ function onresize() {
31851
31835
 
31852
31836
  // adjust scaling ratio based on the new scaling ratio
31853
31837
  scale(scaleX, scaleY);
31838
+ } else {
31839
+ // adjust scaling ratio based on the given settings
31840
+ scale(settings.scale, settings.scale);
31854
31841
  }
31855
31842
  }
31856
31843
  /**
@@ -31927,7 +31914,6 @@ let renderer = null;
31927
31914
  * @param {object} [options] The optional video/renderer parameters.<br> (see Renderer(s) documentation for further specific options)
31928
31915
  * @param {string|HTMLElement} [options.parent=document.body] the DOM parent element to hold the canvas in the HTML file
31929
31916
  * @param {number} [options.renderer=video.AUTO] renderer to use (me.video.CANVAS, me.video.WEBGL, me.video.AUTO)
31930
- * @param {boolean} [options.doubleBuffering=false] enable/disable double buffering
31931
31917
  * @param {number|string} [options.scale=1.0] enable scaling of the canvas ('auto' for automatic scaling)
31932
31918
  * @param {string} [options.scaleMethod="fit"] screen scaling modes ('fit','fill-min','fill-max','flex','flex-width','flex-height','stretch')
31933
31919
  * @param {boolean} [options.preferWebGL1=false] if true the renderer will only use WebGL 1
@@ -31942,8 +31928,7 @@ let renderer = null;
31942
31928
  * parent : "screen",
31943
31929
  * renderer : me.video.AUTO,
31944
31930
  * scale : "auto",
31945
- * scaleMethod : "fit",
31946
- * doubleBuffering : true
31931
+ * scaleMethod : "fit"
31947
31932
  * });
31948
31933
  */
31949
31934
  function init(width, height, options) {
@@ -31959,7 +31944,6 @@ function init(width, height, options) {
31959
31944
  // sanitize potential given parameters
31960
31945
  settings.width = width;
31961
31946
  settings.height = height;
31962
- settings.doubleBuffering = !!(settings.doubleBuffering);
31963
31947
  settings.transparent = !!(settings.transparent);
31964
31948
  settings.antiAlias = !!(settings.antiAlias);
31965
31949
  settings.failIfMajorPerformanceCaveat = !!(settings.failIfMajorPerformanceCaveat);
@@ -31979,24 +31963,21 @@ function init(width, height, options) {
31979
31963
  console.log("melonJS 2 (v" + version + ") | http://melonjs.org" );
31980
31964
  }
31981
31965
 
31982
- // override renderer settings if &webgl is defined in the URL
31966
+ // override renderer settings if &webgl or &canvas is defined in the URL
31983
31967
  var uriFragment = utils.getUriFragment();
31984
31968
  if (uriFragment.webgl === true || uriFragment.webgl1 === true || uriFragment.webgl2 === true) {
31985
31969
  settings.renderer = WEBGL;
31986
31970
  if (uriFragment.webgl1 === true) {
31987
31971
  settings.preferWebGL1 = true;
31988
31972
  }
31973
+ } else if (uriFragment.canvas === true) {
31974
+ settings.renderer = CANVAS;
31989
31975
  }
31990
31976
 
31991
31977
  // normalize scale
31992
31978
  settings.scale = (settings.autoScale) ? 1.0 : (+settings.scale || 1.0);
31993
31979
  scaleRatio.set(settings.scale, settings.scale);
31994
31980
 
31995
- // force double buffering if scaling is required
31996
- if (settings.autoScale || (settings.scale !== 1.0)) {
31997
- settings.doubleBuffering = true;
31998
- }
31999
-
32000
31981
  // hold the requested video size ratio
32001
31982
  designRatio = width / height;
32002
31983
  designWidth = width;
@@ -32068,7 +32049,7 @@ function init(width, height, options) {
32068
32049
 
32069
32050
  // add our canvas (default to document.body if settings.parent is undefined)
32070
32051
  parent = getElement(typeof settings.parent !== "undefined" ? settings.parent : document.body);
32071
- parent.appendChild(renderer.getScreenCanvas());
32052
+ parent.appendChild(renderer.getCanvas());
32072
32053
 
32073
32054
  // Mobile browser hacks
32074
32055
  if (platform.isMobile) {
@@ -32162,8 +32143,8 @@ function getParent() {
32162
32143
  * @param {number} y y scaling multiplier
32163
32144
  */
32164
32145
  function scale(x, y) {
32165
- var canvas = renderer.getScreenCanvas();
32166
- var context = renderer.getScreenContext();
32146
+ var canvas = renderer.getCanvas();
32147
+ var context = renderer.getContext();
32167
32148
  var settings = renderer.settings;
32168
32149
  var pixelRatio = devicePixelRatio;
32169
32150
 
@@ -32898,10 +32879,10 @@ class BasePlugin {
32898
32879
  * this can be overridden by the plugin
32899
32880
  * @public
32900
32881
  * @type {string}
32901
- * @default "13.0.0"
32882
+ * @default "13.2.0"
32902
32883
  * @name plugin.Base#version
32903
32884
  */
32904
- this.version = "13.0.0";
32885
+ this.version = "13.2.0";
32905
32886
  }
32906
32887
  }
32907
32888
 
@@ -33913,7 +33894,8 @@ class Tween {
33913
33894
  var defaultAttributes = {
33914
33895
  offscreenCanvas : false,
33915
33896
  willReadFrequently : false,
33916
- antiAlias : false
33897
+ antiAlias : false,
33898
+ context: "2d"
33917
33899
  };
33918
33900
 
33919
33901
  /**
@@ -33923,7 +33905,8 @@ class CanvasTexture {
33923
33905
  /**
33924
33906
  * @param {number} width the desired width of the canvas
33925
33907
  * @param {number} height the desired height of the canvas
33926
- * @param {object} attributes The attributes to create both the canvas and 2d context
33908
+ * @param {object} attributes The attributes to create both the canvas and context
33909
+ * @param {boolean} [attributes.context="2d"] the context type to be created ("2d", "webgl", "webgl2")
33927
33910
  * @param {boolean} [attributes.offscreenCanvas=false] will create an offscreenCanvas if true instead of a standard canvas
33928
33911
  * @param {boolean} [attributes.willReadFrequently=false] Indicates whether or not a lot of read-back operations are planned
33929
33912
  * @param {boolean} [attributes.antiAlias=false] Whether to enable anti-aliasing, use false (default) for a pixelated effect.
@@ -34142,7 +34125,7 @@ class TextMetrics extends Bounds {
34142
34125
  this.width = this.height = 0;
34143
34126
 
34144
34127
  for (var i = 0; i < strings.length; i++) {
34145
- this.width = Math.max(this.lineWidth(strings[i].trimRight(), context), this.width);
34128
+ this.width = Math.max(this.lineWidth(strings[i].trimEnd(), context), this.width);
34146
34129
  this.height += this.lineHeight();
34147
34130
  }
34148
34131
  this.width = Math.ceil(this.width);
@@ -34617,7 +34600,7 @@ class Text extends Renderable {
34617
34600
  setContextStyle(context, this, stroke);
34618
34601
 
34619
34602
  for (var i = 0; i < text.length; i++) {
34620
- var string = text[i].trimRight();
34603
+ var string = text[i].trimEnd();
34621
34604
  // draw the string
34622
34605
  context[stroke ? "strokeText" : "fillText"](string, x, y);
34623
34606
  // add leading space
@@ -34762,12 +34745,7 @@ class BitmapText extends Renderable {
34762
34745
 
34763
34746
  // apply given fillstyle
34764
34747
  if (typeof settings.fillStyle !== "undefined") {
34765
- if (settings.fillStyle instanceof Color) {
34766
- this.fillStyle.setColor(settings.fillStyle);
34767
- } else {
34768
- // string (#RGB, #ARGB, #RRGGBB, #AARRGGBB)
34769
- this.fillStyle.parseCSS(settings.fillStyle);
34770
- }
34748
+ this.fillStyle = settings.fillStyle;
34771
34749
  }
34772
34750
 
34773
34751
  // update anchorPoint if provided
@@ -34840,7 +34818,12 @@ class BitmapText extends Renderable {
34840
34818
  return this.tint;
34841
34819
  }
34842
34820
  set fillStyle(value) {
34843
- this.tint = value;
34821
+ if (value instanceof Color) {
34822
+ this.tint.copy(value);
34823
+ } else {
34824
+ // string (#RGB, #ARGB, #RRGGBB, #AARRGGBB)
34825
+ this.tint.parseCSS(value);
34826
+ }
34844
34827
  }
34845
34828
 
34846
34829
  /**
@@ -34897,7 +34880,7 @@ class BitmapText extends Renderable {
34897
34880
 
34898
34881
  for (var i = 0; i < this._text.length; i++) {
34899
34882
  x = lX;
34900
- var string = this._text[i].trimRight();
34883
+ var string = this._text[i].trimEnd();
34901
34884
  // adjust x pos based on alignment value
34902
34885
  var stringWidth = this.metrics.lineWidth(string);
34903
34886
  switch (this.textAlign) {
@@ -35638,7 +35621,7 @@ class NineSliceSprite extends Sprite {
35638
35621
  this.width = Math.floor(settings.width);
35639
35622
  this.height = Math.floor(settings.height);
35640
35623
 
35641
- // nine slice sprite specific local variables
35624
+ // nine slice sprite specific internal variables
35642
35625
  this.nss_width = this.width;
35643
35626
  this.nss_height = this.height;
35644
35627
 
@@ -35646,6 +35629,32 @@ class NineSliceSprite extends Sprite {
35646
35629
  this.insety = settings.insety;
35647
35630
  }
35648
35631
 
35632
+ /**
35633
+ * width of the NineSliceSprite
35634
+ * @public
35635
+ * @type {number}
35636
+ * @name width
35637
+ */
35638
+ get width() {
35639
+ return super.width;
35640
+ }
35641
+ set width(value) {
35642
+ super.width = this.nss_width = value;
35643
+ }
35644
+
35645
+ /**
35646
+ * height of the NineSliceSprite
35647
+ * @public
35648
+ * @type {number}
35649
+ * @name height
35650
+ */
35651
+ get height() {
35652
+ return super.height;
35653
+ }
35654
+ set height(value) {
35655
+ super.height = this.nss_height = value;
35656
+ }
35657
+
35649
35658
  /**
35650
35659
  * @ignore
35651
35660
  */
@@ -37607,7 +37616,6 @@ Object.defineProperty(Renderer.prototype, "Texture", {
37607
37616
  }
37608
37617
  });
37609
37618
 
37610
-
37611
37619
  /**
37612
37620
  * @classdesc
37613
37621
  * Used to make a game entity draggable
@@ -37646,6 +37654,33 @@ class DroptargetEntity extends DropTarget {
37646
37654
  }
37647
37655
  }
37648
37656
 
37657
+ /**
37658
+ * return a reference to the screen canvas
37659
+ * @name getScreenCanvas
37660
+ * @memberof Renderer
37661
+ * @returns {HTMLCanvasElement}
37662
+ * @deprecated since 13.1.0
37663
+ * @see getCanvas();
37664
+ */
37665
+ Renderer.prototype.getScreenCanvas = function() {
37666
+ warning("getScreenCanvas", "getCanvas", "13.1.0");
37667
+ return this.getCanvas();
37668
+ };
37669
+
37670
+ /**
37671
+ * return a reference to the screen canvas corresponding 2d Context<br>
37672
+ * (will return buffered context if double buffering is enabled, or a reference to the Screen Context)
37673
+ * @name getScreenContext
37674
+ * @memberof Renderer
37675
+ * @returns {CanvasRenderingContext2D}
37676
+ * @deprecated since 13.1.0
37677
+ * @see getContext();
37678
+ */
37679
+ Renderer.prototype.getScreenContext = function() {
37680
+ warning("getScreenContext", "getContext", "13.1.0");
37681
+ return this.getContext();
37682
+ };
37683
+
37649
37684
  // ES5/ES6 polyfills
37650
37685
 
37651
37686
 
@@ -37656,7 +37691,7 @@ class DroptargetEntity extends DropTarget {
37656
37691
  * @name version
37657
37692
  * @type {string}
37658
37693
  */
37659
- const version = "13.0.0";
37694
+ const version = "13.2.0";
37660
37695
 
37661
37696
 
37662
37697
  /**
@@ -37715,6 +37750,7 @@ function boot() {
37715
37750
  pool.register("me.RoundRect", RoundRect, true);
37716
37751
  pool.register("me.Polygon", Polygon, true);
37717
37752
  pool.register("me.Line", Line, true);
37753
+ pool.register("me.Point", Point, true);
37718
37754
  pool.register("me.Ellipse", Ellipse, true);
37719
37755
  pool.register("me.Bounds", Bounds, true);
37720
37756
 
@@ -37744,6 +37780,7 @@ function boot() {
37744
37780
  pool.register("RoundRect", RoundRect, true);
37745
37781
  pool.register("Polygon", Polygon, true);
37746
37782
  pool.register("Line", Line, true);
37783
+ pool.register("Point", Point, true);
37747
37784
  pool.register("Ellipse", Ellipse, true);
37748
37785
  pool.register("Bounds", Bounds, true);
37749
37786
  pool.register("CanvasTexture", CanvasTexture, true);
@@ -37767,4 +37804,4 @@ onReady(function () {
37767
37804
  }
37768
37805
  });
37769
37806
 
37770
- export { BitmapText, BitmapTextData, Body, Bounds, Camera2d, CanvasRenderer, Collectable, Color, ColorLayer, Container, Draggable, DraggableEntity, DropTarget, DroptargetEntity, Ellipse, Entity, GLShader, GUI_Object, ImageLayer, Light2d, Line, math as Math, Matrix2d, Matrix3d, NineSliceSprite, ObservableVector2d, ObservableVector3d, Particle, ParticleEmitter, ParticleEmitterSettings, Pointer, Polygon, QuadTree, Rect, Renderable, Renderer, RoundRect, Sprite, Stage, TMXHexagonalRenderer, TMXIsometricRenderer, TMXLayer, TMXOrthogonalRenderer, TMXRenderer, TMXStaggeredRenderer, TMXTileMap, TMXTileset, TMXTilesetGroup, Text, TextureAtlas, Tile, Trigger, Tween, Vector2d, Vector3d, WebGLCompositor, WebGLRenderer, World, audio, boot, collision, device, event, game, initialized, input, level, loader, plugin, plugins, pool, save, skipAutoInit, state, timer, utils, version, video, warning };
37807
+ export { BitmapText, BitmapTextData, Body, Bounds, Camera2d, CanvasRenderer, Collectable, Color, ColorLayer, Container, Draggable, DraggableEntity, DropTarget, DroptargetEntity, Ellipse, Entity, GLShader, GUI_Object, ImageLayer, Light2d, Line, math as Math, Matrix2d, Matrix3d, NineSliceSprite, ObservableVector2d, ObservableVector3d, Particle, ParticleEmitter, ParticleEmitterSettings, Point, Pointer, Polygon, QuadTree, Rect, Renderable, Renderer, RoundRect, Sprite, Stage, TMXHexagonalRenderer, TMXIsometricRenderer, TMXLayer, TMXOrthogonalRenderer, TMXRenderer, TMXStaggeredRenderer, TMXTileMap, TMXTileset, TMXTilesetGroup, Text, TextureAtlas, Tile, Trigger, Tween, Vector2d, Vector3d, WebGLCompositor, WebGLRenderer, World, audio, boot, collision, device, event, game, initialized, input, level, loader, plugin, plugins, pool, save, skipAutoInit, state, timer, utils, version, video, warning };