The Gradient FX Controller.
This FX controller manages the gradient effect for a Game Object.
The gradient overlay effect is a visual technique where a smooth color transition is applied over Game Objects, such as sprites or UI components. This effect is used to enhance visual appeal, emphasize depth, or create stylistic and atmospheric variations. It can also be utilized to convey information, such as representing progress or health status through color changes.
A Gradient effect is added to a Game Object via the FX component:
const sprite = this.add.sprite();
sprite.preFX.addGradient();
sprite.postFX.addGradient();
new Gradient(gameObject, [color1], [color2], [alpha], [fromX], [fromY], [toX], [toY], [size])
name | type | arguments | Default | description |
---|---|---|---|---|
gameObject | Phaser.GameObjects.GameObject |
A reference to the Game Object that has this fx. |
||
color1 | number | <optional> | 0xff0000 |
The first gradient color, given as a number value. |
color2 | number | <optional> | 0x00ff00 |
The second gradient color, given as a number value. |
alpha | number | <optional> | 0.2 |
The alpha value of the gradient effect. |
fromX | number | <optional> | 0 |
The horizontal position the gradient will start from. This value is normalized, between 0 and 1, and is not in pixels. |
fromY | number | <optional> | 0 |
The vertical position the gradient will start from. This value is normalized, between 0 and 1, and is not in pixels. |
toX | number | <optional> | 0 |
The horizontal position the gradient will end at. This value is normalized, between 0 and 1, and is not in pixels. |
toY | number | <optional> | 1 |
The vertical position the gradient will end at. This value is normalized, between 0 and 1, and is not in pixels. |
size | number | <optional> | 0 |
How many 'chunks' the gradient is divided in to, as spread over the entire height of the texture. Leave this at zero for a smooth gradient, or set higher for a more retro chunky effect. |
Toggle this boolean to enable or disable this effect, without removing and adding it from the Game Object.
Only works for Pre FX.
Post FX are always active.
The alpha value of the gradient effect.
The first gradient color, given as a number value.
The second gradient color, given as a number value.
The horizontal position the gradient will start from. This value is normalized, between 0 and 1 and is not in pixels.
The vertical position the gradient will start from. This value is normalized, between 0 and 1 and is not in pixels.
A reference to the Game Object that owns this effect.
The internal gl color array for the starting color.
The internal gl color array for the ending color.
Sets how many 'chunks' the gradient is divided in to, as spread over the entire height of the texture. Leave this at zero for a smooth gradient, or set to a higher number to split the gradient into that many sections, giving a more banded 'retro' effect.
The horizontal position the gradient will end. This value is normalized, between 0 and 1 and is not in pixels.
The vertical position the gradient will end. This value is normalized, between 0 and 1 and is not in pixels.
The FX_CONST type of this effect.
Destroys this FX Controller.
Sets the active state of this FX Controller.
A disabled FX Controller will not be updated.
name | type | description |
---|---|---|
value | boolean |
|
This FX Controller instance.