melonjs 13.0.0 → 13.1.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.
- package/dist/melonjs.js +360 -188
- package/dist/melonjs.min.js +3 -3
- package/dist/melonjs.module.d.ts +107 -95
- package/dist/melonjs.module.js +358 -192
- package/package.json +7 -7
- package/src/input/pointerevent.js +2 -2
- package/src/lang/deprecated.js +27 -1
- package/src/level/tiled/TMXGroup.js +10 -0
- package/src/level/tiled/TMXLayer.js +9 -0
- package/src/level/tiled/TMXObject.js +13 -2
- package/src/level/tiled/TMXTileMap.js +12 -0
- package/src/level/tiled/TMXTileset.js +8 -0
- package/src/math/color.js +62 -42
- package/src/math/observable_vector2.js +26 -2
- package/src/math/observable_vector3.js +32 -4
- package/src/math/vector2.js +23 -0
- package/src/math/vector3.js +26 -0
- package/src/renderable/nineslicesprite.js +27 -1
- package/src/video/canvas/canvas_renderer.js +27 -63
- package/src/video/renderer.js +22 -29
- package/src/video/texture/canvas_texture.js +4 -2
- package/src/video/video.js +12 -16
- package/src/video/webgl/webgl_compositor.js +2 -2
- package/src/video/webgl/webgl_renderer.js +8 -20
package/dist/melonjs.module.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* melonJS Game Engine - v13.
|
|
2
|
+
* melonJS Game Engine - v13.1.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.
|
|
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.
|
|
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
|
-
|
|
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,8 +2968,6 @@ 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
|
*/
|
|
@@ -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
|
-
*
|
|
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
|
*/
|
|
@@ -6890,8 +6932,8 @@ class WebGLCompositor {
|
|
|
6890
6932
|
// initial viewport size
|
|
6891
6933
|
this.setViewport(
|
|
6892
6934
|
0, 0,
|
|
6893
|
-
this.renderer.
|
|
6894
|
-
this.renderer.
|
|
6935
|
+
this.renderer.getCanvas().width,
|
|
6936
|
+
this.renderer.getCanvas().height
|
|
6895
6937
|
);
|
|
6896
6938
|
|
|
6897
6939
|
// Initialize clear color
|
|
@@ -10086,7 +10128,6 @@ class Renderer {
|
|
|
10086
10128
|
* @param {number} options.width The width of the canvas without scaling
|
|
10087
10129
|
* @param {number} options.height The height of the canvas without scaling
|
|
10088
10130
|
* @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
10131
|
* @param {boolean} [options.antiAlias=false] Whether to enable anti-aliasing, use false (default) for a pixelated effect.
|
|
10091
10132
|
* @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
10133
|
* @param {boolean} [options.transparent=false] Whether to enable transparency on the canvas (performance hit when enabled)
|
|
@@ -10148,13 +10189,9 @@ class Renderer {
|
|
|
10148
10189
|
} else if (typeof this.settings.canvas !== "undefined") {
|
|
10149
10190
|
this.canvas = this.settings.canvas;
|
|
10150
10191
|
} else {
|
|
10151
|
-
this.canvas = createCanvas(this.settings.
|
|
10192
|
+
this.canvas = createCanvas(this.settings.width, this.settings.height);
|
|
10152
10193
|
}
|
|
10153
10194
|
|
|
10154
|
-
// canvas object and context
|
|
10155
|
-
this.backBufferCanvas = this.canvas;
|
|
10156
|
-
this.context = null;
|
|
10157
|
-
|
|
10158
10195
|
// global color
|
|
10159
10196
|
this.currentColor = new Color(0, 0, 0, 1.0);
|
|
10160
10197
|
|
|
@@ -10180,6 +10217,13 @@ class Renderer {
|
|
|
10180
10217
|
*/
|
|
10181
10218
|
clear() {}
|
|
10182
10219
|
|
|
10220
|
+
/**
|
|
10221
|
+
* render the main framebuffer on screen
|
|
10222
|
+
* @name flush
|
|
10223
|
+
* @memberof Renderer
|
|
10224
|
+
*/
|
|
10225
|
+
flush() {}
|
|
10226
|
+
|
|
10183
10227
|
/**
|
|
10184
10228
|
* Reset context state
|
|
10185
10229
|
* @name reset
|
|
@@ -10193,39 +10237,29 @@ class Renderer {
|
|
|
10193
10237
|
this.cache.clear();
|
|
10194
10238
|
this.currentScissor[0] = 0;
|
|
10195
10239
|
this.currentScissor[1] = 0;
|
|
10196
|
-
this.currentScissor[2] = this.
|
|
10197
|
-
this.currentScissor[3] = this.
|
|
10240
|
+
this.currentScissor[2] = this.getCanvas().width;
|
|
10241
|
+
this.currentScissor[3] = this.getCanvas().height;
|
|
10198
10242
|
this.clearMask();
|
|
10199
10243
|
}
|
|
10200
10244
|
|
|
10201
10245
|
/**
|
|
10202
|
-
* return a reference to the
|
|
10246
|
+
* return a reference to the canvas which this renderer draws to
|
|
10203
10247
|
* @name getCanvas
|
|
10204
10248
|
* @memberof Renderer
|
|
10205
10249
|
* @returns {HTMLCanvasElement}
|
|
10206
10250
|
*/
|
|
10207
10251
|
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
10252
|
return this.canvas;
|
|
10219
10253
|
}
|
|
10220
10254
|
|
|
10255
|
+
|
|
10221
10256
|
/**
|
|
10222
|
-
* return a reference to
|
|
10223
|
-
*
|
|
10224
|
-
* @name getScreenContext
|
|
10257
|
+
* return a reference to this renderer canvas corresponding Context
|
|
10258
|
+
* @name getContext
|
|
10225
10259
|
* @memberof Renderer
|
|
10226
|
-
* @returns {CanvasRenderingContext2D}
|
|
10260
|
+
* @returns {CanvasRenderingContext2D|WebGLRenderingContext}
|
|
10227
10261
|
*/
|
|
10228
|
-
|
|
10262
|
+
getContext() {
|
|
10229
10263
|
return this.context;
|
|
10230
10264
|
}
|
|
10231
10265
|
|
|
@@ -10284,7 +10318,7 @@ class Renderer {
|
|
|
10284
10318
|
* @returns {number}
|
|
10285
10319
|
*/
|
|
10286
10320
|
getWidth() {
|
|
10287
|
-
return this.
|
|
10321
|
+
return this.getCanvas().width;
|
|
10288
10322
|
}
|
|
10289
10323
|
|
|
10290
10324
|
/**
|
|
@@ -10294,7 +10328,7 @@ class Renderer {
|
|
|
10294
10328
|
* @returns {number} height of the system Canvas
|
|
10295
10329
|
*/
|
|
10296
10330
|
getHeight() {
|
|
10297
|
-
return this.
|
|
10331
|
+
return this.getCanvas().height;
|
|
10298
10332
|
}
|
|
10299
10333
|
|
|
10300
10334
|
/**
|
|
@@ -10340,9 +10374,10 @@ class Renderer {
|
|
|
10340
10374
|
* @param {number} height new height of the canvas
|
|
10341
10375
|
*/
|
|
10342
10376
|
resize(width, height) {
|
|
10343
|
-
|
|
10344
|
-
|
|
10345
|
-
|
|
10377
|
+
var canvas = this.getCanvas();
|
|
10378
|
+
if (width !== canvas.width || height !== canvas.height) {
|
|
10379
|
+
canvas.width = width;
|
|
10380
|
+
canvas.height = height;
|
|
10346
10381
|
this.currentScissor[0] = 0;
|
|
10347
10382
|
this.currentScissor[1] = 0;
|
|
10348
10383
|
this.currentScissor[2] = width;
|
|
@@ -14660,8 +14695,32 @@ class ObservableVector2d extends Vector2d {
|
|
|
14660
14695
|
* @returns {ObservableVector2d} Reference to this object for method chaining
|
|
14661
14696
|
*/
|
|
14662
14697
|
lerp(v, alpha) {
|
|
14663
|
-
this.
|
|
14664
|
-
|
|
14698
|
+
return this._set(
|
|
14699
|
+
this._x + ( v.x - this._x ) * alpha,
|
|
14700
|
+
this._y + ( v.y - this._y ) * alpha
|
|
14701
|
+
);
|
|
14702
|
+
}
|
|
14703
|
+
|
|
14704
|
+
/**
|
|
14705
|
+
* interpolate the position of this vector towards the given one while nsure that the distance never exceeds the given step.
|
|
14706
|
+
* @name moveTowards
|
|
14707
|
+
* @memberof ObservableVector2d
|
|
14708
|
+
* @param {Vector2d|ObservableVector2d} target
|
|
14709
|
+
* @param {number} step the maximum step per iteration (Negative values will push the vector away from the target)
|
|
14710
|
+
* @returns {ObservableVector2d} Reference to this object for method chaining
|
|
14711
|
+
*/
|
|
14712
|
+
moveTowards(target, step) {
|
|
14713
|
+
var angle = Math.atan2(target.y - this._y, target.x - this._x);
|
|
14714
|
+
|
|
14715
|
+
var distance = this.distance(target);
|
|
14716
|
+
|
|
14717
|
+
if (distance === 0 || (step >= 0 && distance <= step * step)) {
|
|
14718
|
+
return target;
|
|
14719
|
+
}
|
|
14720
|
+
|
|
14721
|
+
this._x += Math.cos(angle) * step;
|
|
14722
|
+
this._y += Math.sin(angle) * step;
|
|
14723
|
+
|
|
14665
14724
|
return this;
|
|
14666
14725
|
}
|
|
14667
14726
|
|
|
@@ -15166,6 +15225,32 @@ class Vector3d {
|
|
|
15166
15225
|
return this;
|
|
15167
15226
|
}
|
|
15168
15227
|
|
|
15228
|
+
/**
|
|
15229
|
+
* interpolate the position of this vector on the x and y axis towards the given one by the given maximum step.
|
|
15230
|
+
* @name moveTowards
|
|
15231
|
+
* @memberof Vector3d
|
|
15232
|
+
* @param {Vector2d|Vector3d} target
|
|
15233
|
+
* @param {number} step the maximum step per iteration (Negative values will push the vector away from the target)
|
|
15234
|
+
* @returns {Vector3d} Reference to this object for method chaining
|
|
15235
|
+
*/
|
|
15236
|
+
moveTowards(target, step) {
|
|
15237
|
+
var angle = Math.atan2(target.y - this.y, target.x - this.x);
|
|
15238
|
+
|
|
15239
|
+
var dx = this.x - target.x;
|
|
15240
|
+
var dy = this.y - target.y;
|
|
15241
|
+
|
|
15242
|
+
var distance = Math.sqrt(dx * dx + dy * dy);
|
|
15243
|
+
|
|
15244
|
+
if (distance === 0 || (step >= 0 && distance <= step * step)) {
|
|
15245
|
+
return target;
|
|
15246
|
+
}
|
|
15247
|
+
|
|
15248
|
+
this.x += Math.cos(angle) * step;
|
|
15249
|
+
this.y += Math.sin(angle) * step;
|
|
15250
|
+
|
|
15251
|
+
return this;
|
|
15252
|
+
}
|
|
15253
|
+
|
|
15169
15254
|
/**
|
|
15170
15255
|
* return the distance between this vector and the passed one
|
|
15171
15256
|
* @name distance
|
|
@@ -15700,10 +15785,38 @@ class ObservableVector3d extends Vector3d {
|
|
|
15700
15785
|
* @returns {ObservableVector3d} Reference to this object for method chaining
|
|
15701
15786
|
*/
|
|
15702
15787
|
lerp(v, alpha) {
|
|
15703
|
-
this.
|
|
15704
|
-
|
|
15705
|
-
|
|
15706
|
-
|
|
15788
|
+
return this._set(
|
|
15789
|
+
this._x + ( v.x - this._x ) * alpha,
|
|
15790
|
+
this._y + ( v.y - this._y ) * alpha,
|
|
15791
|
+
this._z + ( v.z - this._z ) * alpha
|
|
15792
|
+
);
|
|
15793
|
+
}
|
|
15794
|
+
|
|
15795
|
+
/**
|
|
15796
|
+
* 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.
|
|
15797
|
+
* @name moveTowards
|
|
15798
|
+
* @memberof ObservableVector3d
|
|
15799
|
+
* @param {Vector2d|ObservableVector2d|Vector3d|ObservableVector3d} target
|
|
15800
|
+
* @param {number} step the maximum step per iteration (Negative values will push the vector away from the target)
|
|
15801
|
+
* @returns {ObservableVector3d} Reference to this object for method chaining
|
|
15802
|
+
*/
|
|
15803
|
+
moveTowards(target, step) {
|
|
15804
|
+
var angle = Math.atan2(target.y - this._y, target.x - this._x);
|
|
15805
|
+
|
|
15806
|
+
var dx = this._x - target.x;
|
|
15807
|
+
var dy = this._y - target.y;
|
|
15808
|
+
|
|
15809
|
+
var distance = Math.sqrt(dx * dx + dy * dy);
|
|
15810
|
+
|
|
15811
|
+
if (distance === 0 || (step >= 0 && distance <= step * step)) {
|
|
15812
|
+
return target;
|
|
15813
|
+
}
|
|
15814
|
+
|
|
15815
|
+
return this._set(
|
|
15816
|
+
this._x + Math.cos(angle) * step,
|
|
15817
|
+
this._y + Math.sin(angle) * step,
|
|
15818
|
+
this._z
|
|
15819
|
+
);
|
|
15707
15820
|
}
|
|
15708
15821
|
|
|
15709
15822
|
/**
|
|
@@ -16698,7 +16811,7 @@ function enablePointerEvent() {
|
|
|
16698
16811
|
|
|
16699
16812
|
if (pointerEventTarget === null) {
|
|
16700
16813
|
// default pointer event target
|
|
16701
|
-
pointerEventTarget = renderer.
|
|
16814
|
+
pointerEventTarget = renderer.getCanvas();
|
|
16702
16815
|
}
|
|
16703
16816
|
|
|
16704
16817
|
if (pointerEvent) {
|
|
@@ -17129,7 +17242,7 @@ var throttlingInterval;
|
|
|
17129
17242
|
*/
|
|
17130
17243
|
function globalToLocal(x, y, v) {
|
|
17131
17244
|
v = v || pool.pull("Vector2d");
|
|
17132
|
-
var rect = getElementBounds(renderer.
|
|
17245
|
+
var rect = getElementBounds(renderer.getCanvas());
|
|
17133
17246
|
var pixelRatio = globalThis.devicePixelRatio || 1;
|
|
17134
17247
|
x -= rect.left + (globalThis.pageXOffset || 0);
|
|
17135
17248
|
y -= rect.top + (globalThis.pageYOffset || 0);
|
|
@@ -24227,7 +24340,6 @@ class CanvasRenderer extends Renderer {
|
|
|
24227
24340
|
* @param {number} options.width The width of the canvas without scaling
|
|
24228
24341
|
* @param {number} options.height The height of the canvas without scaling
|
|
24229
24342
|
* @param {HTMLCanvasElement} [options.canvas] The html canvas to draw to on screen
|
|
24230
|
-
* @param {boolean} [options.doubleBuffering=false] Whether to enable double buffering
|
|
24231
24343
|
* @param {boolean} [options.antiAlias=false] Whether to enable anti-aliasing
|
|
24232
24344
|
* @param {boolean} [options.transparent=false] Whether to enable transparency on the canvas (performance hit when enabled)
|
|
24233
24345
|
* @param {boolean} [options.subPixel=false] Whether to enable subpixel renderering (performance hit when enabled)
|
|
@@ -24240,17 +24352,7 @@ class CanvasRenderer extends Renderer {
|
|
|
24240
24352
|
super(options);
|
|
24241
24353
|
|
|
24242
24354
|
// defined the 2d context
|
|
24243
|
-
this.context = this.getContext2d(this.
|
|
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
|
-
}
|
|
24355
|
+
this.context = this.getContext2d(this.getCanvas(), this.settings.transparent);
|
|
24254
24356
|
|
|
24255
24357
|
this.setBlendMode(this.settings.blendMode);
|
|
24256
24358
|
|
|
@@ -24266,13 +24368,13 @@ class CanvasRenderer extends Renderer {
|
|
|
24266
24368
|
}
|
|
24267
24369
|
|
|
24268
24370
|
// context lost & restore event for canvas
|
|
24269
|
-
this.
|
|
24371
|
+
this.getCanvas().addEventListener("contextlost", (e) => {
|
|
24270
24372
|
e.preventDefault();
|
|
24271
24373
|
this.isContextValid = false;
|
|
24272
24374
|
emit(ONCONTEXT_LOST, this);
|
|
24273
24375
|
}, false );
|
|
24274
24376
|
// ctx.restoreContext()
|
|
24275
|
-
this.
|
|
24377
|
+
this.getCanvas().addEventListener("contextrestored", () => {
|
|
24276
24378
|
this.isContextValid = true;
|
|
24277
24379
|
emit(ONCONTEXT_RESTORED, this);
|
|
24278
24380
|
}, false );
|
|
@@ -24294,7 +24396,7 @@ class CanvasRenderer extends Renderer {
|
|
|
24294
24396
|
* @memberof CanvasRenderer
|
|
24295
24397
|
*/
|
|
24296
24398
|
resetTransform() {
|
|
24297
|
-
this.
|
|
24399
|
+
this.getContext().setTransform(1, 0, 0, 1, 0, 0);
|
|
24298
24400
|
}
|
|
24299
24401
|
|
|
24300
24402
|
/**
|
|
@@ -24336,12 +24438,6 @@ class CanvasRenderer extends Renderer {
|
|
|
24336
24438
|
this.currentBlendMode = "normal";
|
|
24337
24439
|
break;
|
|
24338
24440
|
}
|
|
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
24441
|
}
|
|
24346
24442
|
|
|
24347
24443
|
/**
|
|
@@ -24355,17 +24451,6 @@ class CanvasRenderer extends Renderer {
|
|
|
24355
24451
|
}
|
|
24356
24452
|
}
|
|
24357
24453
|
|
|
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);
|
|
24366
|
-
}
|
|
24367
|
-
}
|
|
24368
|
-
|
|
24369
24454
|
/**
|
|
24370
24455
|
* Clears the main framebuffer with the given color
|
|
24371
24456
|
* @name clearColor
|
|
@@ -24374,11 +24459,14 @@ class CanvasRenderer extends Renderer {
|
|
|
24374
24459
|
* @param {boolean} [opaque=false] Allow transparency [default] or clear the surface completely [true]
|
|
24375
24460
|
*/
|
|
24376
24461
|
clearColor(color = "#000000", opaque) {
|
|
24462
|
+
var canvas = this.getCanvas();
|
|
24463
|
+
var context = this.getContext();
|
|
24464
|
+
|
|
24377
24465
|
this.save();
|
|
24378
24466
|
this.resetTransform();
|
|
24379
|
-
|
|
24380
|
-
|
|
24381
|
-
this.fillRect(0, 0,
|
|
24467
|
+
context.globalCompositeOperation = opaque ? "copy" : "source-over";
|
|
24468
|
+
context.fillStyle = (color instanceof Color) ? color.toRGBA() : color;
|
|
24469
|
+
this.fillRect(0, 0, canvas.width, canvas.height);
|
|
24382
24470
|
this.restore();
|
|
24383
24471
|
}
|
|
24384
24472
|
|
|
@@ -24738,17 +24826,6 @@ class CanvasRenderer extends Renderer {
|
|
|
24738
24826
|
this.strokeRoundRect(x, y, width, height, radius, true);
|
|
24739
24827
|
}
|
|
24740
24828
|
|
|
24741
|
-
|
|
24742
|
-
/**
|
|
24743
|
-
* return a reference to the system 2d Context
|
|
24744
|
-
* @name getContext
|
|
24745
|
-
* @memberof CanvasRenderer
|
|
24746
|
-
* @returns {CanvasRenderingContext2D}
|
|
24747
|
-
*/
|
|
24748
|
-
getContext() {
|
|
24749
|
-
return this.backBufferContext2D;
|
|
24750
|
-
}
|
|
24751
|
-
|
|
24752
24829
|
/**
|
|
24753
24830
|
* return a reference to the font 2d Context
|
|
24754
24831
|
* @ignore
|
|
@@ -24764,7 +24841,7 @@ class CanvasRenderer extends Renderer {
|
|
|
24764
24841
|
* @memberof CanvasRenderer
|
|
24765
24842
|
*/
|
|
24766
24843
|
save() {
|
|
24767
|
-
this.
|
|
24844
|
+
this.getContext().save();
|
|
24768
24845
|
}
|
|
24769
24846
|
|
|
24770
24847
|
/**
|
|
@@ -24773,12 +24850,12 @@ class CanvasRenderer extends Renderer {
|
|
|
24773
24850
|
* @memberof CanvasRenderer
|
|
24774
24851
|
*/
|
|
24775
24852
|
restore() {
|
|
24776
|
-
this.
|
|
24853
|
+
this.getContext().restore();
|
|
24777
24854
|
this.currentColor.glArray[3] = this.getGlobalAlpha();
|
|
24778
24855
|
this.currentScissor[0] = 0;
|
|
24779
24856
|
this.currentScissor[1] = 0;
|
|
24780
|
-
this.currentScissor[2] = this.
|
|
24781
|
-
this.currentScissor[3] = this.
|
|
24857
|
+
this.currentScissor[2] = this.getCanvas().width;
|
|
24858
|
+
this.currentScissor[3] = this.getCanvas().height;
|
|
24782
24859
|
}
|
|
24783
24860
|
|
|
24784
24861
|
/**
|
|
@@ -24788,7 +24865,7 @@ class CanvasRenderer extends Renderer {
|
|
|
24788
24865
|
* @param {number} angle in radians
|
|
24789
24866
|
*/
|
|
24790
24867
|
rotate(angle) {
|
|
24791
|
-
this.
|
|
24868
|
+
this.getContext().rotate(angle);
|
|
24792
24869
|
}
|
|
24793
24870
|
|
|
24794
24871
|
/**
|
|
@@ -24799,7 +24876,7 @@ class CanvasRenderer extends Renderer {
|
|
|
24799
24876
|
* @param {number} y
|
|
24800
24877
|
*/
|
|
24801
24878
|
scale(x, y) {
|
|
24802
|
-
this.
|
|
24879
|
+
this.getContext().scale(x, y);
|
|
24803
24880
|
}
|
|
24804
24881
|
|
|
24805
24882
|
/**
|
|
@@ -24810,8 +24887,9 @@ class CanvasRenderer extends Renderer {
|
|
|
24810
24887
|
* @param {Color|string} color css color value
|
|
24811
24888
|
*/
|
|
24812
24889
|
setColor(color) {
|
|
24813
|
-
this.
|
|
24814
|
-
|
|
24890
|
+
var context = this.getContext();
|
|
24891
|
+
context.strokeStyle =
|
|
24892
|
+
context.fillStyle = (
|
|
24815
24893
|
color instanceof Color ?
|
|
24816
24894
|
color.toRGBA() :
|
|
24817
24895
|
color
|
|
@@ -24825,7 +24903,7 @@ class CanvasRenderer extends Renderer {
|
|
|
24825
24903
|
* @param {number} alpha 0.0 to 1.0 values accepted.
|
|
24826
24904
|
*/
|
|
24827
24905
|
setGlobalAlpha(alpha) {
|
|
24828
|
-
this.
|
|
24906
|
+
this.getContext().globalAlpha = this.currentColor.glArray[3] = alpha;
|
|
24829
24907
|
}
|
|
24830
24908
|
|
|
24831
24909
|
/**
|
|
@@ -24835,7 +24913,7 @@ class CanvasRenderer extends Renderer {
|
|
|
24835
24913
|
* @returns {number} global alpha value
|
|
24836
24914
|
*/
|
|
24837
24915
|
getGlobalAlpha() {
|
|
24838
|
-
return this.
|
|
24916
|
+
return this.getContext().globalAlpha;
|
|
24839
24917
|
}
|
|
24840
24918
|
|
|
24841
24919
|
/**
|
|
@@ -24845,7 +24923,7 @@ class CanvasRenderer extends Renderer {
|
|
|
24845
24923
|
* @param {number} width Line width
|
|
24846
24924
|
*/
|
|
24847
24925
|
setLineWidth(width) {
|
|
24848
|
-
this.
|
|
24926
|
+
this.getContext().lineWidth = width;
|
|
24849
24927
|
}
|
|
24850
24928
|
|
|
24851
24929
|
/**
|
|
@@ -24880,7 +24958,7 @@ class CanvasRenderer extends Renderer {
|
|
|
24880
24958
|
f |= 0;
|
|
24881
24959
|
}
|
|
24882
24960
|
|
|
24883
|
-
this.
|
|
24961
|
+
this.getContext().transform(a, b, c, d, e, f);
|
|
24884
24962
|
}
|
|
24885
24963
|
|
|
24886
24964
|
/**
|
|
@@ -24892,9 +24970,9 @@ class CanvasRenderer extends Renderer {
|
|
|
24892
24970
|
*/
|
|
24893
24971
|
translate(x, y) {
|
|
24894
24972
|
if (this.settings.subPixel === false) {
|
|
24895
|
-
this.
|
|
24973
|
+
this.getContext().translate(~~x, ~~y);
|
|
24896
24974
|
} else {
|
|
24897
|
-
this.
|
|
24975
|
+
this.getContext().translate(x, y);
|
|
24898
24976
|
}
|
|
24899
24977
|
}
|
|
24900
24978
|
|
|
@@ -24912,14 +24990,14 @@ class CanvasRenderer extends Renderer {
|
|
|
24912
24990
|
* @param {number} height
|
|
24913
24991
|
*/
|
|
24914
24992
|
clipRect(x, y, width, height) {
|
|
24915
|
-
var canvas = this.
|
|
24993
|
+
var canvas = this.getCanvas();
|
|
24916
24994
|
// if requested box is different from the current canvas size;
|
|
24917
24995
|
if (x !== 0 || y !== 0 || width !== canvas.width || height !== canvas.height) {
|
|
24918
24996
|
var currentScissor = this.currentScissor;
|
|
24919
24997
|
// if different from the current scissor box
|
|
24920
24998
|
if (currentScissor[0] !== x || currentScissor[1] !== y ||
|
|
24921
24999
|
currentScissor[2] !== width || currentScissor[3] !== height) {
|
|
24922
|
-
var context = this.
|
|
25000
|
+
var context = this.getContext();
|
|
24923
25001
|
context.beginPath();
|
|
24924
25002
|
context.rect(x, y, width, height);
|
|
24925
25003
|
context.clip();
|
|
@@ -25145,6 +25223,15 @@ class TMXLayer extends Renderable {
|
|
|
25145
25223
|
*/
|
|
25146
25224
|
this.renderorder = data.renderorder || "right-down";
|
|
25147
25225
|
|
|
25226
|
+
/**
|
|
25227
|
+
* the layer class
|
|
25228
|
+
* @public
|
|
25229
|
+
* @type {string}
|
|
25230
|
+
* @name class
|
|
25231
|
+
* @name TMXLayer#class
|
|
25232
|
+
*/
|
|
25233
|
+
this.class = data.class;
|
|
25234
|
+
|
|
25148
25235
|
// for displaying order
|
|
25149
25236
|
this.pos.z = z;
|
|
25150
25237
|
|
|
@@ -26535,6 +26622,14 @@ class TMXTileset {
|
|
|
26535
26622
|
*/
|
|
26536
26623
|
this.isCollection = false;
|
|
26537
26624
|
|
|
26625
|
+
/**
|
|
26626
|
+
* the tileset class
|
|
26627
|
+
* @public
|
|
26628
|
+
* @type {boolean}
|
|
26629
|
+
* @name TMXTileset#class
|
|
26630
|
+
*/
|
|
26631
|
+
this.class = tileset.class;
|
|
26632
|
+
|
|
26538
26633
|
/**
|
|
26539
26634
|
* Tileset animations
|
|
26540
26635
|
* @private
|
|
@@ -26933,20 +27028,31 @@ class TMXObject {
|
|
|
26933
27028
|
* object type
|
|
26934
27029
|
* @public
|
|
26935
27030
|
* @type {string}
|
|
27031
|
+
* @deprecated since Tiled 1.9
|
|
27032
|
+
* @see https://docs.mapeditor.org/en/stable/reference/tmx-changelog/#tiled-1-9
|
|
26936
27033
|
* @name type
|
|
26937
27034
|
* @memberof TMXObject
|
|
26938
27035
|
*/
|
|
26939
27036
|
this.type = settings.type;
|
|
26940
27037
|
|
|
27038
|
+
/**
|
|
27039
|
+
* the åobject class
|
|
27040
|
+
* @public
|
|
27041
|
+
* @type {string}
|
|
27042
|
+
* @name class
|
|
27043
|
+
* @memberof TMXObject
|
|
27044
|
+
*/
|
|
27045
|
+
this.class = typeof settings.class !== "undefined" ? settings.class : settings.type;
|
|
27046
|
+
|
|
26941
27047
|
/**
|
|
26942
27048
|
* object text
|
|
26943
27049
|
* @public
|
|
26944
27050
|
* @type {object}
|
|
26945
27051
|
* @see http://docs.mapeditor.org/en/stable/reference/tmx-map-format/#text
|
|
26946
|
-
* @name
|
|
27052
|
+
* @name text
|
|
26947
27053
|
* @memberof TMXObject
|
|
26948
27054
|
*/
|
|
26949
|
-
this.
|
|
27055
|
+
this.text = undefined;
|
|
26950
27056
|
|
|
26951
27057
|
/**
|
|
26952
27058
|
* The rotation of the object in radians clockwise (defaults to 0)
|
|
@@ -27202,6 +27308,16 @@ class TMXGroup {
|
|
|
27202
27308
|
*/
|
|
27203
27309
|
this.tintcolor = data.tintcolor;
|
|
27204
27310
|
|
|
27311
|
+
|
|
27312
|
+
/**
|
|
27313
|
+
* the group class
|
|
27314
|
+
* @public
|
|
27315
|
+
* @type {string}
|
|
27316
|
+
* @name class
|
|
27317
|
+
* @memberof TMXGroup
|
|
27318
|
+
*/
|
|
27319
|
+
this.class = data.class;
|
|
27320
|
+
|
|
27205
27321
|
/**
|
|
27206
27322
|
* group z order
|
|
27207
27323
|
* @public
|
|
@@ -27463,6 +27579,16 @@ class TMXTileMap {
|
|
|
27463
27579
|
*/
|
|
27464
27580
|
this.tiledversion = data.tiledversion;
|
|
27465
27581
|
|
|
27582
|
+
|
|
27583
|
+
/**
|
|
27584
|
+
* The map class.
|
|
27585
|
+
* @public
|
|
27586
|
+
* @type {string}
|
|
27587
|
+
* @name TMXTileMap#class
|
|
27588
|
+
*/
|
|
27589
|
+
this.class = data.class;
|
|
27590
|
+
|
|
27591
|
+
|
|
27466
27592
|
// tilesets for this map
|
|
27467
27593
|
this.tilesets = null;
|
|
27468
27594
|
|
|
@@ -27800,6 +27926,8 @@ class TMXTileMap {
|
|
|
27800
27926
|
obj.anchorPoint.set(0, 0);
|
|
27801
27927
|
obj.name = settings.name;
|
|
27802
27928
|
obj.type = settings.type;
|
|
27929
|
+
// for backward compatibility
|
|
27930
|
+
obj.class = settings.class || settings.type;
|
|
27803
27931
|
obj.id = settings.id;
|
|
27804
27932
|
obj.body = new Body(obj, shape);
|
|
27805
27933
|
obj.body.setStatic(true);
|
|
@@ -30647,7 +30775,6 @@ class WebGLRenderer extends Renderer {
|
|
|
30647
30775
|
* @param {number} options.width The width of the canvas without scaling
|
|
30648
30776
|
* @param {number} options.height The height of the canvas without scaling
|
|
30649
30777
|
* @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
30778
|
* @param {boolean} [options.antiAlias=false] Whether to enable anti-aliasing
|
|
30652
30779
|
* @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
30780
|
* @param {boolean} [options.transparent=false] Whether to enable transparency on the canvas (performance hit when enabled)
|
|
@@ -30699,7 +30826,7 @@ class WebGLRenderer extends Renderer {
|
|
|
30699
30826
|
* @memberof WebGLRenderer
|
|
30700
30827
|
* @type {WebGLRenderingContext}
|
|
30701
30828
|
*/
|
|
30702
|
-
this.context = this.gl = this.getContextGL(this.
|
|
30829
|
+
this.context = this.gl = this.getContextGL(this.getCanvas(), options.transparent);
|
|
30703
30830
|
|
|
30704
30831
|
/**
|
|
30705
30832
|
* Maximum number of texture unit supported under the current context
|
|
@@ -30781,13 +30908,13 @@ class WebGLRenderer extends Renderer {
|
|
|
30781
30908
|
// to simulate context lost and restore in WebGL:
|
|
30782
30909
|
// var ctx = me.video.renderer.context.getExtension('WEBGL_lose_context');
|
|
30783
30910
|
// ctx.loseContext()
|
|
30784
|
-
this.
|
|
30911
|
+
this.getCanvas().addEventListener("webglcontextlost", (e) => {
|
|
30785
30912
|
e.preventDefault();
|
|
30786
30913
|
this.isContextValid = false;
|
|
30787
30914
|
emit(ONCONTEXT_LOST, this);
|
|
30788
30915
|
}, false );
|
|
30789
30916
|
// ctx.restoreContext()
|
|
30790
|
-
this.
|
|
30917
|
+
this.getCanvas().addEventListener("webglcontextrestored", () => {
|
|
30791
30918
|
this.reset();
|
|
30792
30919
|
this.isContextValid = true;
|
|
30793
30920
|
emit(ONCONTEXT_RESTORED, this);
|
|
@@ -30858,7 +30985,7 @@ class WebGLRenderer extends Renderer {
|
|
|
30858
30985
|
*/
|
|
30859
30986
|
createFontTexture(cache) {
|
|
30860
30987
|
if (typeof this.fontTexture === "undefined") {
|
|
30861
|
-
var canvas = this.
|
|
30988
|
+
var canvas = this.getCanvas();
|
|
30862
30989
|
var width = canvas.width;
|
|
30863
30990
|
var height = canvas.height;
|
|
30864
30991
|
|
|
@@ -31086,17 +31213,6 @@ class WebGLRenderer extends Renderer {
|
|
|
31086
31213
|
this.currentCompositor.addQuad(pattern, x, y, width, height, uvs[0], uvs[1], uvs[2], uvs[3], this.currentTint.toUint32());
|
|
31087
31214
|
}
|
|
31088
31215
|
|
|
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;
|
|
31098
|
-
}
|
|
31099
|
-
|
|
31100
31216
|
/**
|
|
31101
31217
|
* Returns the WebGL Context object of the given Canvas
|
|
31102
31218
|
* @name getContextGL
|
|
@@ -31254,8 +31370,8 @@ class WebGLRenderer extends Renderer {
|
|
|
31254
31370
|
this.gl.disable(this.gl.SCISSOR_TEST);
|
|
31255
31371
|
this.currentScissor[0] = 0;
|
|
31256
31372
|
this.currentScissor[1] = 0;
|
|
31257
|
-
this.currentScissor[2] = this.
|
|
31258
|
-
this.currentScissor[3] = this.
|
|
31373
|
+
this.currentScissor[2] = this.getCanvas().width;
|
|
31374
|
+
this.currentScissor[3] = this.getCanvas().height;
|
|
31259
31375
|
}
|
|
31260
31376
|
}
|
|
31261
31377
|
|
|
@@ -31346,7 +31462,7 @@ class WebGLRenderer extends Renderer {
|
|
|
31346
31462
|
* @param {number} width Line width
|
|
31347
31463
|
*/
|
|
31348
31464
|
setLineWidth(width) {
|
|
31349
|
-
this.
|
|
31465
|
+
this.getContext().lineWidth(width);
|
|
31350
31466
|
}
|
|
31351
31467
|
|
|
31352
31468
|
/**
|
|
@@ -31642,7 +31758,7 @@ class WebGLRenderer extends Renderer {
|
|
|
31642
31758
|
* @param {number} height
|
|
31643
31759
|
*/
|
|
31644
31760
|
clipRect(x, y, width, height) {
|
|
31645
|
-
var canvas = this.
|
|
31761
|
+
var canvas = this.getCanvas();
|
|
31646
31762
|
var gl = this.gl;
|
|
31647
31763
|
// if requested box is different from the current canvas size
|
|
31648
31764
|
if (x !== 0 || y !== 0 || width !== canvas.width || height !== canvas.height) {
|
|
@@ -31753,10 +31869,9 @@ var designHeight = 0;
|
|
|
31753
31869
|
var settings = {
|
|
31754
31870
|
parent : undefined,
|
|
31755
31871
|
renderer : 2, // AUTO
|
|
31756
|
-
doubleBuffering : false,
|
|
31757
31872
|
autoScale : false,
|
|
31758
31873
|
scale : 1.0,
|
|
31759
|
-
scaleMethod : "
|
|
31874
|
+
scaleMethod : "manual",
|
|
31760
31875
|
transparent : false,
|
|
31761
31876
|
blendMode : "normal",
|
|
31762
31877
|
antiAlias : false,
|
|
@@ -31797,7 +31912,7 @@ function onresize() {
|
|
|
31797
31912
|
var canvasMaxHeight = Infinity;
|
|
31798
31913
|
|
|
31799
31914
|
if (globalThis.getComputedStyle) {
|
|
31800
|
-
var style = globalThis.getComputedStyle(renderer.
|
|
31915
|
+
var style = globalThis.getComputedStyle(renderer.getCanvas(), null);
|
|
31801
31916
|
canvasMaxWidth = parseInt(style.maxWidth, 10) || Infinity;
|
|
31802
31917
|
canvasMaxHeight = parseInt(style.maxHeight, 10) || Infinity;
|
|
31803
31918
|
}
|
|
@@ -31851,6 +31966,9 @@ function onresize() {
|
|
|
31851
31966
|
|
|
31852
31967
|
// adjust scaling ratio based on the new scaling ratio
|
|
31853
31968
|
scale(scaleX, scaleY);
|
|
31969
|
+
} else {
|
|
31970
|
+
// adjust scaling ratio based on the given settings
|
|
31971
|
+
scale(settings.scale, settings.scale);
|
|
31854
31972
|
}
|
|
31855
31973
|
}
|
|
31856
31974
|
/**
|
|
@@ -31927,7 +32045,6 @@ let renderer = null;
|
|
|
31927
32045
|
* @param {object} [options] The optional video/renderer parameters.<br> (see Renderer(s) documentation for further specific options)
|
|
31928
32046
|
* @param {string|HTMLElement} [options.parent=document.body] the DOM parent element to hold the canvas in the HTML file
|
|
31929
32047
|
* @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
32048
|
* @param {number|string} [options.scale=1.0] enable scaling of the canvas ('auto' for automatic scaling)
|
|
31932
32049
|
* @param {string} [options.scaleMethod="fit"] screen scaling modes ('fit','fill-min','fill-max','flex','flex-width','flex-height','stretch')
|
|
31933
32050
|
* @param {boolean} [options.preferWebGL1=false] if true the renderer will only use WebGL 1
|
|
@@ -31942,8 +32059,7 @@ let renderer = null;
|
|
|
31942
32059
|
* parent : "screen",
|
|
31943
32060
|
* renderer : me.video.AUTO,
|
|
31944
32061
|
* scale : "auto",
|
|
31945
|
-
* scaleMethod : "fit"
|
|
31946
|
-
* doubleBuffering : true
|
|
32062
|
+
* scaleMethod : "fit"
|
|
31947
32063
|
* });
|
|
31948
32064
|
*/
|
|
31949
32065
|
function init(width, height, options) {
|
|
@@ -31959,7 +32075,6 @@ function init(width, height, options) {
|
|
|
31959
32075
|
// sanitize potential given parameters
|
|
31960
32076
|
settings.width = width;
|
|
31961
32077
|
settings.height = height;
|
|
31962
|
-
settings.doubleBuffering = !!(settings.doubleBuffering);
|
|
31963
32078
|
settings.transparent = !!(settings.transparent);
|
|
31964
32079
|
settings.antiAlias = !!(settings.antiAlias);
|
|
31965
32080
|
settings.failIfMajorPerformanceCaveat = !!(settings.failIfMajorPerformanceCaveat);
|
|
@@ -31979,24 +32094,21 @@ function init(width, height, options) {
|
|
|
31979
32094
|
console.log("melonJS 2 (v" + version + ") | http://melonjs.org" );
|
|
31980
32095
|
}
|
|
31981
32096
|
|
|
31982
|
-
// override renderer settings if &webgl is defined in the URL
|
|
32097
|
+
// override renderer settings if &webgl or &canvas is defined in the URL
|
|
31983
32098
|
var uriFragment = utils.getUriFragment();
|
|
31984
32099
|
if (uriFragment.webgl === true || uriFragment.webgl1 === true || uriFragment.webgl2 === true) {
|
|
31985
32100
|
settings.renderer = WEBGL;
|
|
31986
32101
|
if (uriFragment.webgl1 === true) {
|
|
31987
32102
|
settings.preferWebGL1 = true;
|
|
31988
32103
|
}
|
|
32104
|
+
} else if (uriFragment.canvas === true) {
|
|
32105
|
+
settings.renderer = CANVAS;
|
|
31989
32106
|
}
|
|
31990
32107
|
|
|
31991
32108
|
// normalize scale
|
|
31992
32109
|
settings.scale = (settings.autoScale) ? 1.0 : (+settings.scale || 1.0);
|
|
31993
32110
|
scaleRatio.set(settings.scale, settings.scale);
|
|
31994
32111
|
|
|
31995
|
-
// force double buffering if scaling is required
|
|
31996
|
-
if (settings.autoScale || (settings.scale !== 1.0)) {
|
|
31997
|
-
settings.doubleBuffering = true;
|
|
31998
|
-
}
|
|
31999
|
-
|
|
32000
32112
|
// hold the requested video size ratio
|
|
32001
32113
|
designRatio = width / height;
|
|
32002
32114
|
designWidth = width;
|
|
@@ -32068,7 +32180,7 @@ function init(width, height, options) {
|
|
|
32068
32180
|
|
|
32069
32181
|
// add our canvas (default to document.body if settings.parent is undefined)
|
|
32070
32182
|
parent = getElement(typeof settings.parent !== "undefined" ? settings.parent : document.body);
|
|
32071
|
-
parent.appendChild(renderer.
|
|
32183
|
+
parent.appendChild(renderer.getCanvas());
|
|
32072
32184
|
|
|
32073
32185
|
// Mobile browser hacks
|
|
32074
32186
|
if (platform.isMobile) {
|
|
@@ -32162,8 +32274,8 @@ function getParent() {
|
|
|
32162
32274
|
* @param {number} y y scaling multiplier
|
|
32163
32275
|
*/
|
|
32164
32276
|
function scale(x, y) {
|
|
32165
|
-
var canvas = renderer.
|
|
32166
|
-
var context = renderer.
|
|
32277
|
+
var canvas = renderer.getCanvas();
|
|
32278
|
+
var context = renderer.getContext();
|
|
32167
32279
|
var settings = renderer.settings;
|
|
32168
32280
|
var pixelRatio = devicePixelRatio;
|
|
32169
32281
|
|
|
@@ -32898,10 +33010,10 @@ class BasePlugin {
|
|
|
32898
33010
|
* this can be overridden by the plugin
|
|
32899
33011
|
* @public
|
|
32900
33012
|
* @type {string}
|
|
32901
|
-
* @default "13.
|
|
33013
|
+
* @default "13.1.0"
|
|
32902
33014
|
* @name plugin.Base#version
|
|
32903
33015
|
*/
|
|
32904
|
-
this.version = "13.
|
|
33016
|
+
this.version = "13.1.0";
|
|
32905
33017
|
}
|
|
32906
33018
|
}
|
|
32907
33019
|
|
|
@@ -33913,7 +34025,8 @@ class Tween {
|
|
|
33913
34025
|
var defaultAttributes = {
|
|
33914
34026
|
offscreenCanvas : false,
|
|
33915
34027
|
willReadFrequently : false,
|
|
33916
|
-
antiAlias : false
|
|
34028
|
+
antiAlias : false,
|
|
34029
|
+
context: "2d"
|
|
33917
34030
|
};
|
|
33918
34031
|
|
|
33919
34032
|
/**
|
|
@@ -33923,7 +34036,8 @@ class CanvasTexture {
|
|
|
33923
34036
|
/**
|
|
33924
34037
|
* @param {number} width the desired width of the canvas
|
|
33925
34038
|
* @param {number} height the desired height of the canvas
|
|
33926
|
-
* @param {object} attributes The attributes to create both the canvas and
|
|
34039
|
+
* @param {object} attributes The attributes to create both the canvas and context
|
|
34040
|
+
* @param {boolean} [attributes.context="2d"] the context type to be created ("2d", "webgl", "webgl2")
|
|
33927
34041
|
* @param {boolean} [attributes.offscreenCanvas=false] will create an offscreenCanvas if true instead of a standard canvas
|
|
33928
34042
|
* @param {boolean} [attributes.willReadFrequently=false] Indicates whether or not a lot of read-back operations are planned
|
|
33929
34043
|
* @param {boolean} [attributes.antiAlias=false] Whether to enable anti-aliasing, use false (default) for a pixelated effect.
|
|
@@ -35638,7 +35752,7 @@ class NineSliceSprite extends Sprite {
|
|
|
35638
35752
|
this.width = Math.floor(settings.width);
|
|
35639
35753
|
this.height = Math.floor(settings.height);
|
|
35640
35754
|
|
|
35641
|
-
// nine slice sprite specific
|
|
35755
|
+
// nine slice sprite specific internal variables
|
|
35642
35756
|
this.nss_width = this.width;
|
|
35643
35757
|
this.nss_height = this.height;
|
|
35644
35758
|
|
|
@@ -35646,6 +35760,32 @@ class NineSliceSprite extends Sprite {
|
|
|
35646
35760
|
this.insety = settings.insety;
|
|
35647
35761
|
}
|
|
35648
35762
|
|
|
35763
|
+
/**
|
|
35764
|
+
* width of the NineSliceSprite
|
|
35765
|
+
* @public
|
|
35766
|
+
* @type {number}
|
|
35767
|
+
* @name width
|
|
35768
|
+
*/
|
|
35769
|
+
get width() {
|
|
35770
|
+
return super.width;
|
|
35771
|
+
}
|
|
35772
|
+
set width(value) {
|
|
35773
|
+
super.width = this.nss_width = value;
|
|
35774
|
+
}
|
|
35775
|
+
|
|
35776
|
+
/**
|
|
35777
|
+
* height of the NineSliceSprite
|
|
35778
|
+
* @public
|
|
35779
|
+
* @type {number}
|
|
35780
|
+
* @name height
|
|
35781
|
+
*/
|
|
35782
|
+
get height() {
|
|
35783
|
+
return super.height;
|
|
35784
|
+
}
|
|
35785
|
+
set height(value) {
|
|
35786
|
+
super.height = this.nss_height = value;
|
|
35787
|
+
}
|
|
35788
|
+
|
|
35649
35789
|
/**
|
|
35650
35790
|
* @ignore
|
|
35651
35791
|
*/
|
|
@@ -37607,7 +37747,6 @@ Object.defineProperty(Renderer.prototype, "Texture", {
|
|
|
37607
37747
|
}
|
|
37608
37748
|
});
|
|
37609
37749
|
|
|
37610
|
-
|
|
37611
37750
|
/**
|
|
37612
37751
|
* @classdesc
|
|
37613
37752
|
* Used to make a game entity draggable
|
|
@@ -37646,6 +37785,33 @@ class DroptargetEntity extends DropTarget {
|
|
|
37646
37785
|
}
|
|
37647
37786
|
}
|
|
37648
37787
|
|
|
37788
|
+
/**
|
|
37789
|
+
* return a reference to the screen canvas
|
|
37790
|
+
* @name getScreenCanvas
|
|
37791
|
+
* @memberof Renderer
|
|
37792
|
+
* @returns {HTMLCanvasElement}
|
|
37793
|
+
* @deprecated since 13.1.0
|
|
37794
|
+
* @see getCanvas();
|
|
37795
|
+
*/
|
|
37796
|
+
Renderer.prototype.getScreenCanvas = function() {
|
|
37797
|
+
warning("getScreenCanvas", "getCanvas", "13.1.0");
|
|
37798
|
+
return this.getCanvas();
|
|
37799
|
+
};
|
|
37800
|
+
|
|
37801
|
+
/**
|
|
37802
|
+
* return a reference to the screen canvas corresponding 2d Context<br>
|
|
37803
|
+
* (will return buffered context if double buffering is enabled, or a reference to the Screen Context)
|
|
37804
|
+
* @name getScreenContext
|
|
37805
|
+
* @memberof Renderer
|
|
37806
|
+
* @returns {CanvasRenderingContext2D}
|
|
37807
|
+
* @deprecated since 13.1.0
|
|
37808
|
+
* @see getContext();
|
|
37809
|
+
*/
|
|
37810
|
+
Renderer.prototype.getScreenContext = function() {
|
|
37811
|
+
warning("getScreenContext", "getContext", "13.1.0");
|
|
37812
|
+
return this.getContext();
|
|
37813
|
+
};
|
|
37814
|
+
|
|
37649
37815
|
// ES5/ES6 polyfills
|
|
37650
37816
|
|
|
37651
37817
|
|
|
@@ -37656,7 +37822,7 @@ class DroptargetEntity extends DropTarget {
|
|
|
37656
37822
|
* @name version
|
|
37657
37823
|
* @type {string}
|
|
37658
37824
|
*/
|
|
37659
|
-
const version = "13.
|
|
37825
|
+
const version = "13.1.0";
|
|
37660
37826
|
|
|
37661
37827
|
|
|
37662
37828
|
/**
|