/
Shadow.js
162 lines (140 loc) · 4.34 KB
/
Shadow.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
/**
* @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 Shadow FX Controller.
*
* This FX controller manages the shadow effect for a Game Object.
*
* The shadow effect is a visual technique used to create the illusion of depth and realism by adding darker,
* offset silhouettes or shapes beneath game objects, characters, or environments. These simulated shadows
* help to enhance the visual appeal and immersion, making the 2D game world appear more dynamic and three-dimensional.
*
* A Shadow effect is added to a Game Object via the FX component:
*
* ```js
* const sprite = this.add.sprite();
*
* sprite.preFX.addShadow();
* sprite.postFX.addShadow();
* ```
*
* @class Shadow
* @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} [x=0] - The horizontal offset of the shadow effect.
* @param {number} [y=0] - The vertical offset of the shadow effect.
* @param {number} [decay=0.1] - The amount of decay for shadow effect.
* @param {number} [power=1] - The power of the shadow effect.
* @param {number} [color=0x000000] - The color of the shadow.
* @param {number} [samples=6] - The number of samples that the shadow effect will run for. An integer between 1 and 12.
* @param {number} [intensity=1] - The intensity of the shadow effect.
*/
var Shadow = new Class({
Extends: Controller,
initialize:
function Shadow (gameObject, x, y, decay, power, color, samples, intensity)
{
if (x === undefined) { x = 0; }
if (y === undefined) { y = 0; }
if (decay === undefined) { decay = 0.1; }
if (power === undefined) { power = 1; }
if (samples === undefined) { samples = 6; }
if (intensity === undefined) { intensity = 1; }
Controller.call(this, FX_CONST.SHADOW, gameObject);
/**
* The horizontal offset of the shadow effect.
*
* @name Phaser.FX.Shadow#x
* @type {number}
* @since 3.60.0
*/
this.x = x;
/**
* The vertical offset of the shadow effect.
*
* @name Phaser.FX.Shadow#y
* @type {number}
* @since 3.60.0
*/
this.y = y;
/**
* The amount of decay for the shadow effect.
*
* @name Phaser.FX.Shadow#decay
* @type {number}
* @since 3.60.0
*/
this.decay = decay;
/**
* The power of the shadow effect.
*
* @name Phaser.FX.Shadow#power
* @type {number}
* @since 3.60.0
*/
this.power = power;
/**
* The internal gl color array.
*
* @name Phaser.FX.Shadow#glcolor
* @type {number[]}
* @since 3.60.0
*/
this.glcolor = [ 0, 0, 0, 1 ];
/**
* The number of samples that the shadow effect will run for.
*
* This should be an integer with a minimum value of 1 and a maximum of 12.
*
* @name Phaser.FX.Shadow#samples
* @type {number}
* @since 3.60.0
*/
this.samples = samples;
/**
* The intensity of the shadow effect.
*
* @name Phaser.FX.Shadow#intensity
* @type {number}
* @since 3.60.0
*/
this.intensity = intensity;
if (color !== undefined)
{
this.color = color;
}
},
/**
* The color of the shadow.
*
* @name Phaser.FX.Shadow#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 = Shadow;