2018-02-12 16:01:20 +00:00
|
|
|
/**
|
|
|
|
* @author Richard Davey <rich@photonstorm.com>
|
|
|
|
* @copyright 2018 Photon Storm Ltd.
|
|
|
|
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
|
|
|
*/
|
|
|
|
|
2017-07-04 00:59:31 +00:00
|
|
|
var BlendModes = require('../../renderer/BlendModes');
|
2017-02-23 03:10:48 +00:00
|
|
|
|
2018-02-01 00:04:45 +00:00
|
|
|
/**
|
|
|
|
* Provides methods used for setting the blend mode of a Game Object.
|
|
|
|
* Should be applied as a mixin and not used directly.
|
|
|
|
*
|
|
|
|
* @name Phaser.GameObjects.Components.BlendMode
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-02-23 03:10:48 +00:00
|
|
|
|
|
|
|
var BlendMode = {
|
|
|
|
|
2017-02-24 01:45:15 +00:00
|
|
|
_blendMode: BlendModes.NORMAL,
|
|
|
|
|
2018-02-01 00:04:45 +00:00
|
|
|
/**
|
2018-02-06 16:15:22 +00:00
|
|
|
* Sets the Blend Mode being used by this Game Object.
|
|
|
|
*
|
|
|
|
* This can be a const, such as `Phaser.BlendModes.SCREEN`, or an integer, such as 4 (for Overlay)
|
|
|
|
*
|
|
|
|
* Under WebGL only the following Blend Modes are available:
|
|
|
|
*
|
|
|
|
* * ADD
|
|
|
|
* * MULTIPLY
|
|
|
|
* * SCREEN
|
|
|
|
*
|
|
|
|
* Canvas has more available depending on browser support.
|
|
|
|
*
|
|
|
|
* You can also create your own custom Blend Modes in WebGL.
|
|
|
|
*
|
|
|
|
* Blend modes have different effects under Canvas and WebGL, and from browser to browser, depending
|
|
|
|
* on support. Blend Modes also cause a WebGL batch flush should it encounter a new blend mode. For these
|
|
|
|
* reasons try to be careful about the construction of your Scene and the frequency of which blend modes
|
|
|
|
* are used.
|
2018-02-01 00:04:45 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.GameObjects.Components.BlendMode#blendMode
|
|
|
|
* @type {integer|string}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-02-23 03:10:48 +00:00
|
|
|
blendMode: {
|
|
|
|
|
|
|
|
get: function ()
|
|
|
|
{
|
2017-02-24 01:45:15 +00:00
|
|
|
return this._blendMode;
|
2017-02-23 03:10:48 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
set: function (value)
|
|
|
|
{
|
2017-10-20 13:12:58 +00:00
|
|
|
if (typeof value === 'string')
|
|
|
|
{
|
|
|
|
value = BlendModes[value];
|
|
|
|
}
|
|
|
|
|
2017-02-23 03:10:48 +00:00
|
|
|
value | 0;
|
|
|
|
|
2017-08-03 01:09:59 +00:00
|
|
|
if (value >= 0)
|
2017-02-23 03:10:48 +00:00
|
|
|
{
|
2017-02-24 01:45:15 +00:00
|
|
|
this._blendMode = value;
|
2017-02-23 03:10:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-21 02:12:25 +00:00
|
|
|
},
|
|
|
|
|
2018-02-01 00:04:45 +00:00
|
|
|
/**
|
|
|
|
* Sets the Blend Mode being used by this Game Object.
|
|
|
|
*
|
|
|
|
* This can be a const, such as `Phaser.BlendModes.SCREEN`, or an integer, such as 4 (for Overlay)
|
|
|
|
*
|
|
|
|
* Under WebGL only the following Blend Modes are available:
|
|
|
|
*
|
|
|
|
* * ADD
|
|
|
|
* * MULTIPLY
|
|
|
|
* * SCREEN
|
|
|
|
*
|
|
|
|
* Canvas has more available depending on browser support.
|
|
|
|
*
|
|
|
|
* You can also create your own custom Blend Modes in WebGL.
|
|
|
|
*
|
2018-02-06 16:15:22 +00:00
|
|
|
* Blend modes have different effects under Canvas and WebGL, and from browser to browser, depending
|
|
|
|
* on support. Blend Modes also cause a WebGL batch flush should it encounter a new blend mode. For these
|
|
|
|
* reasons try to be careful about the construction of your Scene and the frequency of which blend modes
|
|
|
|
* are used.
|
|
|
|
*
|
2018-02-01 01:36:52 +00:00
|
|
|
* @method Phaser.GameObjects.Components.BlendMode#setBlendMode
|
2018-02-01 00:04:45 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*
|
|
|
|
* @param {string|integer} value - The BlendMode value. Either a string or a CONST.
|
|
|
|
*
|
|
|
|
* @return {Phaser.GameObjects.GameObject} This Game Object instance.
|
|
|
|
*/
|
2017-04-21 02:12:25 +00:00
|
|
|
setBlendMode: function (value)
|
|
|
|
{
|
|
|
|
this.blendMode = value;
|
|
|
|
|
|
|
|
return this;
|
2017-02-23 03:10:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = BlendMode;
|