2023-02-14 23:45:44 +00:00
|
|
|
/**
|
|
|
|
* @author Richard Davey <rich@photonstorm.com>
|
|
|
|
* @copyright 2013-2023 Photon Storm Ltd.
|
|
|
|
* @license {@link https://opensource.org/licenses/MIT|MIT License}
|
|
|
|
*/
|
|
|
|
|
|
|
|
var BaseFX = require('./BaseFX');
|
2023-02-16 23:49:14 +00:00
|
|
|
var Class = require('../utils/Class');
|
2023-02-14 23:45:44 +00:00
|
|
|
var FX_CONST = require('./const');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @classdesc
|
|
|
|
*
|
2023-02-15 00:05:33 +00:00
|
|
|
* @class Gradient
|
2023-02-16 23:49:14 +00:00
|
|
|
* @extends Phaser.FX.BaseFX
|
|
|
|
* @memberof Phaser.FX
|
2023-02-14 23:45:44 +00:00
|
|
|
* @constructor
|
|
|
|
* @since 3.60.0
|
|
|
|
*
|
|
|
|
* @param {Phaser.GameObjects.GameObject} gameObject - A reference to the Game Object that has this fx.
|
|
|
|
*/
|
2023-02-15 00:05:33 +00:00
|
|
|
var Gradient = new Class({
|
2023-02-14 23:45:44 +00:00
|
|
|
|
|
|
|
Extends: BaseFX,
|
|
|
|
|
|
|
|
initialize:
|
|
|
|
|
2023-02-16 23:06:53 +00:00
|
|
|
function Gradient (gameObject, color1, color2, alpha, fromX, fromY, toX, toY, size)
|
2023-02-14 23:45:44 +00:00
|
|
|
{
|
2023-02-16 23:06:53 +00:00
|
|
|
if (alpha === undefined) { alpha = 0.2; }
|
|
|
|
if (fromX === undefined) { fromX = 0; }
|
|
|
|
if (fromY === undefined) { fromY = 0; }
|
|
|
|
if (toX === undefined) { toX = 0; }
|
|
|
|
if (toY === undefined) { toY = 1; }
|
|
|
|
if (size === undefined) { size = 0; }
|
|
|
|
|
2023-02-15 00:05:33 +00:00
|
|
|
BaseFX.call(this, FX_CONST.GRADIENT, gameObject);
|
|
|
|
|
2023-02-16 23:06:53 +00:00
|
|
|
this.alpha = alpha;
|
2023-02-15 00:50:31 +00:00
|
|
|
|
|
|
|
// How many 'chunks' the gradient is divided in to, over the entire
|
|
|
|
// height of the texture. Leave at zero for a smoothed gradient.
|
2023-02-16 23:06:53 +00:00
|
|
|
this.size = size;
|
2023-02-15 00:05:33 +00:00
|
|
|
|
2023-02-16 23:06:53 +00:00
|
|
|
this.fromX = fromX;
|
|
|
|
this.fromY = fromY;
|
2023-02-15 00:05:33 +00:00
|
|
|
|
2023-02-16 23:06:53 +00:00
|
|
|
this.toX = toX;
|
|
|
|
this.toY = toY;
|
2023-02-14 23:45:44 +00:00
|
|
|
|
|
|
|
this.glcolor1 = [ 255, 0, 0 ];
|
|
|
|
this.glcolor2 = [ 0, 255, 0 ];
|
2023-02-16 23:06:53 +00:00
|
|
|
|
|
|
|
if (color1 !== undefined && color1 !== null)
|
|
|
|
{
|
|
|
|
this.color1 = color1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (color2 !== undefined && color2 !== null)
|
|
|
|
{
|
|
|
|
this.color2 = color2;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The first gradient color, given as a number value.
|
|
|
|
*
|
2023-02-16 23:49:14 +00:00
|
|
|
* @name Phaser.FX.Gradient#color1
|
2023-02-16 23:06:53 +00:00
|
|
|
* @type {number}
|
|
|
|
* @since 3.60.0
|
|
|
|
*/
|
|
|
|
color1: {
|
|
|
|
|
|
|
|
get: function ()
|
|
|
|
{
|
|
|
|
var color = this.glcolor1;
|
|
|
|
|
|
|
|
return (((color[0] * 255) << 16) + ((color[1] * 255) << 8) + (color[2] * 255 | 0));
|
|
|
|
},
|
|
|
|
|
|
|
|
set: function (value)
|
|
|
|
{
|
|
|
|
var color = this.glcolor1;
|
|
|
|
|
|
|
|
color[0] = ((value >> 16) & 0xFF) / 255;
|
|
|
|
color[1] = ((value >> 8) & 0xFF) / 255;
|
|
|
|
color[2] = (value & 0xFF) / 255;
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The second gradient color, given as a number value.
|
|
|
|
*
|
2023-02-16 23:49:14 +00:00
|
|
|
* @name Phaser.FX.Gradient#color2
|
2023-02-16 23:06:53 +00:00
|
|
|
* @type {number}
|
|
|
|
* @since 3.60.0
|
|
|
|
*/
|
|
|
|
color2: {
|
|
|
|
|
|
|
|
get: function ()
|
|
|
|
{
|
|
|
|
var color = this.glcolor2;
|
|
|
|
|
|
|
|
return (((color[0] * 255) << 16) + ((color[1] * 255) << 8) + (color[2] * 255 | 0));
|
|
|
|
},
|
|
|
|
|
|
|
|
set: function (value)
|
|
|
|
{
|
|
|
|
var color = this.glcolor2;
|
|
|
|
|
|
|
|
color[0] = ((value >> 16) & 0xFF) / 255;
|
|
|
|
color[1] = ((value >> 8) & 0xFF) / 255;
|
|
|
|
color[2] = (value & 0xFF) / 255;
|
|
|
|
}
|
|
|
|
|
2023-02-14 23:45:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2023-02-15 00:05:33 +00:00
|
|
|
module.exports = Gradient;
|