Skip to content

Commit 606ba6d

Browse files
committed
Added new Mask component and added to all relevant Game Objects
1 parent 9cd2565 commit 606ba6d

13 files changed

Lines changed: 151 additions & 0 deletions

File tree

src/gameobjects/bitmaptext/dynamic/DynamicBitmapText.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ var Render = require('./DynamicBitmapTextRender');
4141
* @extends Phaser.GameObjects.Components.Alpha
4242
* @extends Phaser.GameObjects.Components.BlendMode
4343
* @extends Phaser.GameObjects.Components.Depth
44+
* @extends Phaser.GameObjects.Components.Mask
4445
* @extends Phaser.GameObjects.Components.Origin
4546
* @extends Phaser.GameObjects.Components.Pipeline
4647
* @extends Phaser.GameObjects.Components.ScrollFactor
@@ -64,6 +65,7 @@ var DynamicBitmapText = new Class({
6465
Components.Alpha,
6566
Components.BlendMode,
6667
Components.Depth,
68+
Components.Mask,
6769
Components.Origin,
6870
Components.Pipeline,
6971
Components.ScrollFactor,

src/gameobjects/bitmaptext/static/BitmapText.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ var Render = require('./BitmapTextRender');
4949
* @extends Phaser.GameObjects.Components.Alpha
5050
* @extends Phaser.GameObjects.Components.BlendMode
5151
* @extends Phaser.GameObjects.Components.Depth
52+
* @extends Phaser.GameObjects.Components.Mask
5253
* @extends Phaser.GameObjects.Components.Origin
5354
* @extends Phaser.GameObjects.Components.Pipeline
5455
* @extends Phaser.GameObjects.Components.ScaleMode
@@ -73,6 +74,7 @@ var BitmapText = new Class({
7374
Components.Alpha,
7475
Components.BlendMode,
7576
Components.Depth,
77+
Components.Mask,
7678
Components.Origin,
7779
Components.Pipeline,
7880
Components.ScaleMode,

src/gameobjects/blitter/Blitter.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ var List = require('../../structs/List');
4444
* @extends Phaser.GameObjects.Components.Alpha
4545
* @extends Phaser.GameObjects.Components.BlendMode
4646
* @extends Phaser.GameObjects.Components.Depth
47+
* @extends Phaser.GameObjects.Components.Mask
4748
* @extends Phaser.GameObjects.Components.Pipeline
4849
* @extends Phaser.GameObjects.Components.ScaleMode
4950
* @extends Phaser.GameObjects.Components.ScrollFactor
@@ -66,6 +67,7 @@ var Blitter = new Class({
6667
Components.Alpha,
6768
Components.BlendMode,
6869
Components.Depth,
70+
Components.Mask,
6971
Components.Pipeline,
7072
Components.ScaleMode,
7173
Components.ScrollFactor,

src/gameobjects/components/Mask.js

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
/**
2+
* @author Richard Davey <rich@photonstorm.com>
3+
* @copyright 2018 Photon Storm Ltd.
4+
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
5+
*/
6+
7+
var BitmapMask = require('../../display/mask/BitmapMask');
8+
var GeometryMask = require('../../display/mask/GeometryMask');
9+
10+
/**
11+
* Provides methods used for getting and setting the mask of a Game Object.
12+
*
13+
* @name Phaser.GameObjects.Components.Mask
14+
* @since 3.0.0
15+
*/
16+
17+
var Mask = {
18+
19+
/**
20+
* The Mask this Game Object is using during render.
21+
*
22+
* @name Phaser.GameObjects.Components.Mask#mask
23+
* @type {Phaser.Display.Masks.BitmapMask|Phaser.Display.Masks.GeometryMask}
24+
* @since 3.0.0
25+
*/
26+
mask: null,
27+
28+
/**
29+
* Sets the mask that this Game Object will use to render with.
30+
*
31+
* The mask must have been previously created and can be either a
32+
* GeometryMask or a BitmapMask.
33+
*
34+
* Note: Bitmap Masks only work on WebGL. Geometry Masks work on both WebGL and Canvas.
35+
*
36+
* If a mask is already set on this Game Object it will be immediately replaced.
37+
*
38+
* @method Phaser.GameObjects.Components.Mask#setMask
39+
* @since 3.6.2
40+
*
41+
* @param {Phaser.Display.Masks.BitmapMask|Phaser.Display.Masks.GeometryMask} mask - The mask this Game Object will use when rendering.
42+
*
43+
* @return {Phaser.GameObjects.GameObject} This Game Object instance.
44+
*/
45+
setMask: function (mask)
46+
{
47+
this.mask = mask;
48+
49+
return this;
50+
},
51+
52+
/**
53+
* Clears the mask that this Game Object was using.
54+
*
55+
* @method Phaser.GameObjects.Components.Mask#clearMask
56+
* @since 3.6.2
57+
*
58+
* @return {Phaser.GameObjects.GameObject} This Game Object instance.
59+
*/
60+
clearMask: function ()
61+
{
62+
this.mask = null;
63+
64+
return this;
65+
},
66+
67+
/**
68+
* Creates and returns a Bitmap Mask. This mask can be used by any Game Object,
69+
* including this one.
70+
*
71+
* To create the mask you need to pass in a reference to a renderable Game Object.
72+
* A renderable Game Object is one that uses a texture to render with, such as an
73+
* Image, Sprite, Render Texture or BitmapText.
74+
*
75+
* If you do not provide a renderable object, and this Game Object has a texture,
76+
* it will use itself as the object. This means you can call this method to create
77+
* a Bitmap Mask from any renderable Game Object.
78+
*
79+
* @method Phaser.GameObjects.Components.Mask#createBitmapMask
80+
* @since 3.6.2
81+
*
82+
* @param {Phaser.GameObjects.GameObject} [renderable] - A renderable Game Object that uses a texture, such as a Sprite.
83+
*
84+
* @return {Phaser.Display.Masks.BitmapMask} This Bitmap Mask that was created.
85+
*/
86+
createBitmapMask: function (renderable)
87+
{
88+
if (renderable === undefined && this.texture)
89+
{
90+
// eslint-disable-next-line consistent-this
91+
renderable = this;
92+
}
93+
94+
return new BitmapMask(this.scene, renderable);
95+
},
96+
97+
/**
98+
* Creates and returns a Geometry Mask. This mask can be used by any Game Object,
99+
* including this one.
100+
*
101+
* To create the mask you need to pass in a reference to a Graphics Game Object.
102+
*
103+
* If you do not provide a graphics object, and this Game Object is an instance
104+
* of a Graphics object, then it will use itself to create the mask.
105+
*
106+
* This means you can call this method to create a Geometry Mask from any Graphics Game Object.
107+
*
108+
* @method Phaser.GameObjects.Components.Mask#createGeometryMask
109+
* @since 3.6.2
110+
*
111+
* @param {Phaser.GameObjects.Graphics} [graphics] - A Graphics Game Object. The geometry within it will be used as the mask.
112+
*
113+
* @return {Phaser.Display.Masks.GeometryMask} This Geometry Mask that was created.
114+
*/
115+
createGeometryMask: function (graphics)
116+
{
117+
if (graphics === undefined && this.type === 'Graphics')
118+
{
119+
// eslint-disable-next-line consistent-this
120+
graphics = this;
121+
}
122+
123+
return new GeometryMask(this.scene, graphics);
124+
}
125+
126+
};
127+
128+
module.exports = Mask;

src/gameobjects/components/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ module.exports = {
1717
Depth: require('./Depth'),
1818
Flip: require('./Flip'),
1919
GetBounds: require('./GetBounds'),
20+
Mask: require('./Mask'),
2021
MatrixStack: require('./MatrixStack'),
2122
Origin: require('./Origin'),
2223
Pipeline: require('./Pipeline'),

src/gameobjects/graphics/Graphics.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ var Render = require('./GraphicsRender');
2727
* @extends Phaser.GameObjects.Components.Alpha
2828
* @extends Phaser.GameObjects.Components.BlendMode
2929
* @extends Phaser.GameObjects.Components.Depth
30+
* @extends Phaser.GameObjects.Components.Mask
3031
* @extends Phaser.GameObjects.Components.Pipeline
3132
* @extends Phaser.GameObjects.Components.Transform
3233
* @extends Phaser.GameObjects.Components.Visible
@@ -43,6 +44,7 @@ var Graphics = new Class({
4344
Components.Alpha,
4445
Components.BlendMode,
4546
Components.Depth,
47+
Components.Mask,
4648
Components.Pipeline,
4749
Components.Transform,
4850
Components.Visible,

src/gameobjects/image/Image.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ var ImageRender = require('./ImageRender');
2929
* @extends Phaser.GameObjects.Components.Depth
3030
* @extends Phaser.GameObjects.Components.Flip
3131
* @extends Phaser.GameObjects.Components.GetBounds
32+
* @extends Phaser.GameObjects.Components.Mask
3233
* @extends Phaser.GameObjects.Components.Origin
3334
* @extends Phaser.GameObjects.Components.Pipeline
3435
* @extends Phaser.GameObjects.Components.ScaleMode
@@ -55,6 +56,7 @@ var Image = new Class({
5556
Components.Depth,
5657
Components.Flip,
5758
Components.GetBounds,
59+
Components.Mask,
5860
Components.Origin,
5961
Components.Pipeline,
6062
Components.ScaleMode,

src/gameobjects/mesh/Mesh.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ var MeshRender = require('./MeshRender');
2525
* @extends Phaser.GameObjects.Components.Depth
2626
* @extends Phaser.GameObjects.Components.Flip
2727
* @extends Phaser.GameObjects.Components.GetBounds
28+
* @extends Phaser.GameObjects.Components.Mask
2829
* @extends Phaser.GameObjects.Components.Origin
2930
* @extends Phaser.GameObjects.Components.Pipeline
3031
* @extends Phaser.GameObjects.Components.ScaleMode
@@ -54,6 +55,7 @@ var Mesh = new Class({
5455
Components.Depth,
5556
Components.Flip,
5657
Components.GetBounds,
58+
Components.Mask,
5759
Components.Origin,
5860
Components.Pipeline,
5961
Components.ScaleMode,

src/gameobjects/particles/ParticleEmitter.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ var Wrap = require('../../math/Wrap');
4444
* @since 3.0.0
4545
*
4646
* @extends Phaser.GameObjects.Components.BlendMode
47+
* @extends Phaser.GameObjects.Components.Mask
4748
* @extends Phaser.GameObjects.Components.ScrollFactor
4849
* @extends Phaser.GameObjects.Components.Visible
4950
*
@@ -54,6 +55,7 @@ var ParticleEmitter = new Class({
5455

5556
Mixins: [
5657
Components.BlendMode,
58+
Components.Mask,
5759
Components.ScrollFactor,
5860
Components.Visible
5961
],

src/gameobjects/rendertexture/RenderTexture.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ var RenderTextureWebGL = require('./RenderTextureWebGL');
2929
* @extends Phaser.GameObjects.Components.Depth
3030
* @extends Phaser.GameObjects.Components.Flip
3131
* @extends Phaser.GameObjects.Components.GetBounds
32+
* @extends Phaser.GameObjects.Components.Mask
3233
* @extends Phaser.GameObjects.Components.MatrixStack
3334
* @extends Phaser.GameObjects.Components.Origin
3435
* @extends Phaser.GameObjects.Components.Pipeline
@@ -55,6 +56,7 @@ var RenderTexture = new Class({
5556
Components.Depth,
5657
Components.Flip,
5758
Components.GetBounds,
59+
Components.Mask,
5860
Components.MatrixStack,
5961
Components.Origin,
6062
Components.Pipeline,

0 commit comments

Comments
 (0)