phaser/src/gameobjects/components/BlendMode.js

115 lines
3.2 KiB
JavaScript
Raw Normal View History

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}
*/
var BlendModes = require('../../renderer/BlendModes');
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.
2018-03-20 14:56:31 +00:00
*
2018-02-01 00:04:45 +00:00
* @name Phaser.GameObjects.Components.BlendMode
* @since 3.0.0
*/
var BlendMode = {
2018-03-29 12:48:14 +00:00
/**
* Private internal value. Holds the current blend mode.
*
* @name Phaser.GameObjects.Components.BlendMode#_blendMode
* @type {integer}
* @private
* @default 0
* @since 3.0.0
*/
_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.
2018-03-20 14:56:31 +00:00
*
2018-02-06 16:15:22 +00:00
* This can be a const, such as `Phaser.BlendModes.SCREEN`, or an integer, such as 4 (for Overlay)
2018-03-20 14:56:31 +00:00
*
2018-02-06 16:15:22 +00:00
* Under WebGL only the following Blend Modes are available:
2018-03-20 14:56:31 +00:00
*
2018-02-06 16:15:22 +00:00
* * 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-03-20 14:56:31 +00:00
*
2018-02-01 00:04:45 +00:00
* @name Phaser.GameObjects.Components.BlendMode#blendMode
2018-03-27 12:52:58 +00:00
* @type {(Phaser.BlendModes|string)}
2018-02-01 00:04:45 +00:00
* @since 3.0.0
*/
blendMode: {
get: function ()
{
return this._blendMode;
},
set: function (value)
{
if (typeof value === 'string')
{
value = BlendModes[value];
}
2018-03-17 17:03:30 +00:00
value |= 0;
if (value >= 0)
{
this._blendMode = value;
}
}
},
2018-02-01 00:04:45 +00:00
/**
* Sets the Blend Mode being used by this Game Object.
2018-03-20 14:56:31 +00:00
*
2018-02-01 00:04:45 +00:00
* This can be a const, such as `Phaser.BlendModes.SCREEN`, or an integer, such as 4 (for Overlay)
2018-03-20 14:56:31 +00:00
*
2018-02-01 00:04:45 +00:00
* Under WebGL only the following Blend Modes are available:
2018-03-20 14:56:31 +00:00
*
2018-02-01 00:04:45 +00:00
* * 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-03-20 14:56:31 +00:00
*
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
*
2018-03-27 12:52:58 +00:00
* @param {(string|Phaser.BlendModes)} value - The BlendMode value. Either a string or a CONST.
2018-03-20 14:56:31 +00:00
*
2018-02-01 00:04:45 +00:00
* @return {Phaser.GameObjects.GameObject} This Game Object instance.
*/
setBlendMode: function (value)
{
this.blendMode = value;
return this;
}
};
module.exports = BlendMode;