phaser/src/gameobjects/components/BlendMode.js

119 lines
3.3 KiB
JavaScript
Raw Normal View History

2018-02-12 16:01:20 +00:00
/**
* @author Richard Davey <rich@photonstorm.com>
2022-02-28 14:29:51 +00:00
* @copyright 2022 Photon Storm Ltd.
2019-05-10 15:15:04 +00:00
* @license {@link https://opensource.org/licenses/MIT|MIT License}
2018-02-12 16:01:20 +00:00
*/
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
*
2019-02-12 12:48:41 +00:00
* @namespace Phaser.GameObjects.Components.BlendMode
2018-02-01 00:04:45 +00:00
* @since 3.0.0
*/
var BlendMode = {
2018-03-29 12:48:14 +00:00
/**
* Private internal value. Holds the current blend mode.
2022-02-28 14:29:51 +00:00
*
2018-03-29 12:48:14 +00:00
* @name Phaser.GameObjects.Components.BlendMode#_blendMode
2020-11-23 10:22:13 +00:00
* @type {number}
2018-03-29 12:48:14 +00:00
* @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
*
2022-09-29 17:51:16 +00:00
* * NORMAL
2018-02-06 16:15:22 +00:00
* * ADD
* * MULTIPLY
* * SCREEN
2018-11-13 10:31:56 +00:00
* * ERASE
2018-02-06 16:15:22 +00:00
*
* 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
2022-09-29 17:51:16 +00:00
* @type {(Phaser.BlendModes|string|number)}
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 >= -1)
{
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
*
2022-09-29 17:51:16 +00:00
* * NORMAL
2018-02-01 00:04:45 +00:00
* * ADD
* * MULTIPLY
* * SCREEN
2018-11-13 15:10:25 +00:00
* * ERASE (only works when rendering to a framebuffer, like a Render Texture)
2018-02-01 00:04:45 +00:00
*
* 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
2018-11-13 15:10:25 +00:00
* reasons try to be careful about the construction of your Scene and the frequency in which blend modes
2018-02-06 16:15:22 +00:00
* 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
*
2022-09-29 17:51:16 +00:00
* @param {(string|Phaser.BlendModes|number)} value - The BlendMode value. Either a string, a CONST or a number.
2018-03-20 14:56:31 +00:00
*
2018-05-22 04:46:26 +00:00
* @return {this} This Game Object instance.
2018-02-01 00:04:45 +00:00
*/
setBlendMode: function (value)
{
this.blendMode = value;
return this;
}
};
module.exports = BlendMode;