melonjs 10.6.1 → 10.8.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 +37947 -36530
- package/dist/melonjs.min.js +22 -22
- package/dist/melonjs.module.d.ts +1352 -307
- package/dist/melonjs.module.js +2929 -1501
- package/package.json +14 -12
- package/src/camera/camera2d.js +1 -1
- package/src/entity/entity.js +6 -7
- package/src/game.js +5 -5
- package/src/geometries/ellipse.js +10 -11
- package/src/geometries/line.js +3 -3
- package/src/geometries/path2d.js +319 -0
- package/src/geometries/poly.js +11 -11
- package/src/geometries/rectangle.js +30 -15
- package/src/geometries/roundrect.js +67 -0
- package/src/index.js +9 -5
- package/src/input/gamepad.js +12 -10
- package/src/input/keyboard.js +5 -3
- package/src/input/pointer.js +1 -1
- package/src/input/pointerevent.js +3 -4
- package/src/lang/deprecated.js +1 -1
- package/src/level/tiled/TMXLayer.js +1 -1
- package/src/level/tiled/TMXObject.js +9 -12
- package/src/level/tiled/TMXTileMap.js +23 -4
- package/src/level/tiled/TMXUtils.js +1 -1
- package/src/level/tiled/renderer/TMXHexagonalRenderer.js +1 -1
- package/src/level/tiled/renderer/TMXIsometricRenderer.js +1 -1
- package/src/level/tiled/renderer/TMXOrthogonalRenderer.js +1 -1
- package/src/level/tiled/renderer/TMXRenderer.js +1 -1
- package/src/level/tiled/renderer/TMXStaggeredRenderer.js +1 -1
- package/src/loader/loader.js +5 -5
- package/src/loader/loadingscreen.js +1 -1
- package/src/math/color.js +1 -1
- package/src/math/matrix2.js +1 -1
- package/src/math/matrix3.js +67 -66
- package/src/math/observable_vector2.js +1 -1
- package/src/math/observable_vector3.js +1 -1
- package/src/math/vector2.js +1 -1
- package/src/math/vector3.js +1 -1
- package/src/particles/emitter.js +130 -430
- package/src/particles/particle.js +53 -53
- package/src/particles/settings.js +310 -0
- package/src/physics/body.js +67 -51
- package/src/physics/bounds.js +8 -9
- package/src/physics/world.js +1 -1
- package/src/polyfill/console.js +7 -7
- package/src/polyfill/index.js +7 -0
- package/src/polyfill/performance.js +20 -0
- package/src/polyfill/requestAnimationFrame.js +10 -10
- package/src/renderable/collectable.js +9 -2
- package/src/renderable/colorlayer.js +1 -1
- package/src/renderable/container.js +1 -1
- package/src/renderable/imagelayer.js +3 -3
- package/src/renderable/renderable.js +1 -1
- package/src/renderable/sprite.js +2 -3
- package/src/renderable/trigger.js +10 -4
- package/src/state/stage.js +1 -1
- package/src/state/state.js +8 -8
- package/src/system/device.js +148 -133
- package/src/system/event.js +10 -10
- package/src/system/pooling.js +156 -149
- package/src/system/timer.js +1 -1
- package/src/text/bitmaptext.js +1 -1
- package/src/text/text.js +1 -1
- package/src/utils/agent.js +4 -4
- package/src/utils/function.js +2 -2
- package/src/utils/utils.js +10 -5
- package/src/video/canvas/canvas_renderer.js +104 -36
- package/src/video/renderer.js +28 -16
- package/src/video/texture.js +1 -1
- package/src/video/video.js +11 -11
- package/src/video/webgl/glshader.js +30 -194
- package/src/video/webgl/utils/attributes.js +16 -0
- package/src/video/webgl/utils/precision.js +11 -0
- package/src/video/webgl/utils/program.js +58 -0
- package/src/video/webgl/utils/string.js +16 -0
- package/src/video/webgl/utils/uniforms.js +87 -0
- package/src/video/webgl/webgl_compositor.js +1 -14
- package/src/video/webgl/webgl_renderer.js +129 -186
- package/src/particles/particlecontainer.js +0 -95
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import Color from "./../../math/color.js";
|
|
2
|
-
import Vector2d from "./../../math/vector2.js";
|
|
3
2
|
import Matrix2d from "./../../math/matrix2.js";
|
|
4
3
|
import WebGLCompositor from "./webgl_compositor.js";
|
|
5
4
|
import Renderer from "./../renderer.js";
|
|
@@ -7,8 +6,8 @@ import TextureCache from "./../texture_cache.js";
|
|
|
7
6
|
import { TextureAtlas, createAtlas } from "./../texture.js";
|
|
8
7
|
import { createCanvas, renderer } from "./../video.js";
|
|
9
8
|
import * as event from "./../../system/event.js";
|
|
10
|
-
import
|
|
11
|
-
import { isPowerOfTwo, nextPowerOfTwo
|
|
9
|
+
import pool from "./../../system/pooling.js";
|
|
10
|
+
import { isPowerOfTwo, nextPowerOfTwo } from "./../../math/math.js";
|
|
12
11
|
|
|
13
12
|
|
|
14
13
|
/**
|
|
@@ -41,7 +40,7 @@ class WebGLRenderer extends Renderer {
|
|
|
41
40
|
/**
|
|
42
41
|
* The WebGL version used by this renderer (1 or 2)
|
|
43
42
|
* @name WebGLVersion
|
|
44
|
-
* @memberof WebGLRenderer
|
|
43
|
+
* @memberof WebGLRenderer#
|
|
45
44
|
* @type {number}
|
|
46
45
|
* @default 1
|
|
47
46
|
* @readonly
|
|
@@ -51,7 +50,7 @@ class WebGLRenderer extends Renderer {
|
|
|
51
50
|
/**
|
|
52
51
|
* The vendor string of the underlying graphics driver.
|
|
53
52
|
* @name GPUVendor
|
|
54
|
-
* @memberof WebGLRenderer
|
|
53
|
+
* @memberof WebGLRenderer#
|
|
55
54
|
* @type {string}
|
|
56
55
|
* @default null
|
|
57
56
|
* @readonly
|
|
@@ -61,7 +60,7 @@ class WebGLRenderer extends Renderer {
|
|
|
61
60
|
/**
|
|
62
61
|
* The renderer string of the underlying graphics driver.
|
|
63
62
|
* @name GPURenderer
|
|
64
|
-
* @memberof WebGLRenderer
|
|
63
|
+
* @memberof WebGLRenderer#
|
|
65
64
|
* @type {string}
|
|
66
65
|
* @default null
|
|
67
66
|
* @readonly
|
|
@@ -71,7 +70,7 @@ class WebGLRenderer extends Renderer {
|
|
|
71
70
|
/**
|
|
72
71
|
* The WebGL context
|
|
73
72
|
* @name gl
|
|
74
|
-
* @memberof WebGLRenderer
|
|
73
|
+
* @memberof WebGLRenderer#
|
|
75
74
|
* type {WebGLRenderingContext}
|
|
76
75
|
*/
|
|
77
76
|
this.context = this.gl = this.getContextGL(this.getScreenCanvas(), options.transparent);
|
|
@@ -79,7 +78,7 @@ class WebGLRenderer extends Renderer {
|
|
|
79
78
|
/**
|
|
80
79
|
* Maximum number of texture unit supported under the current context
|
|
81
80
|
* @name maxTextures
|
|
82
|
-
* @memberof WebGLRenderer
|
|
81
|
+
* @memberof WebGLRenderer#
|
|
83
82
|
* @type {number}
|
|
84
83
|
* @readonly
|
|
85
84
|
*/
|
|
@@ -105,16 +104,6 @@ class WebGLRenderer extends Renderer {
|
|
|
105
104
|
*/
|
|
106
105
|
this._blendStack = [];
|
|
107
106
|
|
|
108
|
-
/**
|
|
109
|
-
* @ignore
|
|
110
|
-
*/
|
|
111
|
-
this._glPoints = [
|
|
112
|
-
new Vector2d(),
|
|
113
|
-
new Vector2d(),
|
|
114
|
-
new Vector2d(),
|
|
115
|
-
new Vector2d()
|
|
116
|
-
];
|
|
117
|
-
|
|
118
107
|
/**
|
|
119
108
|
* The current transformation matrix used for transformations on the overall scene
|
|
120
109
|
* @name currentTransform
|
|
@@ -134,7 +123,7 @@ class WebGLRenderer extends Renderer {
|
|
|
134
123
|
/**
|
|
135
124
|
* The list of active compositors
|
|
136
125
|
* @name compositors
|
|
137
|
-
* @type {Map}
|
|
126
|
+
* @type {Map<WebGLCompositor>}
|
|
138
127
|
* @memberof WebGLRenderer#
|
|
139
128
|
*/
|
|
140
129
|
this.compositors = new Map();
|
|
@@ -163,19 +152,19 @@ class WebGLRenderer extends Renderer {
|
|
|
163
152
|
// Create a texture cache
|
|
164
153
|
this.cache = new TextureCache(this.maxTextures);
|
|
165
154
|
|
|
166
|
-
// to simulate context lost and restore :
|
|
155
|
+
// to simulate context lost and restore in WebGL:
|
|
167
156
|
// var ctx = me.video.renderer.context.getExtension('WEBGL_lose_context');
|
|
168
157
|
// ctx.loseContext()
|
|
169
158
|
this.getScreenCanvas().addEventListener("webglcontextlost", (e) => {
|
|
170
159
|
e.preventDefault();
|
|
171
160
|
this.isContextValid = false;
|
|
172
|
-
event.emit(event.
|
|
161
|
+
event.emit(event.ONCONTEXT_LOST, this);
|
|
173
162
|
}, false );
|
|
174
163
|
// ctx.restoreContext()
|
|
175
164
|
this.getScreenCanvas().addEventListener("webglcontextrestored", () => {
|
|
176
165
|
this.reset();
|
|
177
166
|
this.isContextValid = true;
|
|
178
|
-
event.emit(event.
|
|
167
|
+
event.emit(event.ONCONTEXT_RESTORED, this);
|
|
179
168
|
}, false );
|
|
180
169
|
}
|
|
181
170
|
|
|
@@ -570,7 +559,7 @@ class WebGLRenderer extends Renderer {
|
|
|
570
559
|
* <img src="images/normal-blendmode.png" width="510"/> <br>
|
|
571
560
|
* - "multiply" : the pixels of the top layer are multiplied with the corresponding pixel of the bottom layer. A darker picture is the result. <br>
|
|
572
561
|
* <img src="images/multiply-blendmode.png" width="510"/> <br>
|
|
573
|
-
* - "lighter" : where both content overlap the color is determined by adding color values. <br>
|
|
562
|
+
* - "additive or lighter" : where both content overlap the color is determined by adding color values. <br>
|
|
574
563
|
* <img src="images/lighter-blendmode.png" width="510"/> <br>
|
|
575
564
|
* - "screen" : The pixels are inverted, multiplied, and inverted again. A lighter picture is the result (opposite of multiply) <br>
|
|
576
565
|
* <img src="images/screen-blendmode.png" width="510"/> <br>
|
|
@@ -578,7 +567,7 @@ class WebGLRenderer extends Renderer {
|
|
|
578
567
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/globalCompositeOperation
|
|
579
568
|
* @memberof WebGLRenderer.prototype
|
|
580
569
|
* @function
|
|
581
|
-
* @param {string} [mode="normal"] blend mode : "normal", "multiply", "lighter", "screen"
|
|
570
|
+
* @param {string} [mode="normal"] blend mode : "normal", "multiply", "lighter", "additive", "screen"
|
|
582
571
|
* @param {WebGLRenderingContext} [gl]
|
|
583
572
|
*/
|
|
584
573
|
setBlendMode(mode = "normal", gl = this.gl) {
|
|
@@ -594,6 +583,7 @@ class WebGLRenderer extends Renderer {
|
|
|
594
583
|
break;
|
|
595
584
|
|
|
596
585
|
case "lighter" :
|
|
586
|
+
case "additive" :
|
|
597
587
|
gl.blendFunc(gl.ONE, gl.ONE);
|
|
598
588
|
break;
|
|
599
589
|
|
|
@@ -720,6 +710,17 @@ class WebGLRenderer extends Renderer {
|
|
|
720
710
|
this.currentColor.alpha = alpha;
|
|
721
711
|
}
|
|
722
712
|
|
|
713
|
+
/**
|
|
714
|
+
* Return the global alpha
|
|
715
|
+
* @name getGlobalAlpha
|
|
716
|
+
* @memberof WebGLRenderer.prototype
|
|
717
|
+
* @function
|
|
718
|
+
* @returns {number} global alpha value
|
|
719
|
+
*/
|
|
720
|
+
getGlobalAlpha() {
|
|
721
|
+
return this.currentColor.alpha;
|
|
722
|
+
}
|
|
723
|
+
|
|
723
724
|
/**
|
|
724
725
|
* Set the current fill & stroke style color.
|
|
725
726
|
* By default, or upon reset, the value is set to #000000.
|
|
@@ -758,34 +759,18 @@ class WebGLRenderer extends Renderer {
|
|
|
758
759
|
* @param {boolean} [antiClockwise=false] draw arc anti-clockwise
|
|
759
760
|
* @param {boolean} [fill=false]
|
|
760
761
|
*/
|
|
761
|
-
strokeArc(x, y, radius, start, end, antiClockwise = false, fill) {
|
|
762
|
-
if (
|
|
763
|
-
|
|
762
|
+
strokeArc(x, y, radius, start, end, antiClockwise = false, fill = false) {
|
|
763
|
+
if (this.getGlobalAlpha() < 1 / 255) {
|
|
764
|
+
// Fast path: don't draw fully transparent
|
|
765
|
+
return;
|
|
766
|
+
}
|
|
767
|
+
this.path2D.beginPath();
|
|
768
|
+
this.path2D.arc(x, y, radius, start, end, antiClockwise);
|
|
769
|
+
if (fill === false) {
|
|
770
|
+
this.currentCompositor.drawVertices(this.gl.LINE_STRIP, this.path2D.points);
|
|
764
771
|
} else {
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
var i, len = Math.floor(24 * Math.sqrt(radius * 2));
|
|
768
|
-
var theta = (end - start) / (len * 2);
|
|
769
|
-
var theta2 = theta * 2;
|
|
770
|
-
var cos_theta = Math.cos(theta);
|
|
771
|
-
var sin_theta = Math.sin(theta);
|
|
772
|
-
|
|
773
|
-
// Grow internal points buffer if necessary
|
|
774
|
-
for (i = points.length; i < len + 1; i++) {
|
|
775
|
-
points.push(new Vector2d());
|
|
776
|
-
}
|
|
777
|
-
|
|
778
|
-
// calculate and draw all segments
|
|
779
|
-
for (i = 0; i < len; i++) {
|
|
780
|
-
var angle = ((theta) + start + (theta2 * i));
|
|
781
|
-
var cos = Math.cos(angle);
|
|
782
|
-
var sin = -Math.sin(angle);
|
|
783
|
-
|
|
784
|
-
points[i].x = x + (((cos_theta * cos) + (sin_theta * sin)) * radius);
|
|
785
|
-
points[i].y = y + (((cos_theta * -sin) + (sin_theta * cos)) * radius);
|
|
786
|
-
}
|
|
787
|
-
// batch draw all lines
|
|
788
|
-
this.currentCompositor.drawVertices(this.gl.LINE_STRIP, points, len);
|
|
772
|
+
this.path2D.closePath();
|
|
773
|
+
this.currentCompositor.drawVertices(this.gl.TRIANGLES, this.path2D.triangulatePath());
|
|
789
774
|
}
|
|
790
775
|
}
|
|
791
776
|
|
|
@@ -801,35 +786,8 @@ class WebGLRenderer extends Renderer {
|
|
|
801
786
|
* @param {number} end end angle in radians
|
|
802
787
|
* @param {boolean} [antiClockwise=false] draw arc anti-clockwise
|
|
803
788
|
*/
|
|
804
|
-
fillArc(x, y, radius, start, end
|
|
805
|
-
|
|
806
|
-
var points = this._glPoints;
|
|
807
|
-
var i, index = 0;
|
|
808
|
-
var len = Math.floor(24 * Math.sqrt(radius * 2));
|
|
809
|
-
var theta = (end - start) / (len * 2);
|
|
810
|
-
var theta2 = theta * 2;
|
|
811
|
-
var cos_theta = Math.cos(theta);
|
|
812
|
-
var sin_theta = Math.sin(theta);
|
|
813
|
-
|
|
814
|
-
// Grow internal points buffer if necessary
|
|
815
|
-
for (i = points.length; i < len * 2; i++) {
|
|
816
|
-
points.push(new Vector2d());
|
|
817
|
-
}
|
|
818
|
-
|
|
819
|
-
// calculate and draw all segments
|
|
820
|
-
for (i = 0; i < len - 1; i++) {
|
|
821
|
-
var angle = ((theta) + start + (theta2 * i));
|
|
822
|
-
var cos = Math.cos(angle);
|
|
823
|
-
var sin = -Math.sin(angle);
|
|
824
|
-
|
|
825
|
-
points[index++].set(x, y);
|
|
826
|
-
points[index++].set(
|
|
827
|
-
x - (((cos_theta * cos) + (sin_theta * sin)) * radius),
|
|
828
|
-
y - (((cos_theta * -sin) + (sin_theta * cos)) * radius)
|
|
829
|
-
);
|
|
830
|
-
}
|
|
831
|
-
// batch draw all triangles
|
|
832
|
-
this.currentCompositor.drawVertices(this.gl.TRIANGLE_STRIP, points, index);
|
|
789
|
+
fillArc(x, y, radius, start, end, antiClockwise = false) {
|
|
790
|
+
this.strokeArc(x, y, radius, start, end, antiClockwise, true);
|
|
833
791
|
}
|
|
834
792
|
|
|
835
793
|
/**
|
|
@@ -844,28 +802,17 @@ class WebGLRenderer extends Renderer {
|
|
|
844
802
|
* @param {boolean} [fill=false] also fill the shape with the current color if true
|
|
845
803
|
*/
|
|
846
804
|
strokeEllipse(x, y, w, h, fill = false) {
|
|
847
|
-
if (
|
|
848
|
-
|
|
805
|
+
if (this.getGlobalAlpha() < 1 / 255) {
|
|
806
|
+
// Fast path: don't draw fully transparent
|
|
807
|
+
return;
|
|
808
|
+
}
|
|
809
|
+
this.path2D.beginPath();
|
|
810
|
+
this.path2D.ellipse(x, y, w, h, 0, 0, 360);
|
|
811
|
+
this.path2D.closePath();
|
|
812
|
+
if (fill === false) {
|
|
813
|
+
this.currentCompositor.drawVertices(this.gl.LINE_LOOP, this.path2D.points);
|
|
849
814
|
} else {
|
|
850
|
-
|
|
851
|
-
var len = Math.floor(24 * Math.sqrt(w)) ||
|
|
852
|
-
Math.floor(12 * Math.sqrt(w + h));
|
|
853
|
-
var segment = (TAU) / len;
|
|
854
|
-
var points = this._glPoints,
|
|
855
|
-
i;
|
|
856
|
-
|
|
857
|
-
// Grow internal points buffer if necessary
|
|
858
|
-
for (i = points.length; i < len; i++) {
|
|
859
|
-
points.push(new Vector2d());
|
|
860
|
-
}
|
|
861
|
-
|
|
862
|
-
// calculate and draw all segments
|
|
863
|
-
for (i = 0; i < len; i++) {
|
|
864
|
-
points[i].x = x + (Math.sin(segment * -i) * w);
|
|
865
|
-
points[i].y = y + (Math.cos(segment * -i) * h);
|
|
866
|
-
}
|
|
867
|
-
// batch draw all lines
|
|
868
|
-
this.currentCompositor.drawVertices(this.gl.LINE_LOOP, points, len);
|
|
815
|
+
this.currentCompositor.drawVertices(this.gl.TRIANGLES, this.path2D.triangulatePath());
|
|
869
816
|
}
|
|
870
817
|
}
|
|
871
818
|
|
|
@@ -880,28 +827,7 @@ class WebGLRenderer extends Renderer {
|
|
|
880
827
|
* @param {number} h vertical radius of the ellipse
|
|
881
828
|
*/
|
|
882
829
|
fillEllipse(x, y, w, h) {
|
|
883
|
-
|
|
884
|
-
var len = Math.floor(24 * Math.sqrt(w)) ||
|
|
885
|
-
Math.floor(12 * Math.sqrt(w + h));
|
|
886
|
-
var segment = (TAU) / len;
|
|
887
|
-
var points = this._glPoints;
|
|
888
|
-
var index = 0, i;
|
|
889
|
-
|
|
890
|
-
// Grow internal points buffer if necessary
|
|
891
|
-
for (i = points.length; i < (len + 1) * 2; i++) {
|
|
892
|
-
points.push(new Vector2d());
|
|
893
|
-
}
|
|
894
|
-
|
|
895
|
-
// draw all vertices vertex coordinates
|
|
896
|
-
for (i = 0; i < len + 1; i++) {
|
|
897
|
-
points[index++].set(x, y);
|
|
898
|
-
points[index++].set(
|
|
899
|
-
x + (Math.sin(segment * i) * w),
|
|
900
|
-
y + (Math.cos(segment * i) * h)
|
|
901
|
-
);
|
|
902
|
-
}
|
|
903
|
-
// batch draw all triangles
|
|
904
|
-
this.currentCompositor.drawVertices(this.gl.TRIANGLE_STRIP, points, index);
|
|
830
|
+
this.strokeEllipse(x, y, w, h, false);
|
|
905
831
|
}
|
|
906
832
|
|
|
907
833
|
/**
|
|
@@ -915,12 +841,14 @@ class WebGLRenderer extends Renderer {
|
|
|
915
841
|
* @param {number} endY the end y coordinate
|
|
916
842
|
*/
|
|
917
843
|
strokeLine(startX, startY, endX, endY) {
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
this.
|
|
844
|
+
if (this.getGlobalAlpha() < 1 / 255) {
|
|
845
|
+
// Fast path: don't draw fully transparent
|
|
846
|
+
return;
|
|
847
|
+
}
|
|
848
|
+
this.path2D.beginPath();
|
|
849
|
+
this.path2D.moveTo(startX, startY);
|
|
850
|
+
this.path2D.lineTo(endX, endY);
|
|
851
|
+
this.currentCompositor.drawVertices(this.gl.LINE_STRIP, this.path2D.points);
|
|
924
852
|
}
|
|
925
853
|
|
|
926
854
|
|
|
@@ -947,25 +875,27 @@ class WebGLRenderer extends Renderer {
|
|
|
947
875
|
* @param {boolean} [fill=false] also fill the shape with the current color if true
|
|
948
876
|
*/
|
|
949
877
|
strokePolygon(poly, fill = false) {
|
|
950
|
-
if (
|
|
951
|
-
|
|
878
|
+
if (this.getGlobalAlpha() < 1 / 255) {
|
|
879
|
+
// Fast path: don't draw fully transparent
|
|
880
|
+
return;
|
|
881
|
+
}
|
|
882
|
+
this.translate(poly.pos.x, poly.pos.y);
|
|
883
|
+
this.path2D.beginPath();
|
|
884
|
+
this.path2D.moveTo(poly.points[0].x, poly.points[0].y);
|
|
885
|
+
var point;
|
|
886
|
+
for (var i = 1; i < poly.points.length; i++) {
|
|
887
|
+
point = poly.points[i];
|
|
888
|
+
this.path2D.lineTo(point.x, point.y);
|
|
889
|
+
}
|
|
890
|
+
this.path2D.lineTo(poly.points[0].x, poly.points[0].y);
|
|
891
|
+
this.path2D.closePath();
|
|
892
|
+
if (fill === false) {
|
|
893
|
+
this.currentCompositor.drawVertices(this.gl.LINE_LOOP, this.path2D.points);
|
|
952
894
|
} else {
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
i;
|
|
956
|
-
|
|
957
|
-
// Grow internal points buffer if necessary
|
|
958
|
-
for (i = points.length; i < len; i++) {
|
|
959
|
-
points.push(new Vector2d());
|
|
960
|
-
}
|
|
961
|
-
|
|
962
|
-
// calculate and draw all segments
|
|
963
|
-
for (i = 0; i < len; i++) {
|
|
964
|
-
points[i].x = poly.pos.x + poly.points[i].x;
|
|
965
|
-
points[i].y = poly.pos.y + poly.points[i].y;
|
|
966
|
-
}
|
|
967
|
-
this.currentCompositor.drawVertices(this.gl.LINE_LOOP, points, len);
|
|
895
|
+
// draw all triangles
|
|
896
|
+
this.currentCompositor.drawVertices(this.gl.TRIANGLES, this.path2D.triangulatePath());
|
|
968
897
|
}
|
|
898
|
+
this.translate(-poly.pos.x, -poly.pos.y);
|
|
969
899
|
}
|
|
970
900
|
|
|
971
901
|
/**
|
|
@@ -976,24 +906,7 @@ class WebGLRenderer extends Renderer {
|
|
|
976
906
|
* @param {Polygon} poly the shape to draw
|
|
977
907
|
*/
|
|
978
908
|
fillPolygon(poly) {
|
|
979
|
-
|
|
980
|
-
var glPoints = this._glPoints;
|
|
981
|
-
var indices = poly.getIndices();
|
|
982
|
-
var x = poly.pos.x, y = poly.pos.y;
|
|
983
|
-
var i;
|
|
984
|
-
|
|
985
|
-
// Grow internal points buffer if necessary
|
|
986
|
-
for (i = glPoints.length; i < indices.length; i++) {
|
|
987
|
-
glPoints.push(new Vector2d());
|
|
988
|
-
}
|
|
989
|
-
|
|
990
|
-
// calculate all vertices
|
|
991
|
-
for (i = 0; i < indices.length; i++ ) {
|
|
992
|
-
glPoints[i].set(x + points[indices[i]].x, y + points[indices[i]].y);
|
|
993
|
-
}
|
|
994
|
-
|
|
995
|
-
// draw all triangle
|
|
996
|
-
this.currentCompositor.drawVertices(this.gl.TRIANGLES, glPoints, indices.length);
|
|
909
|
+
this.strokePolygon(poly, true);
|
|
997
910
|
}
|
|
998
911
|
|
|
999
912
|
/**
|
|
@@ -1008,19 +921,16 @@ class WebGLRenderer extends Renderer {
|
|
|
1008
921
|
* @param {boolean} [fill=false] also fill the shape with the current color if true
|
|
1009
922
|
*/
|
|
1010
923
|
strokeRect(x, y, width, height, fill = false) {
|
|
1011
|
-
if (
|
|
1012
|
-
|
|
924
|
+
if (this.getGlobalAlpha() < 1 / 255) {
|
|
925
|
+
// Fast path: don't draw fully transparent
|
|
926
|
+
return;
|
|
927
|
+
}
|
|
928
|
+
this.path2D.beginPath();
|
|
929
|
+
this.path2D.rect(x, y, width, height);
|
|
930
|
+
if (fill === false) {
|
|
931
|
+
this.currentCompositor.drawVertices(this.gl.LINE_LOOP, this.path2D.points);
|
|
1013
932
|
} else {
|
|
1014
|
-
|
|
1015
|
-
points[0].x = x;
|
|
1016
|
-
points[0].y = y;
|
|
1017
|
-
points[1].x = x + width;
|
|
1018
|
-
points[1].y = y;
|
|
1019
|
-
points[2].x = x + width;
|
|
1020
|
-
points[2].y = y + height;
|
|
1021
|
-
points[3].x = x;
|
|
1022
|
-
points[3].y = y + height;
|
|
1023
|
-
this.currentCompositor.drawVertices(this.gl.LINE_LOOP, points, 4);
|
|
933
|
+
this.currentCompositor.drawVertices(this.gl.TRIANGLES, this.path2D.triangulatePath());
|
|
1024
934
|
}
|
|
1025
935
|
}
|
|
1026
936
|
|
|
@@ -1035,16 +945,49 @@ class WebGLRenderer extends Renderer {
|
|
|
1035
945
|
* @param {number} height
|
|
1036
946
|
*/
|
|
1037
947
|
fillRect(x, y, width, height) {
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
948
|
+
this.strokeRect(x, y, width, height, true);
|
|
949
|
+
}
|
|
950
|
+
|
|
951
|
+
/**
|
|
952
|
+
* Stroke a rounded rectangle at the specified coordinates
|
|
953
|
+
* @name strokeRoundRect
|
|
954
|
+
* @memberof WebGLRenderer.prototype
|
|
955
|
+
* @function
|
|
956
|
+
* @param {number} x
|
|
957
|
+
* @param {number} y
|
|
958
|
+
* @param {number} width
|
|
959
|
+
* @param {number} height
|
|
960
|
+
* @param {number} radius
|
|
961
|
+
* @param {boolean} [fill=false] also fill the shape with the current color if true
|
|
962
|
+
*/
|
|
963
|
+
strokeRoundRect(x, y, width, height, radius, fill = false) {
|
|
964
|
+
if (this.getGlobalAlpha() < 1 / 255) {
|
|
965
|
+
// Fast path: don't draw fully transparent
|
|
966
|
+
return;
|
|
967
|
+
}
|
|
968
|
+
this.path2D.beginPath();
|
|
969
|
+
this.path2D.roundRect(x, y, width, height, radius);
|
|
970
|
+
if (fill === false) {
|
|
971
|
+
this.currentCompositor.drawVertices(this.gl.LINE_LOOP, this.path2D.points);
|
|
972
|
+
} else {
|
|
973
|
+
this.path2D.closePath();
|
|
974
|
+
this.currentCompositor.drawVertices(this.gl.TRIANGLES, this.path2D.triangulatePath());
|
|
975
|
+
}
|
|
976
|
+
}
|
|
977
|
+
|
|
978
|
+
/**
|
|
979
|
+
* Draw a rounded filled rectangle at the specified coordinates
|
|
980
|
+
* @name fillRoundRect
|
|
981
|
+
* @memberof WebGLRenderer.prototype
|
|
982
|
+
* @function
|
|
983
|
+
* @param {number} x
|
|
984
|
+
* @param {number} y
|
|
985
|
+
* @param {number} width
|
|
986
|
+
* @param {number} height
|
|
987
|
+
* @param {number} radius
|
|
988
|
+
*/
|
|
989
|
+
fillRoundRect(x, y, width, height, radius) {
|
|
990
|
+
this.strokeRoundRect(x, y, width, height, radius, true);
|
|
1048
991
|
}
|
|
1049
992
|
|
|
1050
993
|
/**
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
import Container from "./../renderable/container.js";
|
|
2
|
-
import { viewport } from "./../game.js";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* @classdesc
|
|
6
|
-
* Particle Container Object.
|
|
7
|
-
* @class ParticleContainer
|
|
8
|
-
* @augments Container
|
|
9
|
-
* @param {ParticleEmitter} emitter the emitter which owns this container
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
class ParticleContainer extends Container {
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* @ignore
|
|
16
|
-
*/
|
|
17
|
-
constructor(emitter) {
|
|
18
|
-
// call the super constructor
|
|
19
|
-
super(
|
|
20
|
-
viewport.pos.x,
|
|
21
|
-
viewport.pos.y,
|
|
22
|
-
viewport.width,
|
|
23
|
-
viewport.height
|
|
24
|
-
);
|
|
25
|
-
|
|
26
|
-
// don't sort the particles by z-index
|
|
27
|
-
this.autoSort = false;
|
|
28
|
-
|
|
29
|
-
// count the updates
|
|
30
|
-
this._updateCount = 0;
|
|
31
|
-
|
|
32
|
-
// internally store how much time was skipped when frames are skipped
|
|
33
|
-
this._dt = 0;
|
|
34
|
-
|
|
35
|
-
// cache the emitter for later use
|
|
36
|
-
this._emitter = emitter;
|
|
37
|
-
|
|
38
|
-
this.autoTransform = false;
|
|
39
|
-
|
|
40
|
-
this.anchorPoint.set(0, 0);
|
|
41
|
-
|
|
42
|
-
this.isKinematic = true;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* @ignore
|
|
47
|
-
*/
|
|
48
|
-
update(dt) {
|
|
49
|
-
// skip frames if necessary
|
|
50
|
-
if (++this._updateCount > this._emitter.framesToSkip) {
|
|
51
|
-
this._updateCount = 0;
|
|
52
|
-
}
|
|
53
|
-
if (this._updateCount > 0) {
|
|
54
|
-
this._dt += dt;
|
|
55
|
-
return false;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// apply skipped delta time
|
|
59
|
-
dt += this._dt;
|
|
60
|
-
this._dt = 0;
|
|
61
|
-
|
|
62
|
-
// Update particles and remove them if they are dead
|
|
63
|
-
for (var i = this.children.length - 1; i >= 0; --i) {
|
|
64
|
-
var particle = this.children[i];
|
|
65
|
-
particle.inViewport = viewport.isVisible(particle, this.floating);
|
|
66
|
-
if (!particle.update(dt)) {
|
|
67
|
-
this.removeChildNow(particle);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
return true;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* @ignore
|
|
75
|
-
*/
|
|
76
|
-
draw(renderer, rect) {
|
|
77
|
-
if (this.children.length > 0) {
|
|
78
|
-
var context = renderer.getContext(),
|
|
79
|
-
gco;
|
|
80
|
-
// Check for additive draw
|
|
81
|
-
if (this._emitter.textureAdditive) {
|
|
82
|
-
gco = context.globalCompositeOperation;
|
|
83
|
-
context.globalCompositeOperation = "lighter";
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
super.draw(renderer, rect);
|
|
87
|
-
|
|
88
|
-
// Restore globalCompositeOperation
|
|
89
|
-
if (this._emitter.textureAdditive) {
|
|
90
|
-
context.globalCompositeOperation = gco;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
};
|
|
95
|
-
export default ParticleContainer;
|