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 11:01:27 +00:00
|
|
|
var GetColor = function (value)
|
|
|
|
{
|
|
|
|
return (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16);
|
|
|
|
};
|
|
|
|
|
2018-02-01 01:09:34 +00:00
|
|
|
/**
|
|
|
|
* Provides methods used for setting the tint of a Game Object.
|
|
|
|
* Should be applied as a mixin and not used directly.
|
|
|
|
*
|
|
|
|
* @name Phaser.GameObjects.Components.Tint
|
|
|
|
* @webglOnly
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
|
|
|
|
2017-07-04 11:01:27 +00:00
|
|
|
var Tint = {
|
|
|
|
|
|
|
|
// 0: topLeft, 1: topRight, 2: bottomLeft, 3: bottomRight
|
2017-07-05 00:21:47 +00:00
|
|
|
_tintTL: 16777215,
|
|
|
|
_tintTR: 16777215,
|
|
|
|
_tintBL: 16777215,
|
|
|
|
_tintBR: 16777215,
|
2017-07-04 11:01:27 +00:00
|
|
|
|
2018-02-01 01:09:34 +00:00
|
|
|
/**
|
|
|
|
* Clears all tint values associated with this Game Object.
|
|
|
|
* Immediately sets the alpha levels back to 0xffffff (no tint)
|
|
|
|
*
|
2018-02-01 01:36:52 +00:00
|
|
|
* @method Phaser.GameObjects.Components.Tint#clearTint
|
2018-02-01 01:09:34 +00:00
|
|
|
* @webglOnly
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
|
|
|
* @return {Phaser.GameObjects.GameObject} This Game Object instance.
|
|
|
|
*/
|
2017-07-04 11:01:27 +00:00
|
|
|
clearTint: function ()
|
|
|
|
{
|
|
|
|
this.setTint(0xffffff);
|
2017-07-05 00:21:47 +00:00
|
|
|
|
|
|
|
return this;
|
2017-07-04 11:01:27 +00:00
|
|
|
},
|
|
|
|
|
2018-02-01 01:09:34 +00:00
|
|
|
/**
|
|
|
|
* Sets the tint values for this Game Object.
|
|
|
|
*
|
2018-02-01 01:36:52 +00:00
|
|
|
* @method Phaser.GameObjects.Components.Tint#setTint
|
2018-02-01 01:09:34 +00:00
|
|
|
* @webglOnly
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
|
|
|
* @param {integer} [topLeft=0xffffff] - The tint being applied to the top-left of the Game Object. If not other values are given this value is applied evenly, tinting the whole Game Object.
|
|
|
|
* @param {integer} [topRight] - The tint being applied to the top-right of the Game Object.
|
|
|
|
* @param {integer} [bottomLeft] - The tint being applied to the bottom-left of the Game Object.
|
|
|
|
* @param {integer} [bottomRight] - The tint being applied to the bottom-right of the Game Object.
|
|
|
|
*
|
|
|
|
* @return {Phaser.GameObjects.GameObject} This Game Object instance.
|
|
|
|
*/
|
2017-07-04 11:01:27 +00:00
|
|
|
setTint: function (topLeft, topRight, bottomLeft, bottomRight)
|
|
|
|
{
|
2017-07-11 08:38:19 +00:00
|
|
|
if (topLeft === undefined) { topLeft = 0xffffff; }
|
|
|
|
|
2017-07-04 11:01:27 +00:00
|
|
|
if (topRight === undefined)
|
|
|
|
{
|
|
|
|
topRight = topLeft;
|
|
|
|
bottomLeft = topLeft;
|
|
|
|
bottomRight = topLeft;
|
|
|
|
}
|
|
|
|
|
2017-07-05 00:21:47 +00:00
|
|
|
this._tintTL = GetColor(topLeft);
|
|
|
|
this._tintTR = GetColor(topRight);
|
|
|
|
this._tintBL = GetColor(bottomLeft);
|
|
|
|
this._tintBR = GetColor(bottomRight);
|
|
|
|
|
|
|
|
return this;
|
2017-07-04 11:01:27 +00:00
|
|
|
},
|
|
|
|
|
2018-02-01 01:09:34 +00:00
|
|
|
/**
|
|
|
|
* The tint value being applied to the top-left of the Game Object.
|
2018-02-06 16:37:35 +00:00
|
|
|
* This value is interpolated from the corner to the center of the Game Object.
|
2018-02-01 01:09:34 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.GameObjects.Components.Tint#tintTopLeft
|
|
|
|
* @type {integer}
|
|
|
|
* @webglOnly
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-07-04 11:01:27 +00:00
|
|
|
tintTopLeft: {
|
|
|
|
|
|
|
|
get: function ()
|
|
|
|
{
|
2017-07-05 00:21:47 +00:00
|
|
|
return this._tintTL;
|
2017-07-04 11:01:27 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
set: function (value)
|
|
|
|
{
|
2017-07-05 00:21:47 +00:00
|
|
|
this._tintTL = GetColor(value);
|
2017-07-04 11:01:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2018-02-01 01:09:34 +00:00
|
|
|
/**
|
|
|
|
* The tint value being applied to the top-right of the Game Object.
|
2018-02-06 16:37:35 +00:00
|
|
|
* This value is interpolated from the corner to the center of the Game Object.
|
2018-02-01 01:09:34 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.GameObjects.Components.Tint#tintTopRight
|
|
|
|
* @type {integer}
|
|
|
|
* @webglOnly
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-07-04 11:01:27 +00:00
|
|
|
tintTopRight: {
|
|
|
|
|
|
|
|
get: function ()
|
|
|
|
{
|
2017-07-05 00:21:47 +00:00
|
|
|
return this._tintTR;
|
2017-07-04 11:01:27 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
set: function (value)
|
|
|
|
{
|
2017-07-05 00:21:47 +00:00
|
|
|
this._tintTR = GetColor(value);
|
2017-07-04 11:01:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2018-02-01 01:09:34 +00:00
|
|
|
/**
|
|
|
|
* The tint value being applied to the bottom-left of the Game Object.
|
2018-02-06 16:37:35 +00:00
|
|
|
* This value is interpolated from the corner to the center of the Game Object.
|
2018-02-01 01:09:34 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.GameObjects.Components.Tint#tintBottomLeft
|
|
|
|
* @type {integer}
|
|
|
|
* @webglOnly
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-07-04 11:01:27 +00:00
|
|
|
tintBottomLeft: {
|
|
|
|
|
|
|
|
get: function ()
|
|
|
|
{
|
2017-07-05 00:21:47 +00:00
|
|
|
return this._tintBL;
|
2017-07-04 11:01:27 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
set: function (value)
|
|
|
|
{
|
2017-07-05 00:21:47 +00:00
|
|
|
this._tintBL = GetColor(value);
|
2017-07-04 11:01:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2018-02-01 01:09:34 +00:00
|
|
|
/**
|
|
|
|
* The tint value being applied to the bottom-right of the Game Object.
|
2018-02-06 16:37:35 +00:00
|
|
|
* This value is interpolated from the corner to the center of the Game Object.
|
2018-02-01 01:09:34 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.GameObjects.Components.Tint#tintBottomRight
|
|
|
|
* @type {integer}
|
|
|
|
* @webglOnly
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-07-04 11:01:27 +00:00
|
|
|
tintBottomRight: {
|
|
|
|
|
|
|
|
get: function ()
|
|
|
|
{
|
2017-07-05 00:21:47 +00:00
|
|
|
return this._tintBR;
|
2017-07-04 11:01:27 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
set: function (value)
|
|
|
|
{
|
2017-07-05 00:21:47 +00:00
|
|
|
this._tintBR = GetColor(value);
|
2017-07-04 11:01:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2018-02-01 01:09:34 +00:00
|
|
|
/**
|
|
|
|
* The tint value being applied to the whole of the Game Object.
|
|
|
|
*
|
|
|
|
* @name Phaser.GameObjects.Components.Tint#tint
|
|
|
|
* @type {integer}
|
|
|
|
* @webglOnly
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-07-04 11:01:27 +00:00
|
|
|
tint: {
|
|
|
|
|
|
|
|
set: function (value)
|
|
|
|
{
|
|
|
|
this.setTint(value, value, value, value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = Tint;
|