Skip to content

Commit e1125df

Browse files
committed
Adds invertAlpha flag to GeometryMask
Similiar to the invertAlpha flag on Bitmap Mask this flag if set to true will esentially invert the function of the stencil buffer: non drawn shapes will become invisible and drawn shapes will be visible.
1 parent 61008f4 commit e1125df

1 file changed

Lines changed: 23 additions & 4 deletions

File tree

src/display/mask/GeometryMask.js

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ var Class = require('../../utils/Class');
99
/**
1010
* @classdesc
1111
* A Geometry Mask can be applied to a Game Object to hide any pixels of it which don't intersect a visible pixel from the geometry mask. The mask is essentially a clipping path which can only make a masked pixel fully visible or fully invisible without changing its alpha (opacity).
12-
*
12+
*
1313
* A Geometry Mask uses a Graphics Game Object to determine which pixels of the masked Game Object(s) should be clipped. For any given point of a masked Game Object's texture, the pixel will only be displayed if the Graphics Game Object of the Geometry Mask has a visible pixel at the same position. The color and alpha of the pixel from the Geometry Mask do not matter.
14-
*
14+
*
1515
* The Geometry Mask's location matches the location of its Graphics object, not the location of the masked objects. Moving or transforming the underlying Graphics object will change the mask (and affect the visibility of any masked objects), whereas moving or transforming a masked object will not affect the mask. You can think of the Geometry Mask (or rather, of the its Graphics object) as an invisible curtain placed in front of all masked objects which has its own visual properties and, naturally, respects the camera's visual properties, but isn't affected by and doesn't follow the masked objects by itself.
1616
*
1717
* @class GeometryMask
@@ -36,6 +36,16 @@ var GeometryMask = new Class({
3636
* @since 3.0.0
3737
*/
3838
this.geometryMask = graphicsGeometry;
39+
40+
/**
41+
* Similiar to the BitmapMasks invertAlpha setting this to true will then hide all pixels
42+
* drawn to the Geometry Mask.
43+
*
44+
* @name Phaser.Display.Masks.GeometryMask#invertAlpha
45+
* @type {boolean}
46+
* @since 3.16.0
47+
*/
48+
this.invertAlpha = false;
3949
},
4050

4151
/**
@@ -82,7 +92,16 @@ var GeometryMask = new Class({
8292

8393
// Use stencil buffer to affect next rendering object
8494
gl.colorMask(true, true, true, true);
85-
gl.stencilFunc(gl.EQUAL, 1, 1);
95+
96+
if (this.invertAlpha)
97+
{
98+
gl.stencilFunc(gl.NOTEQUAL, 1, 1);
99+
}
100+
else
101+
{
102+
gl.stencilFunc(gl.EQUAL, 1, 1);
103+
}
104+
86105
gl.stencilOp(gl.KEEP, gl.KEEP, gl.KEEP);
87106
},
88107

@@ -140,7 +159,7 @@ var GeometryMask = new Class({
140159

141160
/**
142161
* Destroys this GeometryMask and nulls any references it holds.
143-
*
162+
*
144163
* Note that if a Game Object is currently using this mask it will _not_ automatically detect you have destroyed it,
145164
* so be sure to call `clearMask` on any Game Object using it, before destroying it.
146165
*

0 commit comments

Comments
 (0)