-
Notifications
You must be signed in to change notification settings - Fork 7.1k
/
Glow.js
128 lines (109 loc) · 3.55 KB
/
Glow.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2013-2023 Photon Storm Ltd.
* @license {@link https://opensource.org/licenses/MIT|MIT License}
*/
var Class = require('../utils/Class');
var Controller = require('./Controller');
var FX_CONST = require('./const');
/**
* @classdesc
* The Glow FX Controller.
*
* This FX controller manages the glow effect for a Game Object.
*
* The glow effect is a visual technique that creates a soft, luminous halo around game objects,
* characters, or UI elements. This effect is used to emphasize importance, enhance visual appeal,
* or convey a sense of energy, magic, or otherworldly presence. The effect can also be set on
* the inside of the Game Object. The color and strength of the glow can be modified.
*
* A Glow effect is added to a Game Object via the FX component:
*
* ```js
* const sprite = this.add.sprite();
*
* sprite.preFX.addGlow();
* sprite.postFX.addGlow();
* ```
*
* @class Glow
* @extends Phaser.FX.Controller
* @memberof Phaser.FX
* @constructor
* @since 3.60.0
*
* @param {Phaser.GameObjects.GameObject} gameObject - A reference to the Game Object that has this fx.
* @param {number} [color=0xffffff] - The color of the glow effect as a number value.
* @param {number} [outerStrength=4] - The strength of the glow outward from the edge of the Sprite.
* @param {number} [innerStrength=0] - The strength of the glow inward from the edge of the Sprite.
* @param {boolean} [knockout=false] - If `true` only the glow is drawn, not the texture itself.
*/
var Glow = new Class({
Extends: Controller,
initialize:
function Glow (gameObject, color, outerStrength, innerStrength, knockout)
{
if (outerStrength === undefined) { outerStrength = 4; }
if (innerStrength === undefined) { innerStrength = 0; }
if (knockout === undefined) { knockout = false; }
Controller.call(this, FX_CONST.GLOW, gameObject);
/**
* The strength of the glow outward from the edge of the Sprite.
*
* @name Phaser.FX.Glow#outerStrength
* @type {number}
* @since 3.60.0
*/
this.outerStrength = outerStrength;
/**
* The strength of the glow inward from the edge of the Sprite.
*
* @name Phaser.FX.Glow#innerStrength
* @type {number}
* @since 3.60.0
*/
this.innerStrength = innerStrength;
/**
* If `true` only the glow is drawn, not the texture itself.
*
* @name Phaser.FX.Glow#knockout
* @type {number}
* @since 3.60.0
*/
this.knockout = knockout;
/**
* A 4 element array of gl color values.
*
* @name Phaser.FX.Glow#glcolor
* @type {number[]}
* @since 3.60.0
*/
this.glcolor = [ 1, 1, 1, 1 ];
if (color !== undefined)
{
this.color = color;
}
},
/**
* The color of the glow as a number value.
*
* @name Phaser.FX.Glow#color
* @type {number}
* @since 3.60.0
*/
color: {
get: function ()
{
var color = this.glcolor;
return (((color[0] * 255) << 16) + ((color[1] * 255) << 8) + (color[2] * 255 | 0));
},
set: function (value)
{
var color = this.glcolor;
color[0] = ((value >> 16) & 0xFF) / 255;
color[1] = ((value >> 8) & 0xFF) / 255;
color[2] = (value & 0xFF) / 255;
}
}
});
module.exports = Glow;