forked from phaserjs/phaser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTint.js
More file actions
326 lines (282 loc) · 9.27 KB
/
Copy pathTint.js
File metadata and controls
326 lines (282 loc) · 9.27 KB
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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2020 Photon Storm Ltd.
* @license {@link https://opensource.org/licenses/MIT|MIT License}
*/
var GetColorFromValue = require('../../display/color/GetColorFromValue');
/**
* Provides methods used for setting the tint of a Game Object.
* Should be applied as a mixin and not used directly.
*
* @namespace Phaser.GameObjects.Components.Tint
* @webglOnly
* @since 3.0.0
*/
var Tint = {
/**
* Private internal value. Holds the top-left tint value.
*
* @name Phaser.GameObjects.Components.Tint#_tintTL
* @type {number}
* @private
* @default 16777215
* @since 3.0.0
*/
_tintTL: 16777215,
/**
* Private internal value. Holds the top-right tint value.
*
* @name Phaser.GameObjects.Components.Tint#_tintTR
* @type {number}
* @private
* @default 16777215
* @since 3.0.0
*/
_tintTR: 16777215,
/**
* Private internal value. Holds the bottom-left tint value.
*
* @name Phaser.GameObjects.Components.Tint#_tintBL
* @type {number}
* @private
* @default 16777215
* @since 3.0.0
*/
_tintBL: 16777215,
/**
* Private internal value. Holds the bottom-right tint value.
*
* @name Phaser.GameObjects.Components.Tint#_tintBR
* @type {number}
* @private
* @default 16777215
* @since 3.0.0
*/
_tintBR: 16777215,
/**
* Private internal value. Holds if the Game Object is tinted or not.
*
* @name Phaser.GameObjects.Components.Tint#_isTinted
* @type {boolean}
* @private
* @default false
* @since 3.11.0
*/
_isTinted: false,
/**
* Fill or additive?
*
* @name Phaser.GameObjects.Components.Tint#tintFill
* @type {boolean}
* @default false
* @since 3.11.0
*/
tintFill: false,
/**
* Clears all tint values associated with this Game Object.
*
* Immediately sets the color values back to 0xffffff and the tint type to 'additive',
* which results in no visible change to the texture.
*
* @method Phaser.GameObjects.Components.Tint#clearTint
* @webglOnly
* @since 3.0.0
*
* @return {this} This Game Object instance.
*/
clearTint: function ()
{
this.setTint(0xffffff);
this._isTinted = false;
return this;
},
/**
* Sets an additive tint on this Game Object.
*
* The tint works by taking the pixel color values from the Game Objects texture, and then
* multiplying it by the color value of the tint. You can provide either one color value,
* in which case the whole Game Object will be tinted in that color. Or you can provide a color
* per corner. The colors are blended together across the extent of the Game Object.
*
* To modify the tint color once set, either call this method again with new values or use the
* `tint` property to set all colors at once. Or, use the properties `tintTopLeft`, `tintTopRight,
* `tintBottomLeft` and `tintBottomRight` to set the corner color values independently.
*
* To remove a tint call `clearTint`.
*
* To swap this from being an additive tint to a fill based tint set the property `tintFill` to `true`.
*
* @method Phaser.GameObjects.Components.Tint#setTint
* @webglOnly
* @since 3.0.0
*
* @param {integer} [topLeft=0xffffff] - The tint being applied to the top-left of the Game Object. If no 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 {this} This Game Object instance.
*/
setTint: function (topLeft, topRight, bottomLeft, bottomRight)
{
if (topLeft === undefined) { topLeft = 0xffffff; }
if (topRight === undefined)
{
topRight = topLeft;
bottomLeft = topLeft;
bottomRight = topLeft;
}
this._tintTL = GetColorFromValue(topLeft);
this._tintTR = GetColorFromValue(topRight);
this._tintBL = GetColorFromValue(bottomLeft);
this._tintBR = GetColorFromValue(bottomRight);
this._isTinted = true;
this.tintFill = false;
return this;
},
/**
* Sets a fill-based tint on this Game Object.
*
* Unlike an additive tint, a fill-tint literally replaces the pixel colors from the texture
* with those in the tint. You can use this for effects such as making a player flash 'white'
* if hit by something. You can provide either one color value, in which case the whole
* Game Object will be rendered in that color. Or you can provide a color per corner. The colors
* are blended together across the extent of the Game Object.
*
* To modify the tint color once set, either call this method again with new values or use the
* `tint` property to set all colors at once. Or, use the properties `tintTopLeft`, `tintTopRight,
* `tintBottomLeft` and `tintBottomRight` to set the corner color values independently.
*
* To remove a tint call `clearTint`.
*
* To swap this from being a fill-tint to an additive tint set the property `tintFill` to `false`.
*
* @method Phaser.GameObjects.Components.Tint#setTintFill
* @webglOnly
* @since 3.11.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 {this} This Game Object instance.
*/
setTintFill: function (topLeft, topRight, bottomLeft, bottomRight)
{
this.setTint(topLeft, topRight, bottomLeft, bottomRight);
this.tintFill = true;
return this;
},
/**
* The tint value being applied to the top-left of the Game Object.
* This value is interpolated from the corner to the center of the Game Object.
*
* @name Phaser.GameObjects.Components.Tint#tintTopLeft
* @type {integer}
* @webglOnly
* @since 3.0.0
*/
tintTopLeft: {
get: function ()
{
return this._tintTL;
},
set: function (value)
{
this._tintTL = GetColorFromValue(value);
this._isTinted = true;
}
},
/**
* The tint value being applied to the top-right of the Game Object.
* This value is interpolated from the corner to the center of the Game Object.
*
* @name Phaser.GameObjects.Components.Tint#tintTopRight
* @type {integer}
* @webglOnly
* @since 3.0.0
*/
tintTopRight: {
get: function ()
{
return this._tintTR;
},
set: function (value)
{
this._tintTR = GetColorFromValue(value);
this._isTinted = true;
}
},
/**
* The tint value being applied to the bottom-left of the Game Object.
* This value is interpolated from the corner to the center of the Game Object.
*
* @name Phaser.GameObjects.Components.Tint#tintBottomLeft
* @type {integer}
* @webglOnly
* @since 3.0.0
*/
tintBottomLeft: {
get: function ()
{
return this._tintBL;
},
set: function (value)
{
this._tintBL = GetColorFromValue(value);
this._isTinted = true;
}
},
/**
* The tint value being applied to the bottom-right of the Game Object.
* This value is interpolated from the corner to the center of the Game Object.
*
* @name Phaser.GameObjects.Components.Tint#tintBottomRight
* @type {integer}
* @webglOnly
* @since 3.0.0
*/
tintBottomRight: {
get: function ()
{
return this._tintBR;
},
set: function (value)
{
this._tintBR = GetColorFromValue(value);
this._isTinted = true;
}
},
/**
* The tint value being applied to the whole of the Game Object.
* This property is a setter-only. Use the properties `tintTopLeft` etc to read the current tint value.
*
* @name Phaser.GameObjects.Components.Tint#tint
* @type {integer}
* @webglOnly
* @since 3.0.0
*/
tint: {
set: function (value)
{
this.setTint(value, value, value, value);
}
},
/**
* Does this Game Object have a tint applied to it or not?
*
* @name Phaser.GameObjects.Components.Tint#isTinted
* @type {boolean}
* @webglOnly
* @readonly
* @since 3.11.0
*/
isTinted: {
get: function ()
{
return this._isTinted;
}
}
};
module.exports = Tint;