-
Notifications
You must be signed in to change notification settings - Fork 7.1k
/
Circle.js
202 lines (172 loc) · 5.88 KB
/
Circle.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
/**
* @author Richard Davey <rich@phaser.io>
* @copyright 2013-2024 Phaser Studio Inc.
* @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 Circle FX Controller.
*
* This FX controller manages the circle effect for a Game Object.
*
* This effect will draw a circle around the texture of the Game Object, effectively masking off
* any area outside of the circle without the need for an actual mask. You can control the thickness
* of the circle, the color of the circle and the color of the background, should the texture be
* transparent. You can also control the feathering applied to the circle, allowing for a harsh or soft edge.
*
* Please note that adding this effect to a Game Object will not change the input area or physics body of
* the Game Object, should it have one.
*
* A Circle effect is added to a Game Object via the FX component:
*
* ```js
* const sprite = this.add.sprite();
*
* sprite.preFX.addCircle();
* sprite.postFX.addCircle();
* ```
*
* @class Circle
* @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} [thickness=8] - The width of the circle around the texture, in pixels.
* @param {number} [color=0xfeedb6] - The color of the circular ring, given as a number value.
* @param {number} [backgroundColor=0xff0000] - The color of the background, behind the texture, given as a number value.
* @param {number} [scale=1] - The scale of the circle. The default scale is 1, which is a circle the full size of the underlying texture.
* @param {number} [feather=0.005] - The amount of feathering to apply to the circle from the ring.
*/
var Circle = new Class({
Extends: Controller,
initialize:
function Circle (gameObject, thickness, color, backgroundColor, scale, feather)
{
if (thickness === undefined) { thickness = 8; }
if (scale === undefined) { scale = 1; }
if (feather === undefined) { feather = 0.005; }
Controller.call(this, FX_CONST.CIRCLE, gameObject);
/**
* The scale of the circle. The default scale is 1, which is a circle
* the full size of the underlying texture. Reduce this value to create
* a smaller circle, or increase it to create a circle that extends off
* the edges of the texture.
*
* @name Phaser.FX.Circle#scale
* @type {number}
* @since 3.60.0
*/
this.scale = scale;
/**
* The amount of feathering to apply to the circle from the ring,
* extending into the middle of the circle. The default is 0.005,
* which is a very low amount of feathering just making sure the ring
* has a smooth edge. Increase this amount to a value such as 0.5
* or 0.025 for larger amounts of feathering.
*
* @name Phaser.FX.Circle#feather
* @type {number}
* @since 3.60.0
*/
this.feather = feather;
/**
* The width of the circle around the texture, in pixels. This value
* doesn't factor in the feather, which can extend the thickness
* internally depending on its value.
*
* @name Phaser.FX.Circle#thickness
* @type {number}
* @since 3.60.0
*/
this.thickness = thickness;
/**
* The internal gl color array for the ring color.
*
* @name Phaser.FX.Circle#glcolor
* @type {number[]}
* @since 3.60.0
*/
this.glcolor = [ 1, 0.2, 0.7 ];
/**
* The internal gl color array for the background color.
*
* @name Phaser.FX.Circle#glcolor2
* @type {number[]}
* @since 3.60.0
*/
this.glcolor2 = [ 1, 0, 0, 0.4 ];
if (color !== undefined && color !== null)
{
this.color = color;
}
if (backgroundColor !== undefined && backgroundColor !== null)
{
this.backgroundColor = backgroundColor;
}
},
/**
* The color of the circular ring, given as a number value.
*
* @name Phaser.FX.Circle#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;
}
},
/**
* The color of the background, behind the texture, given as a number value.
*
* @name Phaser.FX.Circle#backgroundColor
* @type {number}
* @since 3.60.0
*/
backgroundColor: {
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;
}
},
/**
* The alpha of the background, behind the texture, given as a number value.
*
* @name Phaser.FX.Circle#backgroundAlpha
* @type {number}
* @since 3.70.0
*/
backgroundAlpha: {
get: function ()
{
return this.glcolor2[3];
},
set: function (value)
{
this.glcolor2[3] = value;
}
}
});
module.exports = Circle;