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.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
|
|
@@ -315,10 +315,10 @@
|
|
|
315
315
|
(shared$3.exports = function (key, value) {
|
|
316
316
|
return store$2[key] || (store$2[key] = value !== undefined ? value : {});
|
|
317
317
|
})('versions', []).push({
|
|
318
|
-
version: '3.
|
|
318
|
+
version: '3.24.1',
|
|
319
319
|
mode: 'global',
|
|
320
320
|
copyright: '© 2014-2022 Denis Pushkarev (zloirock.ru)',
|
|
321
|
-
license: 'https://github.com/zloirock/core-js/blob/v3.
|
|
321
|
+
license: 'https://github.com/zloirock/core-js/blob/v3.24.1/LICENSE',
|
|
322
322
|
source: 'https://github.com/zloirock/core-js'
|
|
323
323
|
});
|
|
324
324
|
|
|
@@ -2366,6 +2366,29 @@
|
|
|
2366
2366
|
return this;
|
|
2367
2367
|
};
|
|
2368
2368
|
|
|
2369
|
+
/**
|
|
2370
|
+
* interpolate the position of this vector towards the given one by the given maximum step.
|
|
2371
|
+
* @name moveTowards
|
|
2372
|
+
* @memberof Vector2d
|
|
2373
|
+
* @param {Vector2d} target
|
|
2374
|
+
* @param {number} step the maximum step per iteration (Negative values will push the vector away from the target)
|
|
2375
|
+
* @returns {Vector2d} Reference to this object for method chaining
|
|
2376
|
+
*/
|
|
2377
|
+
Vector2d.prototype.moveTowards = function moveTowards (target, step) {
|
|
2378
|
+
var angle = Math.atan2(target.y - this.y, target.x - this.x);
|
|
2379
|
+
|
|
2380
|
+
var distance = this.distance(target);
|
|
2381
|
+
|
|
2382
|
+
if (distance === 0 || (step >= 0 && distance <= step * step)) {
|
|
2383
|
+
return target;
|
|
2384
|
+
}
|
|
2385
|
+
|
|
2386
|
+
this.x += Math.cos(angle) * step;
|
|
2387
|
+
this.y += Math.sin(angle) * step;
|
|
2388
|
+
|
|
2389
|
+
return this;
|
|
2390
|
+
};
|
|
2391
|
+
|
|
2369
2392
|
/**
|
|
2370
2393
|
* return the distance between this vector and the passed one
|
|
2371
2394
|
* @name distance
|
|
@@ -2433,9 +2456,17 @@
|
|
|
2433
2456
|
};
|
|
2434
2457
|
|
|
2435
2458
|
// convert a give color component to it hexadecimal value
|
|
2436
|
-
|
|
2459
|
+
function toHex(component) {
|
|
2437
2460
|
return "0123456789ABCDEF".charAt((component - (component % 16)) >> 4) + "0123456789ABCDEF".charAt(component % 16);
|
|
2438
|
-
}
|
|
2461
|
+
}
|
|
2462
|
+
function hue2rgb(p, q, t) {
|
|
2463
|
+
if (t < 0) { t += 1; }
|
|
2464
|
+
if (t > 1) { t -= 1; }
|
|
2465
|
+
if (t < 1/6) { return p + (q - p) * 6 * t; }
|
|
2466
|
+
if (t < 1/2) { return q; }
|
|
2467
|
+
if (t < 2/3) { return p + (q - p) * (2/3 - t) * 6; }
|
|
2468
|
+
return p;
|
|
2469
|
+
}
|
|
2439
2470
|
|
|
2440
2471
|
var rgbaRx = /^rgba?\((\d+), ?(\d+), ?(\d+)(, ?([\d\.]+))?\)$/;
|
|
2441
2472
|
var hex3Rx = /^#([\da-fA-F])([\da-fA-F])([\da-fA-F])$/;
|
|
@@ -2635,7 +2666,6 @@
|
|
|
2635
2666
|
/**
|
|
2636
2667
|
* Color Red Component [0 .. 255]
|
|
2637
2668
|
* @type {number}
|
|
2638
|
-
* @memberof Color
|
|
2639
2669
|
*/
|
|
2640
2670
|
prototypeAccessors$4.r.get = function () {
|
|
2641
2671
|
return ~~(this.glArray[0] * 255);
|
|
@@ -2649,7 +2679,6 @@
|
|
|
2649
2679
|
/**
|
|
2650
2680
|
* Color Green Component [0 .. 255]
|
|
2651
2681
|
* @type {number}
|
|
2652
|
-
* @memberof Color
|
|
2653
2682
|
*/
|
|
2654
2683
|
prototypeAccessors$4.g.get = function () {
|
|
2655
2684
|
return ~~(this.glArray[1] * 255);
|
|
@@ -2663,7 +2692,6 @@
|
|
|
2663
2692
|
/**
|
|
2664
2693
|
* Color Blue Component [0 .. 255]
|
|
2665
2694
|
* @type {number}
|
|
2666
|
-
* @memberof Color
|
|
2667
2695
|
*/
|
|
2668
2696
|
prototypeAccessors$4.b.get = function () {
|
|
2669
2697
|
return ~~(this.glArray[2] * 255);
|
|
@@ -2675,7 +2703,6 @@
|
|
|
2675
2703
|
/**
|
|
2676
2704
|
* Color Alpha Component [0.0 .. 1.0]
|
|
2677
2705
|
* @type {number}
|
|
2678
|
-
* @memberof Color
|
|
2679
2706
|
*/
|
|
2680
2707
|
prototypeAccessors$4.alpha.get = function () {
|
|
2681
2708
|
return this.glArray[3];
|
|
@@ -2688,8 +2715,6 @@
|
|
|
2688
2715
|
|
|
2689
2716
|
/**
|
|
2690
2717
|
* Set this color to the specified value.
|
|
2691
|
-
* @name setColor
|
|
2692
|
-
* @memberof Color
|
|
2693
2718
|
* @param {number} r red component [0 .. 255]
|
|
2694
2719
|
* @param {number} g green component [0 .. 255]
|
|
2695
2720
|
* @param {number} b blue component [0 .. 255]
|
|
@@ -2706,10 +2731,59 @@
|
|
|
2706
2731
|
return this;
|
|
2707
2732
|
};
|
|
2708
2733
|
|
|
2734
|
+
/**
|
|
2735
|
+
* set this color to the specified HSV value
|
|
2736
|
+
* @param {number} h hue (a value from 0 to 1)
|
|
2737
|
+
* @param {number} s saturation (a value from 0 to 1)
|
|
2738
|
+
* @param {number} v value (a value from 0 to 1)
|
|
2739
|
+
* @returns {Color} Reference to this object for method chaining
|
|
2740
|
+
*/
|
|
2741
|
+
Color.prototype.setHSV = function setHSV (h, s, v) {
|
|
2742
|
+
var r, g, b;
|
|
2743
|
+
|
|
2744
|
+
var i = Math.floor(h * 6);
|
|
2745
|
+
var f = h * 6 - i;
|
|
2746
|
+
var p = v * (1 - s);
|
|
2747
|
+
var q = v * (1 - f * s);
|
|
2748
|
+
var t = v * (1 - (1 - f) * s);
|
|
2749
|
+
|
|
2750
|
+
switch (i % 6) {
|
|
2751
|
+
case 0: r = v, g = t, b = p; break;
|
|
2752
|
+
case 1: r = q, g = v, b = p; break;
|
|
2753
|
+
case 2: r = p, g = v, b = t; break;
|
|
2754
|
+
case 3: r = p, g = q, b = v; break;
|
|
2755
|
+
case 4: r = t, g = p, b = v; break;
|
|
2756
|
+
case 5: r = v, g = p, b = q; break;
|
|
2757
|
+
}
|
|
2758
|
+
return this.setColor(r * 255, g * 255, b * 255);
|
|
2759
|
+
};
|
|
2760
|
+
|
|
2761
|
+
/**
|
|
2762
|
+
* set this color to the specified HSL value
|
|
2763
|
+
* @param {number} h hue (a value from 0 to 1)
|
|
2764
|
+
* @param {number} s saturation (a value from 0 to 1)
|
|
2765
|
+
* @param {number} l lightness (a value from 0 to 1)
|
|
2766
|
+
* @returns {Color} Reference to this object for method chaining
|
|
2767
|
+
*/
|
|
2768
|
+
Color.prototype.setHSL = function setHSL (h, s, l) {
|
|
2769
|
+
var r, g, b;
|
|
2770
|
+
|
|
2771
|
+
if (s === 0) {
|
|
2772
|
+
r = g = b = l; // achromatic
|
|
2773
|
+
} else {
|
|
2774
|
+
var q = l < 0.5 ? l * (1 + s) : l + s - l * s;
|
|
2775
|
+
var p = 2 * l - q;
|
|
2776
|
+
|
|
2777
|
+
r = hue2rgb(p, q, h + 1/3);
|
|
2778
|
+
g = hue2rgb(p, q, h);
|
|
2779
|
+
b = hue2rgb(p, q, h - 1/3);
|
|
2780
|
+
}
|
|
2781
|
+
|
|
2782
|
+
return this.setColor(r * 255, g * 255, b * 255);
|
|
2783
|
+
};
|
|
2784
|
+
|
|
2709
2785
|
/**
|
|
2710
2786
|
* Create a new copy of this color object.
|
|
2711
|
-
* @name clone
|
|
2712
|
-
* @memberof Color
|
|
2713
2787
|
* @returns {Color} Reference to the newly cloned object
|
|
2714
2788
|
*/
|
|
2715
2789
|
Color.prototype.clone = function clone () {
|
|
@@ -2718,8 +2792,6 @@
|
|
|
2718
2792
|
|
|
2719
2793
|
/**
|
|
2720
2794
|
* Copy a color object or CSS color into this one.
|
|
2721
|
-
* @name copy
|
|
2722
|
-
* @memberof Color
|
|
2723
2795
|
* @param {Color|string} color
|
|
2724
2796
|
* @returns {Color} Reference to this object for method chaining
|
|
2725
2797
|
*/
|
|
@@ -2734,8 +2806,6 @@
|
|
|
2734
2806
|
|
|
2735
2807
|
/**
|
|
2736
2808
|
* Blend this color with the given one using addition.
|
|
2737
|
-
* @name add
|
|
2738
|
-
* @memberof Color
|
|
2739
2809
|
* @param {Color} color
|
|
2740
2810
|
* @returns {Color} Reference to this object for method chaining
|
|
2741
2811
|
*/
|
|
@@ -2750,8 +2820,6 @@
|
|
|
2750
2820
|
|
|
2751
2821
|
/**
|
|
2752
2822
|
* Darken this color value by 0..1
|
|
2753
|
-
* @name darken
|
|
2754
|
-
* @memberof Color
|
|
2755
2823
|
* @param {number} scale
|
|
2756
2824
|
* @returns {Color} Reference to this object for method chaining
|
|
2757
2825
|
*/
|
|
@@ -2766,8 +2834,6 @@
|
|
|
2766
2834
|
|
|
2767
2835
|
/**
|
|
2768
2836
|
* Linearly interpolate between this color and the given one.
|
|
2769
|
-
* @name lerp
|
|
2770
|
-
* @memberof Color
|
|
2771
2837
|
* @param {Color} color
|
|
2772
2838
|
* @param {number} alpha with alpha = 0 being this color, and alpha = 1 being the given one.
|
|
2773
2839
|
* @returns {Color} Reference to this object for method chaining
|
|
@@ -2783,8 +2849,6 @@
|
|
|
2783
2849
|
|
|
2784
2850
|
/**
|
|
2785
2851
|
* Lighten this color value by 0..1
|
|
2786
|
-
* @name lighten
|
|
2787
|
-
* @memberof Color
|
|
2788
2852
|
* @param {number} scale
|
|
2789
2853
|
* @returns {Color} Reference to this object for method chaining
|
|
2790
2854
|
*/
|
|
@@ -2799,8 +2863,6 @@
|
|
|
2799
2863
|
|
|
2800
2864
|
/**
|
|
2801
2865
|
* Generate random r,g,b values for this color object
|
|
2802
|
-
* @name random
|
|
2803
|
-
* @memberof Color
|
|
2804
2866
|
* @param {number} [min=0] minimum value for the random range
|
|
2805
2867
|
* @param {number} [max=255] maxmium value for the random range
|
|
2806
2868
|
* @returns {Color} Reference to this object for method chaining
|
|
@@ -2827,8 +2889,6 @@
|
|
|
2827
2889
|
/**
|
|
2828
2890
|
* Return true if the r,g,b,a values of this color are equal with the
|
|
2829
2891
|
* given one.
|
|
2830
|
-
* @name equals
|
|
2831
|
-
* @memberof Color
|
|
2832
2892
|
* @param {Color} color
|
|
2833
2893
|
* @returns {boolean}
|
|
2834
2894
|
*/
|
|
@@ -2844,8 +2904,6 @@
|
|
|
2844
2904
|
/**
|
|
2845
2905
|
* Parse a CSS color string and set this color to the corresponding
|
|
2846
2906
|
* r,g,b values
|
|
2847
|
-
* @name parseCSS
|
|
2848
|
-
* @memberof Color
|
|
2849
2907
|
* @param {string} cssColor
|
|
2850
2908
|
* @returns {Color} Reference to this object for method chaining
|
|
2851
2909
|
*/
|
|
@@ -2861,8 +2919,6 @@
|
|
|
2861
2919
|
|
|
2862
2920
|
/**
|
|
2863
2921
|
* Parse an RGB or RGBA CSS color string
|
|
2864
|
-
* @name parseRGB
|
|
2865
|
-
* @memberof Color
|
|
2866
2922
|
* @param {string} rgbColor
|
|
2867
2923
|
* @returns {Color} Reference to this object for method chaining
|
|
2868
2924
|
*/
|
|
@@ -2880,8 +2936,6 @@
|
|
|
2880
2936
|
/**
|
|
2881
2937
|
* Parse a Hex color ("#RGB", "#RGBA" or "#RRGGBB", "#RRGGBBAA" format) and set this color to
|
|
2882
2938
|
* the corresponding r,g,b,a values
|
|
2883
|
-
* @name parseHex
|
|
2884
|
-
* @memberof Color
|
|
2885
2939
|
* @param {string} hexColor
|
|
2886
2940
|
* @param {boolean} [argb = false] true if format is #ARGB, or #AARRGGBB (as opposed to #RGBA or #RGGBBAA)
|
|
2887
2941
|
* @returns {Color} Reference to this object for method chaining
|
|
@@ -2941,8 +2995,6 @@
|
|
|
2941
2995
|
|
|
2942
2996
|
/**
|
|
2943
2997
|
* Pack this color into a Uint32 ARGB representation
|
|
2944
|
-
* @name toUint32
|
|
2945
|
-
* @memberof Color
|
|
2946
2998
|
* @param {number} [alpha=1.0] alpha value [0.0 .. 1.0]
|
|
2947
2999
|
* @returns {number}
|
|
2948
3000
|
*/
|
|
@@ -2959,8 +3011,6 @@
|
|
|
2959
3011
|
|
|
2960
3012
|
/**
|
|
2961
3013
|
* return an array representation of this object
|
|
2962
|
-
* @name toArray
|
|
2963
|
-
* @memberof Color
|
|
2964
3014
|
* @returns {Float32Array}
|
|
2965
3015
|
*/
|
|
2966
3016
|
Color.prototype.toArray = function toArray () {
|
|
@@ -2969,9 +3019,7 @@
|
|
|
2969
3019
|
|
|
2970
3020
|
|
|
2971
3021
|
/**
|
|
2972
|
-
*
|
|
2973
|
-
* @name toHex
|
|
2974
|
-
* @memberof Color
|
|
3022
|
+
* return the color in "#RRGGBB" format
|
|
2975
3023
|
* @returns {string}
|
|
2976
3024
|
*/
|
|
2977
3025
|
Color.prototype.toHex = function toHex$1 () {
|
|
@@ -2983,8 +3031,6 @@
|
|
|
2983
3031
|
|
|
2984
3032
|
/**
|
|
2985
3033
|
* Get the color in "#RRGGBBAA" format
|
|
2986
|
-
* @name toHex8
|
|
2987
|
-
* @memberof Color
|
|
2988
3034
|
* @returns {string}
|
|
2989
3035
|
*/
|
|
2990
3036
|
Color.prototype.toHex8 = function toHex8 (alpha) {
|
|
@@ -2998,8 +3044,6 @@
|
|
|
2998
3044
|
|
|
2999
3045
|
/**
|
|
3000
3046
|
* Get the color in "rgb(R,G,B)" format
|
|
3001
|
-
* @name toRGB
|
|
3002
|
-
* @memberof Color
|
|
3003
3047
|
* @returns {string}
|
|
3004
3048
|
*/
|
|
3005
3049
|
Color.prototype.toRGB = function toRGB () {
|
|
@@ -3015,8 +3059,6 @@
|
|
|
3015
3059
|
|
|
3016
3060
|
/**
|
|
3017
3061
|
* Get the color in "rgba(R,G,B,A)" format
|
|
3018
|
-
* @name toRGBA
|
|
3019
|
-
* @memberof Color
|
|
3020
3062
|
* @param {number} [alpha=1.0] alpha value [0.0 .. 1.0]
|
|
3021
3063
|
* @returns {string}
|
|
3022
3064
|
*/
|
|
@@ -6904,8 +6946,8 @@
|
|
|
6904
6946
|
// initial viewport size
|
|
6905
6947
|
this.setViewport(
|
|
6906
6948
|
0, 0,
|
|
6907
|
-
this.renderer.
|
|
6908
|
-
this.renderer.
|
|
6949
|
+
this.renderer.getCanvas().width,
|
|
6950
|
+
this.renderer.getCanvas().height
|
|
6909
6951
|
);
|
|
6910
6952
|
|
|
6911
6953
|
// Initialize clear color
|
|
@@ -10147,13 +10189,9 @@
|
|
|
10147
10189
|
} else if (typeof this.settings.canvas !== "undefined") {
|
|
10148
10190
|
this.canvas = this.settings.canvas;
|
|
10149
10191
|
} else {
|
|
10150
|
-
this.canvas = createCanvas(this.settings.
|
|
10192
|
+
this.canvas = createCanvas(this.settings.width, this.settings.height);
|
|
10151
10193
|
}
|
|
10152
10194
|
|
|
10153
|
-
// canvas object and context
|
|
10154
|
-
this.backBufferCanvas = this.canvas;
|
|
10155
|
-
this.context = null;
|
|
10156
|
-
|
|
10157
10195
|
// global color
|
|
10158
10196
|
this.currentColor = new Color(0, 0, 0, 1.0);
|
|
10159
10197
|
|
|
@@ -10179,6 +10217,13 @@
|
|
|
10179
10217
|
*/
|
|
10180
10218
|
Renderer.prototype.clear = function clear () {};
|
|
10181
10219
|
|
|
10220
|
+
/**
|
|
10221
|
+
* render the main framebuffer on screen
|
|
10222
|
+
* @name flush
|
|
10223
|
+
* @memberof Renderer
|
|
10224
|
+
*/
|
|
10225
|
+
Renderer.prototype.flush = function flush () {};
|
|
10226
|
+
|
|
10182
10227
|
/**
|
|
10183
10228
|
* Reset context state
|
|
10184
10229
|
* @name reset
|
|
@@ -10192,39 +10237,29 @@
|
|
|
10192
10237
|
this.cache.clear();
|
|
10193
10238
|
this.currentScissor[0] = 0;
|
|
10194
10239
|
this.currentScissor[1] = 0;
|
|
10195
|
-
this.currentScissor[2] = this.
|
|
10196
|
-
this.currentScissor[3] = this.
|
|
10240
|
+
this.currentScissor[2] = this.getCanvas().width;
|
|
10241
|
+
this.currentScissor[3] = this.getCanvas().height;
|
|
10197
10242
|
this.clearMask();
|
|
10198
10243
|
};
|
|
10199
10244
|
|
|
10200
10245
|
/**
|
|
10201
|
-
* return a reference to the
|
|
10246
|
+
* return a reference to the canvas which this renderer draws to
|
|
10202
10247
|
* @name getCanvas
|
|
10203
10248
|
* @memberof Renderer
|
|
10204
10249
|
* @returns {HTMLCanvasElement}
|
|
10205
10250
|
*/
|
|
10206
10251
|
Renderer.prototype.getCanvas = function getCanvas () {
|
|
10207
|
-
return this.backBufferCanvas;
|
|
10208
|
-
};
|
|
10209
|
-
|
|
10210
|
-
/**
|
|
10211
|
-
* return a reference to the screen canvas
|
|
10212
|
-
* @name getScreenCanvas
|
|
10213
|
-
* @memberof Renderer
|
|
10214
|
-
* @returns {HTMLCanvasElement}
|
|
10215
|
-
*/
|
|
10216
|
-
Renderer.prototype.getScreenCanvas = function getScreenCanvas () {
|
|
10217
10252
|
return this.canvas;
|
|
10218
10253
|
};
|
|
10219
10254
|
|
|
10255
|
+
|
|
10220
10256
|
/**
|
|
10221
|
-
* return a reference to
|
|
10222
|
-
*
|
|
10223
|
-
* @name getScreenContext
|
|
10257
|
+
* return a reference to this renderer canvas corresponding Context
|
|
10258
|
+
* @name getContext
|
|
10224
10259
|
* @memberof Renderer
|
|
10225
|
-
* @returns {CanvasRenderingContext2D}
|
|
10260
|
+
* @returns {CanvasRenderingContext2D|WebGLRenderingContext}
|
|
10226
10261
|
*/
|
|
10227
|
-
Renderer.prototype.
|
|
10262
|
+
Renderer.prototype.getContext = function getContext () {
|
|
10228
10263
|
return this.context;
|
|
10229
10264
|
};
|
|
10230
10265
|
|
|
@@ -10283,7 +10318,7 @@
|
|
|
10283
10318
|
* @returns {number}
|
|
10284
10319
|
*/
|
|
10285
10320
|
Renderer.prototype.getWidth = function getWidth () {
|
|
10286
|
-
return this.
|
|
10321
|
+
return this.getCanvas().width;
|
|
10287
10322
|
};
|
|
10288
10323
|
|
|
10289
10324
|
/**
|
|
@@ -10293,7 +10328,7 @@
|
|
|
10293
10328
|
* @returns {number} height of the system Canvas
|
|
10294
10329
|
*/
|
|
10295
10330
|
Renderer.prototype.getHeight = function getHeight () {
|
|
10296
|
-
return this.
|
|
10331
|
+
return this.getCanvas().height;
|
|
10297
10332
|
};
|
|
10298
10333
|
|
|
10299
10334
|
/**
|
|
@@ -10339,9 +10374,10 @@
|
|
|
10339
10374
|
* @param {number} height new height of the canvas
|
|
10340
10375
|
*/
|
|
10341
10376
|
Renderer.prototype.resize = function resize (width, height) {
|
|
10342
|
-
|
|
10343
|
-
|
|
10344
|
-
|
|
10377
|
+
var canvas = this.getCanvas();
|
|
10378
|
+
if (width !== canvas.width || height !== canvas.height) {
|
|
10379
|
+
canvas.width = width;
|
|
10380
|
+
canvas.height = height;
|
|
10345
10381
|
this.currentScissor[0] = 0;
|
|
10346
10382
|
this.currentScissor[1] = 0;
|
|
10347
10383
|
this.currentScissor[2] = width;
|
|
@@ -14678,8 +14714,32 @@
|
|
|
14678
14714
|
* @returns {ObservableVector2d} Reference to this object for method chaining
|
|
14679
14715
|
*/
|
|
14680
14716
|
ObservableVector2d.prototype.lerp = function lerp (v, alpha) {
|
|
14681
|
-
this.
|
|
14682
|
-
|
|
14717
|
+
return this._set(
|
|
14718
|
+
this._x + ( v.x - this._x ) * alpha,
|
|
14719
|
+
this._y + ( v.y - this._y ) * alpha
|
|
14720
|
+
);
|
|
14721
|
+
};
|
|
14722
|
+
|
|
14723
|
+
/**
|
|
14724
|
+
* interpolate the position of this vector towards the given one while nsure that the distance never exceeds the given step.
|
|
14725
|
+
* @name moveTowards
|
|
14726
|
+
* @memberof ObservableVector2d
|
|
14727
|
+
* @param {Vector2d|ObservableVector2d} target
|
|
14728
|
+
* @param {number} step the maximum step per iteration (Negative values will push the vector away from the target)
|
|
14729
|
+
* @returns {ObservableVector2d} Reference to this object for method chaining
|
|
14730
|
+
*/
|
|
14731
|
+
ObservableVector2d.prototype.moveTowards = function moveTowards (target, step) {
|
|
14732
|
+
var angle = Math.atan2(target.y - this._y, target.x - this._x);
|
|
14733
|
+
|
|
14734
|
+
var distance = this.distance(target);
|
|
14735
|
+
|
|
14736
|
+
if (distance === 0 || (step >= 0 && distance <= step * step)) {
|
|
14737
|
+
return target;
|
|
14738
|
+
}
|
|
14739
|
+
|
|
14740
|
+
this._x += Math.cos(angle) * step;
|
|
14741
|
+
this._y += Math.sin(angle) * step;
|
|
14742
|
+
|
|
14683
14743
|
return this;
|
|
14684
14744
|
};
|
|
14685
14745
|
|
|
@@ -15192,6 +15252,32 @@
|
|
|
15192
15252
|
return this;
|
|
15193
15253
|
};
|
|
15194
15254
|
|
|
15255
|
+
/**
|
|
15256
|
+
* interpolate the position of this vector on the x and y axis towards the given one by the given maximum step.
|
|
15257
|
+
* @name moveTowards
|
|
15258
|
+
* @memberof Vector3d
|
|
15259
|
+
* @param {Vector2d|Vector3d} target
|
|
15260
|
+
* @param {number} step the maximum step per iteration (Negative values will push the vector away from the target)
|
|
15261
|
+
* @returns {Vector3d} Reference to this object for method chaining
|
|
15262
|
+
*/
|
|
15263
|
+
Vector3d.prototype.moveTowards = function moveTowards (target, step) {
|
|
15264
|
+
var angle = Math.atan2(target.y - this.y, target.x - this.x);
|
|
15265
|
+
|
|
15266
|
+
var dx = this.x - target.x;
|
|
15267
|
+
var dy = this.y - target.y;
|
|
15268
|
+
|
|
15269
|
+
var distance = Math.sqrt(dx * dx + dy * dy);
|
|
15270
|
+
|
|
15271
|
+
if (distance === 0 || (step >= 0 && distance <= step * step)) {
|
|
15272
|
+
return target;
|
|
15273
|
+
}
|
|
15274
|
+
|
|
15275
|
+
this.x += Math.cos(angle) * step;
|
|
15276
|
+
this.y += Math.sin(angle) * step;
|
|
15277
|
+
|
|
15278
|
+
return this;
|
|
15279
|
+
};
|
|
15280
|
+
|
|
15195
15281
|
/**
|
|
15196
15282
|
* return the distance between this vector and the passed one
|
|
15197
15283
|
* @name distance
|
|
@@ -15733,10 +15819,38 @@
|
|
|
15733
15819
|
* @returns {ObservableVector3d} Reference to this object for method chaining
|
|
15734
15820
|
*/
|
|
15735
15821
|
ObservableVector3d.prototype.lerp = function lerp (v, alpha) {
|
|
15736
|
-
this.
|
|
15737
|
-
|
|
15738
|
-
|
|
15739
|
-
|
|
15822
|
+
return this._set(
|
|
15823
|
+
this._x + ( v.x - this._x ) * alpha,
|
|
15824
|
+
this._y + ( v.y - this._y ) * alpha,
|
|
15825
|
+
this._z + ( v.z - this._z ) * alpha
|
|
15826
|
+
);
|
|
15827
|
+
};
|
|
15828
|
+
|
|
15829
|
+
/**
|
|
15830
|
+
* 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.
|
|
15831
|
+
* @name moveTowards
|
|
15832
|
+
* @memberof ObservableVector3d
|
|
15833
|
+
* @param {Vector2d|ObservableVector2d|Vector3d|ObservableVector3d} target
|
|
15834
|
+
* @param {number} step the maximum step per iteration (Negative values will push the vector away from the target)
|
|
15835
|
+
* @returns {ObservableVector3d} Reference to this object for method chaining
|
|
15836
|
+
*/
|
|
15837
|
+
ObservableVector3d.prototype.moveTowards = function moveTowards (target, step) {
|
|
15838
|
+
var angle = Math.atan2(target.y - this._y, target.x - this._x);
|
|
15839
|
+
|
|
15840
|
+
var dx = this._x - target.x;
|
|
15841
|
+
var dy = this._y - target.y;
|
|
15842
|
+
|
|
15843
|
+
var distance = Math.sqrt(dx * dx + dy * dy);
|
|
15844
|
+
|
|
15845
|
+
if (distance === 0 || (step >= 0 && distance <= step * step)) {
|
|
15846
|
+
return target;
|
|
15847
|
+
}
|
|
15848
|
+
|
|
15849
|
+
return this._set(
|
|
15850
|
+
this._x + Math.cos(angle) * step,
|
|
15851
|
+
this._y + Math.sin(angle) * step,
|
|
15852
|
+
this._z
|
|
15853
|
+
);
|
|
15740
15854
|
};
|
|
15741
15855
|
|
|
15742
15856
|
/**
|
|
@@ -16750,7 +16864,7 @@
|
|
|
16750
16864
|
|
|
16751
16865
|
if (pointerEventTarget === null) {
|
|
16752
16866
|
// default pointer event target
|
|
16753
|
-
pointerEventTarget = renderer.
|
|
16867
|
+
pointerEventTarget = renderer.getCanvas();
|
|
16754
16868
|
}
|
|
16755
16869
|
|
|
16756
16870
|
if (pointerEvent) {
|
|
@@ -17181,7 +17295,7 @@
|
|
|
17181
17295
|
*/
|
|
17182
17296
|
function globalToLocal(x, y, v) {
|
|
17183
17297
|
v = v || pool.pull("Vector2d");
|
|
17184
|
-
var rect = getElementBounds(renderer.
|
|
17298
|
+
var rect = getElementBounds(renderer.getCanvas());
|
|
17185
17299
|
var pixelRatio = globalThis.devicePixelRatio || 1;
|
|
17186
17300
|
x -= rect.left + (globalThis.pageXOffset || 0);
|
|
17187
17301
|
y -= rect.top + (globalThis.pageYOffset || 0);
|
|
@@ -24334,17 +24448,7 @@
|
|
|
24334
24448
|
Renderer.call(this, options);
|
|
24335
24449
|
|
|
24336
24450
|
// defined the 2d context
|
|
24337
|
-
this.context = this.getContext2d(this.
|
|
24338
|
-
|
|
24339
|
-
// create the back buffer if we use double buffering
|
|
24340
|
-
if (this.settings.doubleBuffering) {
|
|
24341
|
-
this.backBufferCanvas = createCanvas(this.settings.width, this.settings.height, true);
|
|
24342
|
-
this.backBufferContext2D = this.getContext2d(this.backBufferCanvas);
|
|
24343
|
-
}
|
|
24344
|
-
else {
|
|
24345
|
-
this.backBufferCanvas = this.getScreenCanvas();
|
|
24346
|
-
this.backBufferContext2D = this.context;
|
|
24347
|
-
}
|
|
24451
|
+
this.context = this.getContext2d(this.getCanvas(), this.settings.transparent);
|
|
24348
24452
|
|
|
24349
24453
|
this.setBlendMode(this.settings.blendMode);
|
|
24350
24454
|
|
|
@@ -24360,13 +24464,13 @@
|
|
|
24360
24464
|
}
|
|
24361
24465
|
|
|
24362
24466
|
// context lost & restore event for canvas
|
|
24363
|
-
this.
|
|
24467
|
+
this.getCanvas().addEventListener("contextlost", function (e) {
|
|
24364
24468
|
e.preventDefault();
|
|
24365
24469
|
this$1$1.isContextValid = false;
|
|
24366
24470
|
emit(ONCONTEXT_LOST, this$1$1);
|
|
24367
24471
|
}, false );
|
|
24368
24472
|
// ctx.restoreContext()
|
|
24369
|
-
this.
|
|
24473
|
+
this.getCanvas().addEventListener("contextrestored", function () {
|
|
24370
24474
|
this$1$1.isContextValid = true;
|
|
24371
24475
|
emit(ONCONTEXT_RESTORED, this$1$1);
|
|
24372
24476
|
}, false );
|
|
@@ -24392,7 +24496,7 @@
|
|
|
24392
24496
|
* @memberof CanvasRenderer
|
|
24393
24497
|
*/
|
|
24394
24498
|
CanvasRenderer.prototype.resetTransform = function resetTransform () {
|
|
24395
|
-
this.
|
|
24499
|
+
this.getContext().setTransform(1, 0, 0, 1, 0, 0);
|
|
24396
24500
|
};
|
|
24397
24501
|
|
|
24398
24502
|
/**
|
|
@@ -24436,12 +24540,6 @@
|
|
|
24436
24540
|
this.currentBlendMode = "normal";
|
|
24437
24541
|
break;
|
|
24438
24542
|
}
|
|
24439
|
-
|
|
24440
|
-
// transparent setting will override the given blendmode for this.context
|
|
24441
|
-
if (this.settings.doubleBuffering && this.settings.transparent) {
|
|
24442
|
-
// Clears the front buffer for each frame blit
|
|
24443
|
-
this.context.globalCompositeOperation = "copy";
|
|
24444
|
-
}
|
|
24445
24543
|
};
|
|
24446
24544
|
|
|
24447
24545
|
/**
|
|
@@ -24455,17 +24553,6 @@
|
|
|
24455
24553
|
}
|
|
24456
24554
|
};
|
|
24457
24555
|
|
|
24458
|
-
/**
|
|
24459
|
-
* render the main framebuffer on screen
|
|
24460
|
-
* @name flush
|
|
24461
|
-
* @memberof CanvasRenderer
|
|
24462
|
-
*/
|
|
24463
|
-
CanvasRenderer.prototype.flush = function flush () {
|
|
24464
|
-
if (this.settings.doubleBuffering) {
|
|
24465
|
-
this.context.drawImage(this.backBufferCanvas, 0, 0);
|
|
24466
|
-
}
|
|
24467
|
-
};
|
|
24468
|
-
|
|
24469
24556
|
/**
|
|
24470
24557
|
* Clears the main framebuffer with the given color
|
|
24471
24558
|
* @name clearColor
|
|
@@ -24476,11 +24563,14 @@
|
|
|
24476
24563
|
CanvasRenderer.prototype.clearColor = function clearColor (color, opaque) {
|
|
24477
24564
|
if ( color === void 0 ) color = "#000000";
|
|
24478
24565
|
|
|
24566
|
+
var canvas = this.getCanvas();
|
|
24567
|
+
var context = this.getContext();
|
|
24568
|
+
|
|
24479
24569
|
this.save();
|
|
24480
24570
|
this.resetTransform();
|
|
24481
|
-
|
|
24482
|
-
|
|
24483
|
-
this.fillRect(0, 0,
|
|
24571
|
+
context.globalCompositeOperation = opaque ? "copy" : "source-over";
|
|
24572
|
+
context.fillStyle = (color instanceof Color) ? color.toRGBA() : color;
|
|
24573
|
+
this.fillRect(0, 0, canvas.width, canvas.height);
|
|
24484
24574
|
this.restore();
|
|
24485
24575
|
};
|
|
24486
24576
|
|
|
@@ -24850,17 +24940,6 @@
|
|
|
24850
24940
|
this.strokeRoundRect(x, y, width, height, radius, true);
|
|
24851
24941
|
};
|
|
24852
24942
|
|
|
24853
|
-
|
|
24854
|
-
/**
|
|
24855
|
-
* return a reference to the system 2d Context
|
|
24856
|
-
* @name getContext
|
|
24857
|
-
* @memberof CanvasRenderer
|
|
24858
|
-
* @returns {CanvasRenderingContext2D}
|
|
24859
|
-
*/
|
|
24860
|
-
CanvasRenderer.prototype.getContext = function getContext () {
|
|
24861
|
-
return this.backBufferContext2D;
|
|
24862
|
-
};
|
|
24863
|
-
|
|
24864
24943
|
/**
|
|
24865
24944
|
* return a reference to the font 2d Context
|
|
24866
24945
|
* @ignore
|
|
@@ -24876,7 +24955,7 @@
|
|
|
24876
24955
|
* @memberof CanvasRenderer
|
|
24877
24956
|
*/
|
|
24878
24957
|
CanvasRenderer.prototype.save = function save () {
|
|
24879
|
-
this.
|
|
24958
|
+
this.getContext().save();
|
|
24880
24959
|
};
|
|
24881
24960
|
|
|
24882
24961
|
/**
|
|
@@ -24885,12 +24964,12 @@
|
|
|
24885
24964
|
* @memberof CanvasRenderer
|
|
24886
24965
|
*/
|
|
24887
24966
|
CanvasRenderer.prototype.restore = function restore () {
|
|
24888
|
-
this.
|
|
24967
|
+
this.getContext().restore();
|
|
24889
24968
|
this.currentColor.glArray[3] = this.getGlobalAlpha();
|
|
24890
24969
|
this.currentScissor[0] = 0;
|
|
24891
24970
|
this.currentScissor[1] = 0;
|
|
24892
|
-
this.currentScissor[2] = this.
|
|
24893
|
-
this.currentScissor[3] = this.
|
|
24971
|
+
this.currentScissor[2] = this.getCanvas().width;
|
|
24972
|
+
this.currentScissor[3] = this.getCanvas().height;
|
|
24894
24973
|
};
|
|
24895
24974
|
|
|
24896
24975
|
/**
|
|
@@ -24900,7 +24979,7 @@
|
|
|
24900
24979
|
* @param {number} angle in radians
|
|
24901
24980
|
*/
|
|
24902
24981
|
CanvasRenderer.prototype.rotate = function rotate (angle) {
|
|
24903
|
-
this.
|
|
24982
|
+
this.getContext().rotate(angle);
|
|
24904
24983
|
};
|
|
24905
24984
|
|
|
24906
24985
|
/**
|
|
@@ -24911,7 +24990,7 @@
|
|
|
24911
24990
|
* @param {number} y
|
|
24912
24991
|
*/
|
|
24913
24992
|
CanvasRenderer.prototype.scale = function scale (x, y) {
|
|
24914
|
-
this.
|
|
24993
|
+
this.getContext().scale(x, y);
|
|
24915
24994
|
};
|
|
24916
24995
|
|
|
24917
24996
|
/**
|
|
@@ -24922,8 +25001,9 @@
|
|
|
24922
25001
|
* @param {Color|string} color css color value
|
|
24923
25002
|
*/
|
|
24924
25003
|
CanvasRenderer.prototype.setColor = function setColor (color) {
|
|
24925
|
-
this.
|
|
24926
|
-
|
|
25004
|
+
var context = this.getContext();
|
|
25005
|
+
context.strokeStyle =
|
|
25006
|
+
context.fillStyle = (
|
|
24927
25007
|
color instanceof Color ?
|
|
24928
25008
|
color.toRGBA() :
|
|
24929
25009
|
color
|
|
@@ -24937,7 +25017,7 @@
|
|
|
24937
25017
|
* @param {number} alpha 0.0 to 1.0 values accepted.
|
|
24938
25018
|
*/
|
|
24939
25019
|
CanvasRenderer.prototype.setGlobalAlpha = function setGlobalAlpha (alpha) {
|
|
24940
|
-
this.
|
|
25020
|
+
this.getContext().globalAlpha = this.currentColor.glArray[3] = alpha;
|
|
24941
25021
|
};
|
|
24942
25022
|
|
|
24943
25023
|
/**
|
|
@@ -24947,7 +25027,7 @@
|
|
|
24947
25027
|
* @returns {number} global alpha value
|
|
24948
25028
|
*/
|
|
24949
25029
|
CanvasRenderer.prototype.getGlobalAlpha = function getGlobalAlpha () {
|
|
24950
|
-
return this.
|
|
25030
|
+
return this.getContext().globalAlpha;
|
|
24951
25031
|
};
|
|
24952
25032
|
|
|
24953
25033
|
/**
|
|
@@ -24957,7 +25037,7 @@
|
|
|
24957
25037
|
* @param {number} width Line width
|
|
24958
25038
|
*/
|
|
24959
25039
|
CanvasRenderer.prototype.setLineWidth = function setLineWidth (width) {
|
|
24960
|
-
this.
|
|
25040
|
+
this.getContext().lineWidth = width;
|
|
24961
25041
|
};
|
|
24962
25042
|
|
|
24963
25043
|
/**
|
|
@@ -24992,7 +25072,7 @@
|
|
|
24992
25072
|
f |= 0;
|
|
24993
25073
|
}
|
|
24994
25074
|
|
|
24995
|
-
this.
|
|
25075
|
+
this.getContext().transform(a, b, c, d, e, f);
|
|
24996
25076
|
};
|
|
24997
25077
|
|
|
24998
25078
|
/**
|
|
@@ -25004,9 +25084,9 @@
|
|
|
25004
25084
|
*/
|
|
25005
25085
|
CanvasRenderer.prototype.translate = function translate (x, y) {
|
|
25006
25086
|
if (this.settings.subPixel === false) {
|
|
25007
|
-
this.
|
|
25087
|
+
this.getContext().translate(~~x, ~~y);
|
|
25008
25088
|
} else {
|
|
25009
|
-
this.
|
|
25089
|
+
this.getContext().translate(x, y);
|
|
25010
25090
|
}
|
|
25011
25091
|
};
|
|
25012
25092
|
|
|
@@ -25024,14 +25104,14 @@
|
|
|
25024
25104
|
* @param {number} height
|
|
25025
25105
|
*/
|
|
25026
25106
|
CanvasRenderer.prototype.clipRect = function clipRect (x, y, width, height) {
|
|
25027
|
-
var canvas = this.
|
|
25107
|
+
var canvas = this.getCanvas();
|
|
25028
25108
|
// if requested box is different from the current canvas size;
|
|
25029
25109
|
if (x !== 0 || y !== 0 || width !== canvas.width || height !== canvas.height) {
|
|
25030
25110
|
var currentScissor = this.currentScissor;
|
|
25031
25111
|
// if different from the current scissor box
|
|
25032
25112
|
if (currentScissor[0] !== x || currentScissor[1] !== y ||
|
|
25033
25113
|
currentScissor[2] !== width || currentScissor[3] !== height) {
|
|
25034
|
-
var context = this.
|
|
25114
|
+
var context = this.getContext();
|
|
25035
25115
|
context.beginPath();
|
|
25036
25116
|
context.rect(x, y, width, height);
|
|
25037
25117
|
context.clip();
|
|
@@ -25252,6 +25332,15 @@
|
|
|
25252
25332
|
*/
|
|
25253
25333
|
this.renderorder = data.renderorder || "right-down";
|
|
25254
25334
|
|
|
25335
|
+
/**
|
|
25336
|
+
* the layer class
|
|
25337
|
+
* @public
|
|
25338
|
+
* @type {string}
|
|
25339
|
+
* @name class
|
|
25340
|
+
* @name TMXLayer#class
|
|
25341
|
+
*/
|
|
25342
|
+
this.class = data.class;
|
|
25343
|
+
|
|
25255
25344
|
// for displaying order
|
|
25256
25345
|
this.pos.z = z;
|
|
25257
25346
|
|
|
@@ -26649,6 +26738,14 @@
|
|
|
26649
26738
|
*/
|
|
26650
26739
|
this.isCollection = false;
|
|
26651
26740
|
|
|
26741
|
+
/**
|
|
26742
|
+
* the tileset class
|
|
26743
|
+
* @public
|
|
26744
|
+
* @type {boolean}
|
|
26745
|
+
* @name TMXTileset#class
|
|
26746
|
+
*/
|
|
26747
|
+
this.class = tileset.class;
|
|
26748
|
+
|
|
26652
26749
|
/**
|
|
26653
26750
|
* Tileset animations
|
|
26654
26751
|
* @private
|
|
@@ -27041,20 +27138,31 @@
|
|
|
27041
27138
|
* object type
|
|
27042
27139
|
* @public
|
|
27043
27140
|
* @type {string}
|
|
27141
|
+
* @deprecated since Tiled 1.9
|
|
27142
|
+
* @see https://docs.mapeditor.org/en/stable/reference/tmx-changelog/#tiled-1-9
|
|
27044
27143
|
* @name type
|
|
27045
27144
|
* @memberof TMXObject
|
|
27046
27145
|
*/
|
|
27047
27146
|
this.type = settings.type;
|
|
27048
27147
|
|
|
27148
|
+
/**
|
|
27149
|
+
* the åobject class
|
|
27150
|
+
* @public
|
|
27151
|
+
* @type {string}
|
|
27152
|
+
* @name class
|
|
27153
|
+
* @memberof TMXObject
|
|
27154
|
+
*/
|
|
27155
|
+
this.class = typeof settings.class !== "undefined" ? settings.class : settings.type;
|
|
27156
|
+
|
|
27049
27157
|
/**
|
|
27050
27158
|
* object text
|
|
27051
27159
|
* @public
|
|
27052
27160
|
* @type {object}
|
|
27053
27161
|
* @see http://docs.mapeditor.org/en/stable/reference/tmx-map-format/#text
|
|
27054
|
-
* @name
|
|
27162
|
+
* @name text
|
|
27055
27163
|
* @memberof TMXObject
|
|
27056
27164
|
*/
|
|
27057
|
-
this.
|
|
27165
|
+
this.text = undefined;
|
|
27058
27166
|
|
|
27059
27167
|
/**
|
|
27060
27168
|
* The rotation of the object in radians clockwise (defaults to 0)
|
|
@@ -27309,6 +27417,16 @@
|
|
|
27309
27417
|
*/
|
|
27310
27418
|
this.tintcolor = data.tintcolor;
|
|
27311
27419
|
|
|
27420
|
+
|
|
27421
|
+
/**
|
|
27422
|
+
* the group class
|
|
27423
|
+
* @public
|
|
27424
|
+
* @type {string}
|
|
27425
|
+
* @name class
|
|
27426
|
+
* @memberof TMXGroup
|
|
27427
|
+
*/
|
|
27428
|
+
this.class = data.class;
|
|
27429
|
+
|
|
27312
27430
|
/**
|
|
27313
27431
|
* group z order
|
|
27314
27432
|
* @public
|
|
@@ -27559,6 +27677,16 @@
|
|
|
27559
27677
|
*/
|
|
27560
27678
|
this.tiledversion = data.tiledversion;
|
|
27561
27679
|
|
|
27680
|
+
|
|
27681
|
+
/**
|
|
27682
|
+
* The map class.
|
|
27683
|
+
* @public
|
|
27684
|
+
* @type {string}
|
|
27685
|
+
* @name TMXTileMap#class
|
|
27686
|
+
*/
|
|
27687
|
+
this.class = data.class;
|
|
27688
|
+
|
|
27689
|
+
|
|
27562
27690
|
// tilesets for this map
|
|
27563
27691
|
this.tilesets = null;
|
|
27564
27692
|
|
|
@@ -27898,6 +28026,8 @@
|
|
|
27898
28026
|
obj.anchorPoint.set(0, 0);
|
|
27899
28027
|
obj.name = settings.name;
|
|
27900
28028
|
obj.type = settings.type;
|
|
28029
|
+
// for backward compatibility
|
|
28030
|
+
obj.class = settings.class || settings.type;
|
|
27901
28031
|
obj.id = settings.id;
|
|
27902
28032
|
obj.body = new Body(obj, shape);
|
|
27903
28033
|
obj.body.setStatic(true);
|
|
@@ -30733,7 +30863,7 @@
|
|
|
30733
30863
|
* @memberof WebGLRenderer
|
|
30734
30864
|
* @type {WebGLRenderingContext}
|
|
30735
30865
|
*/
|
|
30736
|
-
this.context = this.gl = this.getContextGL(this.
|
|
30866
|
+
this.context = this.gl = this.getContextGL(this.getCanvas(), options.transparent);
|
|
30737
30867
|
|
|
30738
30868
|
/**
|
|
30739
30869
|
* Maximum number of texture unit supported under the current context
|
|
@@ -30815,13 +30945,13 @@
|
|
|
30815
30945
|
// to simulate context lost and restore in WebGL:
|
|
30816
30946
|
// var ctx = me.video.renderer.context.getExtension('WEBGL_lose_context');
|
|
30817
30947
|
// ctx.loseContext()
|
|
30818
|
-
this.
|
|
30948
|
+
this.getCanvas().addEventListener("webglcontextlost", function (e) {
|
|
30819
30949
|
e.preventDefault();
|
|
30820
30950
|
this$1$1.isContextValid = false;
|
|
30821
30951
|
emit(ONCONTEXT_LOST, this$1$1);
|
|
30822
30952
|
}, false );
|
|
30823
30953
|
// ctx.restoreContext()
|
|
30824
|
-
this.
|
|
30954
|
+
this.getCanvas().addEventListener("webglcontextrestored", function () {
|
|
30825
30955
|
this$1$1.reset();
|
|
30826
30956
|
this$1$1.isContextValid = true;
|
|
30827
30957
|
emit(ONCONTEXT_RESTORED, this$1$1);
|
|
@@ -30900,7 +31030,7 @@
|
|
|
30900
31030
|
*/
|
|
30901
31031
|
WebGLRenderer.prototype.createFontTexture = function createFontTexture (cache) {
|
|
30902
31032
|
if (typeof this.fontTexture === "undefined") {
|
|
30903
|
-
var canvas = this.
|
|
31033
|
+
var canvas = this.getCanvas();
|
|
30904
31034
|
var width = canvas.width;
|
|
30905
31035
|
var height = canvas.height;
|
|
30906
31036
|
|
|
@@ -31131,17 +31261,6 @@
|
|
|
31131
31261
|
this.currentCompositor.addQuad(pattern, x, y, width, height, uvs[0], uvs[1], uvs[2], uvs[3], this.currentTint.toUint32());
|
|
31132
31262
|
};
|
|
31133
31263
|
|
|
31134
|
-
|
|
31135
|
-
/**
|
|
31136
|
-
* return a reference to the screen canvas corresponding WebGL Context
|
|
31137
|
-
* @name getScreenContext
|
|
31138
|
-
* @memberof WebGLRenderer
|
|
31139
|
-
* @returns {WebGLRenderingContext}
|
|
31140
|
-
*/
|
|
31141
|
-
WebGLRenderer.prototype.getScreenContext = function getScreenContext () {
|
|
31142
|
-
return this.gl;
|
|
31143
|
-
};
|
|
31144
|
-
|
|
31145
31264
|
/**
|
|
31146
31265
|
* Returns the WebGL Context object of the given Canvas
|
|
31147
31266
|
* @name getContextGL
|
|
@@ -31302,8 +31421,8 @@
|
|
|
31302
31421
|
this.gl.disable(this.gl.SCISSOR_TEST);
|
|
31303
31422
|
this.currentScissor[0] = 0;
|
|
31304
31423
|
this.currentScissor[1] = 0;
|
|
31305
|
-
this.currentScissor[2] = this.
|
|
31306
|
-
this.currentScissor[3] = this.
|
|
31424
|
+
this.currentScissor[2] = this.getCanvas().width;
|
|
31425
|
+
this.currentScissor[3] = this.getCanvas().height;
|
|
31307
31426
|
}
|
|
31308
31427
|
};
|
|
31309
31428
|
|
|
@@ -31394,7 +31513,7 @@
|
|
|
31394
31513
|
* @param {number} width Line width
|
|
31395
31514
|
*/
|
|
31396
31515
|
WebGLRenderer.prototype.setLineWidth = function setLineWidth (width) {
|
|
31397
|
-
this.
|
|
31516
|
+
this.getContext().lineWidth(width);
|
|
31398
31517
|
};
|
|
31399
31518
|
|
|
31400
31519
|
/**
|
|
@@ -31703,7 +31822,7 @@
|
|
|
31703
31822
|
* @param {number} height
|
|
31704
31823
|
*/
|
|
31705
31824
|
WebGLRenderer.prototype.clipRect = function clipRect (x, y, width, height) {
|
|
31706
|
-
var canvas = this.
|
|
31825
|
+
var canvas = this.getCanvas();
|
|
31707
31826
|
var gl = this.gl;
|
|
31708
31827
|
// if requested box is different from the current canvas size
|
|
31709
31828
|
if (x !== 0 || y !== 0 || width !== canvas.width || height !== canvas.height) {
|
|
@@ -31818,10 +31937,9 @@
|
|
|
31818
31937
|
var settings = {
|
|
31819
31938
|
parent : undefined,
|
|
31820
31939
|
renderer : 2, // AUTO
|
|
31821
|
-
doubleBuffering : false,
|
|
31822
31940
|
autoScale : false,
|
|
31823
31941
|
scale : 1.0,
|
|
31824
|
-
scaleMethod : "
|
|
31942
|
+
scaleMethod : "manual",
|
|
31825
31943
|
transparent : false,
|
|
31826
31944
|
blendMode : "normal",
|
|
31827
31945
|
antiAlias : false,
|
|
@@ -31862,7 +31980,7 @@
|
|
|
31862
31980
|
var canvasMaxHeight = Infinity;
|
|
31863
31981
|
|
|
31864
31982
|
if (globalThis.getComputedStyle) {
|
|
31865
|
-
var style = globalThis.getComputedStyle(renderer.
|
|
31983
|
+
var style = globalThis.getComputedStyle(renderer.getCanvas(), null);
|
|
31866
31984
|
canvasMaxWidth = parseInt(style.maxWidth, 10) || Infinity;
|
|
31867
31985
|
canvasMaxHeight = parseInt(style.maxHeight, 10) || Infinity;
|
|
31868
31986
|
}
|
|
@@ -31916,6 +32034,9 @@
|
|
|
31916
32034
|
|
|
31917
32035
|
// adjust scaling ratio based on the new scaling ratio
|
|
31918
32036
|
scale(scaleX, scaleY);
|
|
32037
|
+
} else {
|
|
32038
|
+
// adjust scaling ratio based on the given settings
|
|
32039
|
+
scale(settings.scale, settings.scale);
|
|
31919
32040
|
}
|
|
31920
32041
|
}
|
|
31921
32042
|
/**
|
|
@@ -31992,7 +32113,6 @@
|
|
|
31992
32113
|
* @param {object} [options] The optional video/renderer parameters.<br> (see Renderer(s) documentation for further specific options)
|
|
31993
32114
|
* @param {string|HTMLElement} [options.parent=document.body] the DOM parent element to hold the canvas in the HTML file
|
|
31994
32115
|
* @param {number} [options.renderer=video.AUTO] renderer to use (me.video.CANVAS, me.video.WEBGL, me.video.AUTO)
|
|
31995
|
-
* @param {boolean} [options.doubleBuffering=false] enable/disable double buffering
|
|
31996
32116
|
* @param {number|string} [options.scale=1.0] enable scaling of the canvas ('auto' for automatic scaling)
|
|
31997
32117
|
* @param {string} [options.scaleMethod="fit"] screen scaling modes ('fit','fill-min','fill-max','flex','flex-width','flex-height','stretch')
|
|
31998
32118
|
* @param {boolean} [options.preferWebGL1=false] if true the renderer will only use WebGL 1
|
|
@@ -32007,8 +32127,7 @@
|
|
|
32007
32127
|
* parent : "screen",
|
|
32008
32128
|
* renderer : me.video.AUTO,
|
|
32009
32129
|
* scale : "auto",
|
|
32010
|
-
* scaleMethod : "fit"
|
|
32011
|
-
* doubleBuffering : true
|
|
32130
|
+
* scaleMethod : "fit"
|
|
32012
32131
|
* });
|
|
32013
32132
|
*/
|
|
32014
32133
|
function init(width, height, options) {
|
|
@@ -32024,7 +32143,6 @@
|
|
|
32024
32143
|
// sanitize potential given parameters
|
|
32025
32144
|
settings.width = width;
|
|
32026
32145
|
settings.height = height;
|
|
32027
|
-
settings.doubleBuffering = !!(settings.doubleBuffering);
|
|
32028
32146
|
settings.transparent = !!(settings.transparent);
|
|
32029
32147
|
settings.antiAlias = !!(settings.antiAlias);
|
|
32030
32148
|
settings.failIfMajorPerformanceCaveat = !!(settings.failIfMajorPerformanceCaveat);
|
|
@@ -32044,24 +32162,21 @@
|
|
|
32044
32162
|
console.log("melonJS 2 (v" + version + ") | http://melonjs.org" );
|
|
32045
32163
|
}
|
|
32046
32164
|
|
|
32047
|
-
// override renderer settings if &webgl is defined in the URL
|
|
32165
|
+
// override renderer settings if &webgl or &canvas is defined in the URL
|
|
32048
32166
|
var uriFragment = utils.getUriFragment();
|
|
32049
32167
|
if (uriFragment.webgl === true || uriFragment.webgl1 === true || uriFragment.webgl2 === true) {
|
|
32050
32168
|
settings.renderer = WEBGL;
|
|
32051
32169
|
if (uriFragment.webgl1 === true) {
|
|
32052
32170
|
settings.preferWebGL1 = true;
|
|
32053
32171
|
}
|
|
32172
|
+
} else if (uriFragment.canvas === true) {
|
|
32173
|
+
settings.renderer = CANVAS;
|
|
32054
32174
|
}
|
|
32055
32175
|
|
|
32056
32176
|
// normalize scale
|
|
32057
32177
|
settings.scale = (settings.autoScale) ? 1.0 : (+settings.scale || 1.0);
|
|
32058
32178
|
scaleRatio.set(settings.scale, settings.scale);
|
|
32059
32179
|
|
|
32060
|
-
// force double buffering if scaling is required
|
|
32061
|
-
if (settings.autoScale || (settings.scale !== 1.0)) {
|
|
32062
|
-
settings.doubleBuffering = true;
|
|
32063
|
-
}
|
|
32064
|
-
|
|
32065
32180
|
// hold the requested video size ratio
|
|
32066
32181
|
designRatio = width / height;
|
|
32067
32182
|
designWidth = width;
|
|
@@ -32133,7 +32248,7 @@
|
|
|
32133
32248
|
|
|
32134
32249
|
// add our canvas (default to document.body if settings.parent is undefined)
|
|
32135
32250
|
parent = getElement(typeof settings.parent !== "undefined" ? settings.parent : document.body);
|
|
32136
|
-
parent.appendChild(renderer.
|
|
32251
|
+
parent.appendChild(renderer.getCanvas());
|
|
32137
32252
|
|
|
32138
32253
|
// Mobile browser hacks
|
|
32139
32254
|
if (platform.isMobile) {
|
|
@@ -32229,8 +32344,8 @@
|
|
|
32229
32344
|
* @param {number} y y scaling multiplier
|
|
32230
32345
|
*/
|
|
32231
32346
|
function scale(x, y) {
|
|
32232
|
-
var canvas = renderer.
|
|
32233
|
-
var context = renderer.
|
|
32347
|
+
var canvas = renderer.getCanvas();
|
|
32348
|
+
var context = renderer.getContext();
|
|
32234
32349
|
var settings = renderer.settings;
|
|
32235
32350
|
var pixelRatio = devicePixelRatio;
|
|
32236
32351
|
|
|
@@ -32990,10 +33105,10 @@
|
|
|
32990
33105
|
* this can be overridden by the plugin
|
|
32991
33106
|
* @public
|
|
32992
33107
|
* @type {string}
|
|
32993
|
-
* @default "13.
|
|
33108
|
+
* @default "13.1.0"
|
|
32994
33109
|
* @name plugin.Base#version
|
|
32995
33110
|
*/
|
|
32996
|
-
this.version = "13.
|
|
33111
|
+
this.version = "13.1.0";
|
|
32997
33112
|
};
|
|
32998
33113
|
|
|
32999
33114
|
/**
|
|
@@ -33993,7 +34108,8 @@
|
|
|
33993
34108
|
var defaultAttributes = {
|
|
33994
34109
|
offscreenCanvas : false,
|
|
33995
34110
|
willReadFrequently : false,
|
|
33996
|
-
antiAlias : false
|
|
34111
|
+
antiAlias : false,
|
|
34112
|
+
context: "2d"
|
|
33997
34113
|
};
|
|
33998
34114
|
|
|
33999
34115
|
/**
|
|
@@ -35663,7 +35779,7 @@
|
|
|
35663
35779
|
this.width = Math.floor(settings.width);
|
|
35664
35780
|
this.height = Math.floor(settings.height);
|
|
35665
35781
|
|
|
35666
|
-
// nine slice sprite specific
|
|
35782
|
+
// nine slice sprite specific internal variables
|
|
35667
35783
|
this.nss_width = this.width;
|
|
35668
35784
|
this.nss_height = this.height;
|
|
35669
35785
|
|
|
@@ -35675,6 +35791,34 @@
|
|
|
35675
35791
|
NineSliceSprite.prototype = Object.create( Sprite && Sprite.prototype );
|
|
35676
35792
|
NineSliceSprite.prototype.constructor = NineSliceSprite;
|
|
35677
35793
|
|
|
35794
|
+
var prototypeAccessors = { width: { configurable: true },height: { configurable: true } };
|
|
35795
|
+
|
|
35796
|
+
/**
|
|
35797
|
+
* width of the NineSliceSprite
|
|
35798
|
+
* @public
|
|
35799
|
+
* @type {number}
|
|
35800
|
+
* @name width
|
|
35801
|
+
*/
|
|
35802
|
+
prototypeAccessors.width.get = function () {
|
|
35803
|
+
return Sprite.prototype.width;
|
|
35804
|
+
};
|
|
35805
|
+
prototypeAccessors.width.set = function (value) {
|
|
35806
|
+
Sprite.prototype.width = this.nss_width = value;
|
|
35807
|
+
};
|
|
35808
|
+
|
|
35809
|
+
/**
|
|
35810
|
+
* height of the NineSliceSprite
|
|
35811
|
+
* @public
|
|
35812
|
+
* @type {number}
|
|
35813
|
+
* @name height
|
|
35814
|
+
*/
|
|
35815
|
+
prototypeAccessors.height.get = function () {
|
|
35816
|
+
return Sprite.prototype.height;
|
|
35817
|
+
};
|
|
35818
|
+
prototypeAccessors.height.set = function (value) {
|
|
35819
|
+
Sprite.prototype.height = this.nss_height = value;
|
|
35820
|
+
};
|
|
35821
|
+
|
|
35678
35822
|
/**
|
|
35679
35823
|
* @ignore
|
|
35680
35824
|
*/
|
|
@@ -35829,6 +35973,8 @@
|
|
|
35829
35973
|
);
|
|
35830
35974
|
};
|
|
35831
35975
|
|
|
35976
|
+
Object.defineProperties( NineSliceSprite.prototype, prototypeAccessors );
|
|
35977
|
+
|
|
35832
35978
|
return NineSliceSprite;
|
|
35833
35979
|
}(Sprite));
|
|
35834
35980
|
|
|
@@ -37579,7 +37725,6 @@
|
|
|
37579
37725
|
}
|
|
37580
37726
|
});
|
|
37581
37727
|
|
|
37582
|
-
|
|
37583
37728
|
/**
|
|
37584
37729
|
* @classdesc
|
|
37585
37730
|
* Used to make a game entity draggable
|
|
@@ -37620,6 +37765,33 @@
|
|
|
37620
37765
|
return DroptargetEntity;
|
|
37621
37766
|
}(DropTarget));
|
|
37622
37767
|
|
|
37768
|
+
/**
|
|
37769
|
+
* return a reference to the screen canvas
|
|
37770
|
+
* @name getScreenCanvas
|
|
37771
|
+
* @memberof Renderer
|
|
37772
|
+
* @returns {HTMLCanvasElement}
|
|
37773
|
+
* @deprecated since 13.1.0
|
|
37774
|
+
* @see getCanvas();
|
|
37775
|
+
*/
|
|
37776
|
+
Renderer.prototype.getScreenCanvas = function() {
|
|
37777
|
+
warning("getScreenCanvas", "getCanvas", "13.1.0");
|
|
37778
|
+
return this.getCanvas();
|
|
37779
|
+
};
|
|
37780
|
+
|
|
37781
|
+
/**
|
|
37782
|
+
* return a reference to the screen canvas corresponding 2d Context<br>
|
|
37783
|
+
* (will return buffered context if double buffering is enabled, or a reference to the Screen Context)
|
|
37784
|
+
* @name getScreenContext
|
|
37785
|
+
* @memberof Renderer
|
|
37786
|
+
* @returns {CanvasRenderingContext2D}
|
|
37787
|
+
* @deprecated since 13.1.0
|
|
37788
|
+
* @see getContext();
|
|
37789
|
+
*/
|
|
37790
|
+
Renderer.prototype.getScreenContext = function() {
|
|
37791
|
+
warning("getScreenContext", "getContext", "13.1.0");
|
|
37792
|
+
return this.getContext();
|
|
37793
|
+
};
|
|
37794
|
+
|
|
37623
37795
|
// ES5/ES6 polyfills
|
|
37624
37796
|
|
|
37625
37797
|
|
|
@@ -37630,7 +37802,7 @@
|
|
|
37630
37802
|
* @name version
|
|
37631
37803
|
* @type {string}
|
|
37632
37804
|
*/
|
|
37633
|
-
var version = "13.
|
|
37805
|
+
var version = "13.1.0";
|
|
37634
37806
|
|
|
37635
37807
|
|
|
37636
37808
|
/**
|