mirror of
https://github.com/photonstorm/phaser
synced 2025-02-17 14:38:30 +00:00
Added new Mask component and added to all relevant Game Objects
This commit is contained in:
parent
9cd2565c6e
commit
606ba6d8d7
13 changed files with 151 additions and 0 deletions
|
@ -41,6 +41,7 @@ var Render = require('./DynamicBitmapTextRender');
|
|||
* @extends Phaser.GameObjects.Components.Alpha
|
||||
* @extends Phaser.GameObjects.Components.BlendMode
|
||||
* @extends Phaser.GameObjects.Components.Depth
|
||||
* @extends Phaser.GameObjects.Components.Mask
|
||||
* @extends Phaser.GameObjects.Components.Origin
|
||||
* @extends Phaser.GameObjects.Components.Pipeline
|
||||
* @extends Phaser.GameObjects.Components.ScrollFactor
|
||||
|
@ -64,6 +65,7 @@ var DynamicBitmapText = new Class({
|
|||
Components.Alpha,
|
||||
Components.BlendMode,
|
||||
Components.Depth,
|
||||
Components.Mask,
|
||||
Components.Origin,
|
||||
Components.Pipeline,
|
||||
Components.ScrollFactor,
|
||||
|
|
|
@ -49,6 +49,7 @@ var Render = require('./BitmapTextRender');
|
|||
* @extends Phaser.GameObjects.Components.Alpha
|
||||
* @extends Phaser.GameObjects.Components.BlendMode
|
||||
* @extends Phaser.GameObjects.Components.Depth
|
||||
* @extends Phaser.GameObjects.Components.Mask
|
||||
* @extends Phaser.GameObjects.Components.Origin
|
||||
* @extends Phaser.GameObjects.Components.Pipeline
|
||||
* @extends Phaser.GameObjects.Components.ScaleMode
|
||||
|
@ -73,6 +74,7 @@ var BitmapText = new Class({
|
|||
Components.Alpha,
|
||||
Components.BlendMode,
|
||||
Components.Depth,
|
||||
Components.Mask,
|
||||
Components.Origin,
|
||||
Components.Pipeline,
|
||||
Components.ScaleMode,
|
||||
|
|
|
@ -44,6 +44,7 @@ var List = require('../../structs/List');
|
|||
* @extends Phaser.GameObjects.Components.Alpha
|
||||
* @extends Phaser.GameObjects.Components.BlendMode
|
||||
* @extends Phaser.GameObjects.Components.Depth
|
||||
* @extends Phaser.GameObjects.Components.Mask
|
||||
* @extends Phaser.GameObjects.Components.Pipeline
|
||||
* @extends Phaser.GameObjects.Components.ScaleMode
|
||||
* @extends Phaser.GameObjects.Components.ScrollFactor
|
||||
|
@ -66,6 +67,7 @@ var Blitter = new Class({
|
|||
Components.Alpha,
|
||||
Components.BlendMode,
|
||||
Components.Depth,
|
||||
Components.Mask,
|
||||
Components.Pipeline,
|
||||
Components.ScaleMode,
|
||||
Components.ScrollFactor,
|
||||
|
|
128
src/gameobjects/components/Mask.js
Normal file
128
src/gameobjects/components/Mask.js
Normal file
|
@ -0,0 +1,128 @@
|
|||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2018 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
*/
|
||||
|
||||
var BitmapMask = require('../../display/mask/BitmapMask');
|
||||
var GeometryMask = require('../../display/mask/GeometryMask');
|
||||
|
||||
/**
|
||||
* Provides methods used for getting and setting the mask of a Game Object.
|
||||
*
|
||||
* @name Phaser.GameObjects.Components.Mask
|
||||
* @since 3.0.0
|
||||
*/
|
||||
|
||||
var Mask = {
|
||||
|
||||
/**
|
||||
* The Mask this Game Object is using during render.
|
||||
*
|
||||
* @name Phaser.GameObjects.Components.Mask#mask
|
||||
* @type {Phaser.Display.Masks.BitmapMask|Phaser.Display.Masks.GeometryMask}
|
||||
* @since 3.0.0
|
||||
*/
|
||||
mask: null,
|
||||
|
||||
/**
|
||||
* Sets the mask that this Game Object will use to render with.
|
||||
*
|
||||
* The mask must have been previously created and can be either a
|
||||
* GeometryMask or a BitmapMask.
|
||||
*
|
||||
* Note: Bitmap Masks only work on WebGL. Geometry Masks work on both WebGL and Canvas.
|
||||
*
|
||||
* If a mask is already set on this Game Object it will be immediately replaced.
|
||||
*
|
||||
* @method Phaser.GameObjects.Components.Mask#setMask
|
||||
* @since 3.6.2
|
||||
*
|
||||
* @param {Phaser.Display.Masks.BitmapMask|Phaser.Display.Masks.GeometryMask} mask - The mask this Game Object will use when rendering.
|
||||
*
|
||||
* @return {Phaser.GameObjects.GameObject} This Game Object instance.
|
||||
*/
|
||||
setMask: function (mask)
|
||||
{
|
||||
this.mask = mask;
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* Clears the mask that this Game Object was using.
|
||||
*
|
||||
* @method Phaser.GameObjects.Components.Mask#clearMask
|
||||
* @since 3.6.2
|
||||
*
|
||||
* @return {Phaser.GameObjects.GameObject} This Game Object instance.
|
||||
*/
|
||||
clearMask: function ()
|
||||
{
|
||||
this.mask = null;
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* Creates and returns a Bitmap Mask. This mask can be used by any Game Object,
|
||||
* including this one.
|
||||
*
|
||||
* To create the mask you need to pass in a reference to a renderable Game Object.
|
||||
* A renderable Game Object is one that uses a texture to render with, such as an
|
||||
* Image, Sprite, Render Texture or BitmapText.
|
||||
*
|
||||
* If you do not provide a renderable object, and this Game Object has a texture,
|
||||
* it will use itself as the object. This means you can call this method to create
|
||||
* a Bitmap Mask from any renderable Game Object.
|
||||
*
|
||||
* @method Phaser.GameObjects.Components.Mask#createBitmapMask
|
||||
* @since 3.6.2
|
||||
*
|
||||
* @param {Phaser.GameObjects.GameObject} [renderable] - A renderable Game Object that uses a texture, such as a Sprite.
|
||||
*
|
||||
* @return {Phaser.Display.Masks.BitmapMask} This Bitmap Mask that was created.
|
||||
*/
|
||||
createBitmapMask: function (renderable)
|
||||
{
|
||||
if (renderable === undefined && this.texture)
|
||||
{
|
||||
// eslint-disable-next-line consistent-this
|
||||
renderable = this;
|
||||
}
|
||||
|
||||
return new BitmapMask(this.scene, renderable);
|
||||
},
|
||||
|
||||
/**
|
||||
* Creates and returns a Geometry Mask. This mask can be used by any Game Object,
|
||||
* including this one.
|
||||
*
|
||||
* To create the mask you need to pass in a reference to a Graphics Game Object.
|
||||
*
|
||||
* If you do not provide a graphics object, and this Game Object is an instance
|
||||
* of a Graphics object, then it will use itself to create the mask.
|
||||
*
|
||||
* This means you can call this method to create a Geometry Mask from any Graphics Game Object.
|
||||
*
|
||||
* @method Phaser.GameObjects.Components.Mask#createGeometryMask
|
||||
* @since 3.6.2
|
||||
*
|
||||
* @param {Phaser.GameObjects.Graphics} [graphics] - A Graphics Game Object. The geometry within it will be used as the mask.
|
||||
*
|
||||
* @return {Phaser.Display.Masks.GeometryMask} This Geometry Mask that was created.
|
||||
*/
|
||||
createGeometryMask: function (graphics)
|
||||
{
|
||||
if (graphics === undefined && this.type === 'Graphics')
|
||||
{
|
||||
// eslint-disable-next-line consistent-this
|
||||
graphics = this;
|
||||
}
|
||||
|
||||
return new GeometryMask(this.scene, graphics);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
module.exports = Mask;
|
|
@ -17,6 +17,7 @@ module.exports = {
|
|||
Depth: require('./Depth'),
|
||||
Flip: require('./Flip'),
|
||||
GetBounds: require('./GetBounds'),
|
||||
Mask: require('./Mask'),
|
||||
MatrixStack: require('./MatrixStack'),
|
||||
Origin: require('./Origin'),
|
||||
Pipeline: require('./Pipeline'),
|
||||
|
|
|
@ -27,6 +27,7 @@ var Render = require('./GraphicsRender');
|
|||
* @extends Phaser.GameObjects.Components.Alpha
|
||||
* @extends Phaser.GameObjects.Components.BlendMode
|
||||
* @extends Phaser.GameObjects.Components.Depth
|
||||
* @extends Phaser.GameObjects.Components.Mask
|
||||
* @extends Phaser.GameObjects.Components.Pipeline
|
||||
* @extends Phaser.GameObjects.Components.Transform
|
||||
* @extends Phaser.GameObjects.Components.Visible
|
||||
|
@ -43,6 +44,7 @@ var Graphics = new Class({
|
|||
Components.Alpha,
|
||||
Components.BlendMode,
|
||||
Components.Depth,
|
||||
Components.Mask,
|
||||
Components.Pipeline,
|
||||
Components.Transform,
|
||||
Components.Visible,
|
||||
|
|
|
@ -29,6 +29,7 @@ var ImageRender = require('./ImageRender');
|
|||
* @extends Phaser.GameObjects.Components.Depth
|
||||
* @extends Phaser.GameObjects.Components.Flip
|
||||
* @extends Phaser.GameObjects.Components.GetBounds
|
||||
* @extends Phaser.GameObjects.Components.Mask
|
||||
* @extends Phaser.GameObjects.Components.Origin
|
||||
* @extends Phaser.GameObjects.Components.Pipeline
|
||||
* @extends Phaser.GameObjects.Components.ScaleMode
|
||||
|
@ -55,6 +56,7 @@ var Image = new Class({
|
|||
Components.Depth,
|
||||
Components.Flip,
|
||||
Components.GetBounds,
|
||||
Components.Mask,
|
||||
Components.Origin,
|
||||
Components.Pipeline,
|
||||
Components.ScaleMode,
|
||||
|
|
|
@ -25,6 +25,7 @@ var MeshRender = require('./MeshRender');
|
|||
* @extends Phaser.GameObjects.Components.Depth
|
||||
* @extends Phaser.GameObjects.Components.Flip
|
||||
* @extends Phaser.GameObjects.Components.GetBounds
|
||||
* @extends Phaser.GameObjects.Components.Mask
|
||||
* @extends Phaser.GameObjects.Components.Origin
|
||||
* @extends Phaser.GameObjects.Components.Pipeline
|
||||
* @extends Phaser.GameObjects.Components.ScaleMode
|
||||
|
@ -54,6 +55,7 @@ var Mesh = new Class({
|
|||
Components.Depth,
|
||||
Components.Flip,
|
||||
Components.GetBounds,
|
||||
Components.Mask,
|
||||
Components.Origin,
|
||||
Components.Pipeline,
|
||||
Components.ScaleMode,
|
||||
|
|
|
@ -44,6 +44,7 @@ var Wrap = require('../../math/Wrap');
|
|||
* @since 3.0.0
|
||||
*
|
||||
* @extends Phaser.GameObjects.Components.BlendMode
|
||||
* @extends Phaser.GameObjects.Components.Mask
|
||||
* @extends Phaser.GameObjects.Components.ScrollFactor
|
||||
* @extends Phaser.GameObjects.Components.Visible
|
||||
*
|
||||
|
@ -54,6 +55,7 @@ var ParticleEmitter = new Class({
|
|||
|
||||
Mixins: [
|
||||
Components.BlendMode,
|
||||
Components.Mask,
|
||||
Components.ScrollFactor,
|
||||
Components.Visible
|
||||
],
|
||||
|
|
|
@ -29,6 +29,7 @@ var RenderTextureWebGL = require('./RenderTextureWebGL');
|
|||
* @extends Phaser.GameObjects.Components.Depth
|
||||
* @extends Phaser.GameObjects.Components.Flip
|
||||
* @extends Phaser.GameObjects.Components.GetBounds
|
||||
* @extends Phaser.GameObjects.Components.Mask
|
||||
* @extends Phaser.GameObjects.Components.MatrixStack
|
||||
* @extends Phaser.GameObjects.Components.Origin
|
||||
* @extends Phaser.GameObjects.Components.Pipeline
|
||||
|
@ -55,6 +56,7 @@ var RenderTexture = new Class({
|
|||
Components.Depth,
|
||||
Components.Flip,
|
||||
Components.GetBounds,
|
||||
Components.Mask,
|
||||
Components.MatrixStack,
|
||||
Components.Origin,
|
||||
Components.Pipeline,
|
||||
|
|
|
@ -32,6 +32,7 @@ var SpriteRender = require('./SpriteRender');
|
|||
* @extends Phaser.GameObjects.Components.Depth
|
||||
* @extends Phaser.GameObjects.Components.Flip
|
||||
* @extends Phaser.GameObjects.Components.GetBounds
|
||||
* @extends Phaser.GameObjects.Components.Mask
|
||||
* @extends Phaser.GameObjects.Components.Origin
|
||||
* @extends Phaser.GameObjects.Components.Pipeline
|
||||
* @extends Phaser.GameObjects.Components.ScaleMode
|
||||
|
@ -58,6 +59,7 @@ var Sprite = new Class({
|
|||
Components.Depth,
|
||||
Components.Flip,
|
||||
Components.GetBounds,
|
||||
Components.Mask,
|
||||
Components.Origin,
|
||||
Components.Pipeline,
|
||||
Components.ScaleMode,
|
||||
|
|
|
@ -32,6 +32,7 @@ var TextStyle = require('../TextStyle');
|
|||
* @extends Phaser.GameObjects.Components.Depth
|
||||
* @extends Phaser.GameObjects.Components.Flip
|
||||
* @extends Phaser.GameObjects.Components.GetBounds
|
||||
* @extends Phaser.GameObjects.Components.Mask
|
||||
* @extends Phaser.GameObjects.Components.Origin
|
||||
* @extends Phaser.GameObjects.Components.Pipeline
|
||||
* @extends Phaser.GameObjects.Components.ScaleMode
|
||||
|
@ -57,6 +58,7 @@ var Text = new Class({
|
|||
Components.Depth,
|
||||
Components.Flip,
|
||||
Components.GetBounds,
|
||||
Components.Mask,
|
||||
Components.Origin,
|
||||
Components.Pipeline,
|
||||
Components.ScaleMode,
|
||||
|
|
|
@ -27,6 +27,7 @@ var TileSpriteRender = require('./TileSpriteRender');
|
|||
* @extends Phaser.GameObjects.Components.Depth
|
||||
* @extends Phaser.GameObjects.Components.Flip
|
||||
* @extends Phaser.GameObjects.Components.GetBounds
|
||||
* @extends Phaser.GameObjects.Components.Mask
|
||||
* @extends Phaser.GameObjects.Components.Origin
|
||||
* @extends Phaser.GameObjects.Components.Pipeline
|
||||
* @extends Phaser.GameObjects.Components.ScaleMode
|
||||
|
@ -55,6 +56,7 @@ var TileSprite = new Class({
|
|||
Components.Depth,
|
||||
Components.Flip,
|
||||
Components.GetBounds,
|
||||
Components.Mask,
|
||||
Components.Origin,
|
||||
Components.Pipeline,
|
||||
Components.ScaleMode,
|
||||
|
|
Loading…
Add table
Reference in a new issue