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 Clamp = require('../../math/Clamp');
|
2017-02-23 03:10:48 +00:00
|
|
|
|
2018-02-01 01:36:52 +00:00
|
|
|
// bitmask flag for GameObject.renderMask
|
|
|
|
var _FLAG = 2; // 0010
|
|
|
|
|
2018-01-26 15:37:34 +00:00
|
|
|
/**
|
|
|
|
* Provides methods used for setting the alpha properties of a Game Object.
|
|
|
|
* Should be applied as a mixin and not used directly.
|
|
|
|
*
|
|
|
|
* @name Phaser.GameObjects.Components.Alpha
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-02-23 03:10:48 +00:00
|
|
|
|
|
|
|
var Alpha = {
|
|
|
|
|
2017-02-24 01:45:15 +00:00
|
|
|
_alpha: 1,
|
|
|
|
|
2017-07-25 21:28:02 +00:00
|
|
|
_alphaTL: 1,
|
|
|
|
_alphaTR: 1,
|
|
|
|
_alphaBL: 1,
|
|
|
|
_alphaBR: 1,
|
|
|
|
|
2018-01-26 15:37:34 +00:00
|
|
|
/**
|
2018-02-01 00:04:45 +00:00
|
|
|
* Clears all alpha values associated with this Game Object.
|
|
|
|
* Immediately sets the alpha levels back to 1 (fully opaque)
|
2018-01-26 15:37:34 +00:00
|
|
|
*
|
2018-02-01 01:36:52 +00:00
|
|
|
* @method Phaser.GameObjects.Components.Alpha#clearAlpha
|
2018-01-26 15:37:34 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*
|
|
|
|
* @return {Phaser.GameObjects.GameObject} This Game Object instance.
|
|
|
|
*/
|
2017-07-25 21:28:02 +00:00
|
|
|
clearAlpha: function ()
|
|
|
|
{
|
|
|
|
return this.setAlpha(1);
|
|
|
|
},
|
|
|
|
|
2018-01-26 15:37:34 +00:00
|
|
|
/**
|
2018-02-01 00:04:45 +00:00
|
|
|
* Set the Alpha level of this Game Object. The alpha controls the opacity of the Game Object as it renders.
|
|
|
|
* Alpha values are provided as a float between 0, fully transparent, and 1, fully opaque.
|
|
|
|
*
|
|
|
|
* If your game is running under WebGL you can optionally specify four different alpha values, each of which
|
|
|
|
* correspond to the four corners of the Game Object. Under Canvas only the `topLeft` value given is used.
|
2018-01-26 15:37:34 +00:00
|
|
|
*
|
2018-02-01 01:36:52 +00:00
|
|
|
* @method Phaser.GameObjects.Components.Alpha#setAlpha
|
2018-01-26 15:37:34 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*
|
|
|
|
* @param {float} [topLeft=1] - The alpha value used for the top-left of the Game Object. If this is the only value given it's applied across the whole Game Object.
|
2018-02-01 00:04:45 +00:00
|
|
|
* @param {float} [topRight] - The alpha value used for the top-right of the Game Object. WebGL only.
|
|
|
|
* @param {float} [bottomLeft] - The alpha value used for the bottom-left of the Game Object. WebGL only.
|
|
|
|
* @param {float} [bottomRight] - The alpha value used for the bottom-right of the Game Object. WebGL only.
|
2018-01-26 15:37:34 +00:00
|
|
|
*
|
|
|
|
* @return {Phaser.GameObjects.GameObject} This Game Object instance.
|
|
|
|
*/
|
2017-07-25 21:28:02 +00:00
|
|
|
setAlpha: function (topLeft, topRight, bottomLeft, bottomRight)
|
|
|
|
{
|
|
|
|
if (topLeft === undefined) { topLeft = 1; }
|
|
|
|
|
|
|
|
// Treat as if there is only one alpha value for the whole Game Object
|
|
|
|
if (topRight === undefined)
|
|
|
|
{
|
|
|
|
this.alpha = topLeft;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this._alphaTL = Clamp(topLeft, 0, 1);
|
|
|
|
this._alphaTR = Clamp(topRight, 0, 1);
|
|
|
|
this._alphaBL = Clamp(bottomLeft, 0, 1);
|
|
|
|
this._alphaBR = Clamp(bottomRight, 0, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2018-01-26 15:37:34 +00:00
|
|
|
/**
|
2018-02-06 16:15:22 +00:00
|
|
|
* The alpha value of the Game Object.
|
|
|
|
*
|
|
|
|
* This is a global value, impacting the entire Game Object, not just a region of it.
|
2018-01-26 15:37:34 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.GameObjects.Components.Alpha#alpha
|
2018-02-01 00:04:45 +00:00
|
|
|
* @type {float}
|
2018-01-26 15:37:34 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-02-23 03:10:48 +00:00
|
|
|
alpha: {
|
|
|
|
|
|
|
|
get: function ()
|
|
|
|
{
|
2017-02-24 01:45:15 +00:00
|
|
|
return this._alpha;
|
2017-02-23 03:10:48 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
set: function (value)
|
|
|
|
{
|
2017-07-25 21:28:02 +00:00
|
|
|
var v = Clamp(value, 0, 1);
|
|
|
|
|
|
|
|
this._alpha = v;
|
|
|
|
this._alphaTL = v;
|
|
|
|
this._alphaTR = v;
|
|
|
|
this._alphaBL = v;
|
|
|
|
this._alphaBR = v;
|
2017-02-23 03:10:48 +00:00
|
|
|
|
2017-07-25 21:28:02 +00:00
|
|
|
if (v === 0)
|
2017-02-23 03:10:48 +00:00
|
|
|
{
|
|
|
|
this.renderFlags &= ~_FLAG;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.renderFlags |= _FLAG;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-17 03:37:42 +00:00
|
|
|
},
|
|
|
|
|
2018-01-26 15:37:34 +00:00
|
|
|
/**
|
2018-02-06 16:15:22 +00:00
|
|
|
* The alpha value starting from the top-left of the Game Object.
|
|
|
|
* This value is interpolated from the corner to the center of the Game Object.
|
2018-01-26 15:37:34 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.GameObjects.Components.Alpha#alphaTopLeft
|
2018-02-01 00:04:45 +00:00
|
|
|
* @type {float}
|
2018-01-26 15:37:34 +00:00
|
|
|
* @webglOnly
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-07-25 21:28:02 +00:00
|
|
|
alphaTopLeft: {
|
|
|
|
|
|
|
|
get: function ()
|
|
|
|
{
|
|
|
|
return this._alphaTL;
|
|
|
|
},
|
|
|
|
|
|
|
|
set: function (value)
|
|
|
|
{
|
|
|
|
var v = Clamp(value, 0, 1);
|
|
|
|
|
2018-01-26 15:37:34 +00:00
|
|
|
this._alphaTL = v;
|
2017-07-25 21:28:02 +00:00
|
|
|
|
|
|
|
if (v !== 0)
|
|
|
|
{
|
|
|
|
this.renderFlags |= _FLAG;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2018-01-26 15:37:34 +00:00
|
|
|
/**
|
2018-02-06 16:15:22 +00:00
|
|
|
* The alpha value starting from the top-right of the Game Object.
|
|
|
|
* This value is interpolated from the corner to the center of the Game Object.
|
2018-01-26 15:37:34 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.GameObjects.Components.Alpha#alphaTopRight
|
2018-02-01 00:04:45 +00:00
|
|
|
* @type {float}
|
2018-01-26 15:37:34 +00:00
|
|
|
* @webglOnly
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-07-25 21:28:02 +00:00
|
|
|
alphaTopRight: {
|
|
|
|
|
|
|
|
get: function ()
|
|
|
|
{
|
|
|
|
return this._alphaTR;
|
|
|
|
},
|
|
|
|
|
|
|
|
set: function (value)
|
|
|
|
{
|
|
|
|
var v = Clamp(value, 0, 1);
|
|
|
|
|
2018-01-26 15:37:34 +00:00
|
|
|
this._alphaTR = v;
|
2017-07-25 21:28:02 +00:00
|
|
|
|
|
|
|
if (v !== 0)
|
|
|
|
{
|
|
|
|
this.renderFlags |= _FLAG;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2018-01-26 15:37:34 +00:00
|
|
|
/**
|
2018-02-06 16:15:22 +00:00
|
|
|
* The alpha value starting from the bottom-left of the Game Object.
|
|
|
|
* This value is interpolated from the corner to the center of the Game Object.
|
2018-01-26 15:37:34 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.GameObjects.Components.Alpha#alphaBottomLeft
|
2018-02-01 00:04:45 +00:00
|
|
|
* @type {float}
|
2018-01-26 15:37:34 +00:00
|
|
|
* @webglOnly
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-07-25 21:28:02 +00:00
|
|
|
alphaBottomLeft: {
|
|
|
|
|
|
|
|
get: function ()
|
|
|
|
{
|
|
|
|
return this._alphaBL;
|
|
|
|
},
|
|
|
|
|
|
|
|
set: function (value)
|
|
|
|
{
|
|
|
|
var v = Clamp(value, 0, 1);
|
|
|
|
|
2018-01-26 15:37:34 +00:00
|
|
|
this._alphaBL = v;
|
2017-07-25 21:28:02 +00:00
|
|
|
|
|
|
|
if (v !== 0)
|
|
|
|
{
|
|
|
|
this.renderFlags |= _FLAG;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2018-01-26 15:37:34 +00:00
|
|
|
/**
|
2018-02-06 16:15:22 +00:00
|
|
|
* The alpha value starting from the bottom-right of the Game Object.
|
|
|
|
* This value is interpolated from the corner to the center of the Game Object.
|
2018-01-26 15:37:34 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.GameObjects.Components.Alpha#alphaBottomRight
|
2018-02-01 00:04:45 +00:00
|
|
|
* @type {float}
|
2018-01-26 15:37:34 +00:00
|
|
|
* @webglOnly
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-07-25 21:28:02 +00:00
|
|
|
alphaBottomRight: {
|
|
|
|
|
|
|
|
get: function ()
|
|
|
|
{
|
|
|
|
return this._alphaBR;
|
|
|
|
},
|
|
|
|
|
|
|
|
set: function (value)
|
|
|
|
{
|
|
|
|
var v = Clamp(value, 0, 1);
|
|
|
|
|
2018-01-26 15:37:34 +00:00
|
|
|
this._alphaBR = v;
|
2017-07-25 21:28:02 +00:00
|
|
|
|
|
|
|
if (v !== 0)
|
|
|
|
{
|
|
|
|
this.renderFlags |= _FLAG;
|
|
|
|
}
|
|
|
|
}
|
2017-05-17 03:37:42 +00:00
|
|
|
|
2017-02-23 03:10:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = Alpha;
|