@@ -62,7 +62,6 @@ var BaseCamera = new Class({
6262
6363 Mixins : [
6464 Components . Alpha ,
65- Components . Mask ,
6665 Components . Visible
6766 ] ,
6867
@@ -104,6 +103,15 @@ var BaseCamera = new Class({
104103 */
105104 this . scaleManager ;
106105
106+ /**
107+ * A reference to the Scene's Camera Manager to which this Camera belongs.
108+ *
109+ * @name Phaser.Cameras.Scene2D.BaseCamera#cameraManager
110+ * @type {Phaser.Cameras.Scene2D.CameraManager }
111+ * @since 3.17.0
112+ */
113+ this . cameraManager ;
114+
107115 /**
108116 * The Camera ID. Assigned by the Camera Manager and used to handle camera exclusion.
109117 * This value is a bitmask.
@@ -492,6 +500,30 @@ var BaseCamera = new Class({
492500 * @since 3.12.0
493501 */
494502 this . _customViewport = false ;
503+
504+ /**
505+ * The Mask this Camera is using during render.
506+ * Set the mask using the `setMask` method. Remove the mask using the `clearMask` method.
507+ *
508+ * @name Phaser.Cameras.Scene2D.BaseCamera#mask
509+ * @type {?(Phaser.Display.Masks.BitmapMask|Phaser.Display.Masks.GeometryMask) }
510+ * @since 3.17.0
511+ */
512+ this . mask = null ;
513+
514+ /**
515+ * The Camera that this Camera uses for translation during masking.
516+ *
517+ * If the mask is fixed in position this will be a reference to
518+ * the CameraManager.default instance. Otherwise, it'll be a reference
519+ * to itself.
520+ *
521+ * @name Phaser.Cameras.Scene2D.BaseCamera#_maskCamera
522+ * @type {?Phaser.Cameras.Scene2D.BaseCamera }
523+ * @private
524+ * @since 3.17.0
525+ */
526+ this . _maskCamera = null ;
495527 } ,
496528
497529 /**
@@ -1251,8 +1283,11 @@ var BaseCamera = new Class({
12511283
12521284 this . scene = scene ;
12531285
1254- this . sceneManager = scene . sys . game . scene ;
1255- this . scaleManager = scene . sys . scale ;
1286+ var sys = scene . sys ;
1287+
1288+ this . sceneManager = sys . game . scene ;
1289+ this . scaleManager = sys . scale ;
1290+ this . cameraManager = sys . cameras ;
12561291
12571292 var res = this . scaleManager . resolution ;
12581293
@@ -1380,6 +1415,63 @@ var BaseCamera = new Class({
13801415 return this ;
13811416 } ,
13821417
1418+ /**
1419+ * Sets the mask to be applied to this Camera during rendering.
1420+ *
1421+ * The mask must have been previously created and can be either a GeometryMask or a BitmapMask.
1422+ *
1423+ * Bitmap Masks only work on WebGL. Geometry Masks work on both WebGL and Canvas.
1424+ *
1425+ * If a mask is already set on this Camera it will be immediately replaced.
1426+ *
1427+ * Masks have no impact on physics or input detection. They are purely a rendering component
1428+ * that allows you to limit what is visible during the render pass.
1429+ *
1430+ * Note: You cannot mask a Camera that has `renderToTexture` set.
1431+ *
1432+ * @method Phaser.Cameras.Scene2D.BaseCamera#setMask
1433+ * @since 3.17.0
1434+ *
1435+ * @param {(Phaser.Display.Masks.BitmapMask|Phaser.Display.Masks.GeometryMask) } mask - The mask this Camera will use when rendering.
1436+ * @param {boolean } [fixedPosition=true] - Should the mask translate along with the Camera, or be fixed in place and not impacted by the Cameras transform?
1437+ *
1438+ * @return {this } This Camera instance.
1439+ */
1440+ setMask : function ( mask , fixedPosition )
1441+ {
1442+ if ( fixedPosition === undefined ) { fixedPosition = true ; }
1443+
1444+ this . mask = mask ;
1445+
1446+ this . _maskCamera = ( fixedPosition ) ? this . cameraManager . default : this ;
1447+
1448+ return this ;
1449+ } ,
1450+
1451+ /**
1452+ * Clears the mask that this Camera was using.
1453+ *
1454+ * @method Phaser.Cameras.Scene2D.BaseCamera#clearMask
1455+ * @since 3.17.0
1456+ *
1457+ * @param {boolean } [destroyMask=false] - Destroy the mask before clearing it?
1458+ *
1459+ * @return {this } This Camera instance.
1460+ */
1461+ clearMask : function ( destroyMask )
1462+ {
1463+ if ( destroyMask === undefined ) { destroyMask = false ; }
1464+
1465+ if ( destroyMask && this . mask )
1466+ {
1467+ this . mask . destroy ( ) ;
1468+ }
1469+
1470+ this . mask = null ;
1471+
1472+ return this ;
1473+ } ,
1474+
13831475 /**
13841476 * Sets the visibility of this Camera.
13851477 *
@@ -1512,6 +1604,7 @@ var BaseCamera = new Class({
15121604 this . scene = null ;
15131605 this . scaleManager = null ;
15141606 this . sceneManager = null ;
1607+ this . cameraManager = null ;
15151608 } ,
15161609
15171610 /**
0 commit comments