phaser/src/gameobjects/components/BlendMode.js

106 lines
3 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 = {
_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-20 14:56:31 +00:00
* @type {(integer|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-20 14:56:31 +00:00
* @param {(string|integer)} value - The BlendMode value. Either a string or a CONST.
*
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;