mirror of
https://github.com/photonstorm/phaser
synced 2024-12-26 13:03:36 +00:00
118 lines
3.3 KiB
JavaScript
118 lines
3.3 KiB
JavaScript
/**
|
|
* @author Richard Davey <rich@photonstorm.com>
|
|
* @copyright 2022 Photon Storm Ltd.
|
|
* @license {@link https://opensource.org/licenses/MIT|MIT License}
|
|
*/
|
|
|
|
var BlendModes = require('../../renderer/BlendModes');
|
|
|
|
/**
|
|
* Provides methods used for setting the blend mode of a Game Object.
|
|
* Should be applied as a mixin and not used directly.
|
|
*
|
|
* @namespace Phaser.GameObjects.Components.BlendMode
|
|
* @since 3.0.0
|
|
*/
|
|
|
|
var BlendMode = {
|
|
|
|
/**
|
|
* Private internal value. Holds the current blend mode.
|
|
*
|
|
* @name Phaser.GameObjects.Components.BlendMode#_blendMode
|
|
* @type {number}
|
|
* @private
|
|
* @default 0
|
|
* @since 3.0.0
|
|
*/
|
|
_blendMode: BlendModes.NORMAL,
|
|
|
|
/**
|
|
* 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:
|
|
*
|
|
* * NORMAL
|
|
* * ADD
|
|
* * MULTIPLY
|
|
* * SCREEN
|
|
* * ERASE
|
|
*
|
|
* 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.
|
|
*
|
|
* @name Phaser.GameObjects.Components.BlendMode#blendMode
|
|
* @type {(Phaser.BlendModes|string|number)}
|
|
* @since 3.0.0
|
|
*/
|
|
blendMode: {
|
|
|
|
get: function ()
|
|
{
|
|
return this._blendMode;
|
|
},
|
|
|
|
set: function (value)
|
|
{
|
|
if (typeof value === 'string')
|
|
{
|
|
value = BlendModes[value];
|
|
}
|
|
|
|
value |= 0;
|
|
|
|
if (value >= -1)
|
|
{
|
|
this._blendMode = value;
|
|
}
|
|
}
|
|
|
|
},
|
|
|
|
/**
|
|
* 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:
|
|
*
|
|
* * NORMAL
|
|
* * ADD
|
|
* * MULTIPLY
|
|
* * SCREEN
|
|
* * ERASE (only works when rendering to a framebuffer, like a Render Texture)
|
|
*
|
|
* 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 in which blend modes
|
|
* are used.
|
|
*
|
|
* @method Phaser.GameObjects.Components.BlendMode#setBlendMode
|
|
* @since 3.0.0
|
|
*
|
|
* @param {(string|Phaser.BlendModes|number)} value - The BlendMode value. Either a string, a CONST or a number.
|
|
*
|
|
* @return {this} This Game Object instance.
|
|
*/
|
|
setBlendMode: function (value)
|
|
{
|
|
this.blendMode = value;
|
|
|
|
return this;
|
|
}
|
|
|
|
};
|
|
|
|
module.exports = BlendMode;
|