The Color class holds a single color value and allows for easy modification and reading of it.
new Color([red], [green], [blue], [alpha])
name | type | arguments | Default | description |
---|---|---|---|---|
red | number | <optional> | 0 |
The red color value. A number between 0 and 255. |
green | number | <optional> | 0 |
The green color value. A number between 0 and 255. |
blue | number | <optional> | 0 |
The blue color value. A number between 0 and 255. |
alpha | number | <optional> | 255 |
The alpha value. A number between 0 and 255. |
The alpha color value, normalized to the range 0 to 255.
The alpha color value, normalized to the range 0 to 1.
The blue color value, normalized to the range 0 to 255.
The blue color value, normalized to the range 0 to 1.
The color of this Color component, not including the alpha channel.
The color of this Color component, including the alpha channel.
An array containing the calculated color values for WebGL use.
The green color value, normalized to the range 0 to 255.
The green color value, normalized to the range 0 to 1.
The hue color value. A number between 0 and 1. This is the base color.
The red color value, normalized to the range 0 to 255.
The red color value, normalized to the range 0 to 1.
The color of this Color component as a string which can be used in CSS color values.
The saturation color value. A number between 0 and 1. This controls how much of the hue will be in the final color, where 1 is fully saturated and 0 will give you white.
The lightness color value. A number between 0 and 1. This controls how dark the color is. Where 1 is as bright as possible and 0 is black.
Brighten this Color by the percentage amount given.
name | type | description |
---|---|---|
amount | number |
The percentage amount to change this color by. A value between 0 and 100. |
This Color object.
Returns a new Color component using the values from this one.
A new Color object.
Decrease the lightness of this Color by the percentage amount given.
name | type | description |
---|---|---|
amount | number |
The percentage amount to change this color by. A value between 0 and 100. |
This Color object.
Decrease the saturation of this Color by the percentage amount given. The saturation is the amount of the base color in the hue.
name | type | description |
---|---|---|
amount | number |
The percentage amount to change this color by. A value between 0 and 100. |
This Color object.
Sets this Color object to be grayscaled based on the shade value given.
name | type | description |
---|---|---|
shade | number |
A value between 0 and 255. |
This Color object.
Increase the lightness of this Color by the percentage amount given.
name | type | description |
---|---|---|
amount | number |
The percentage amount to change this color by. A value between 0 and 100. |
This Color object.
Sets this Color object to be a random color between the min
and max
values given.
name | type | arguments | Default | description |
---|---|---|---|---|
min | number | <optional> | 0 |
The minimum random color value. Between 0 and 255. |
max | number | <optional> | 255 |
The maximum random color value. Between 0 and 255. |
This Color object.
Sets this Color object to be a random grayscale color between the min
and max
values given.
name | type | arguments | Default | description |
---|---|---|---|---|
min | number | <optional> | 0 |
The minimum random color value. Between 0 and 255. |
max | number | <optional> | 255 |
The maximum random color value. Between 0 and 255. |
This Color object.
Increase the saturation of this Color by the percentage amount given. The saturation is the amount of the base color in the hue.
name | type | description |
---|---|---|
amount | number |
The percentage amount to change this color by. A value between 0 and 100. |
This Color object.
Sets the color based on the hue, saturation and lightness values given.
name | type | description |
---|---|---|
h | number |
The hue, in the range 0 - 1. This is the base color. |
s | number |
The saturation, in the range 0 - 1. This controls how much of the hue will be in the final color, where 1 is fully saturated and 0 will give you white. |
v | number |
The value, in the range 0 - 1. This controls how dark the color is. Where 1 is as bright as possible and 0 is black. |
This Color object.
Sets the color based on the color object given.
name | type | description |
---|---|---|
color | Phaser.Types.Display.InputColorObject |
An object containing |
This Color object.
Sets the red, green, blue and alpha GL values of this Color component.
name | type | arguments | Default | description |
---|---|---|---|---|
red | number |
The red color value. A number between 0 and 1. |
||
green | number |
The green color value. A number between 0 and 1. |
||
blue | number |
The blue color value. A number between 0 and 1. |
||
alpha | number | <optional> | 1 |
The alpha value. A number between 0 and 1. |
This Color object.
Sets the color of this Color component.
name | type | arguments | Default | description |
---|---|---|---|---|
red | number |
The red color value. A number between 0 and 255. |
||
green | number |
The green color value. A number between 0 and 255. |
||
blue | number |
The blue color value. A number between 0 and 255. |
||
alpha | number | <optional> | 255 |
The alpha value. A number between 0 and 255. |
updateHSV | boolean | <optional> | true |
Update the HSV values after setting the RGB values? |
This Color object.
Sets this color to be transparent. Sets all values to zero.
This Color object.
Return an array of Colors in a Color Spectrum.
The spectrum colors flow in the order: red, yellow, green, blue.
By default this function will return an array with 1024 elements in.
However, you can reduce this to a smaller quantity if needed, by specitying the limit
parameter.
name | type | arguments | Default | description |
---|---|---|---|---|
limit | number | <optional> | 1024 |
How many colors should be returned? The maximum is 1024 but you can set a smaller quantity if required. |
An array containing limit
parameter number of elements, where each contains a Color Object.
Converts the given color value into an Object containing r,g,b and a properties.
name | type | description |
---|---|---|
color | number |
A color value, optionally including the alpha value. |
An object containing the parsed color values.
Returns a string containing a hex representation of the given color component.
name | type | description |
---|---|---|
color | number |
The color channel to get the hex value for, must be a value between 0 and 255. |
A string of length 2 characters, i.e. 255 = ff, 100 = 64.
Given 3 separate color values this will return an integer representation of it.
name | type | description |
---|---|---|
red | number |
The red color value. A number between 0 and 255. |
green | number |
The green color value. A number between 0 and 255. |
blue | number |
The blue color value. A number between 0 and 255. |
The combined color value.
Given an alpha and 3 color values this will return an integer representation of it.
name | type | description |
---|---|---|
red | number |
The red color value. A number between 0 and 255. |
green | number |
The green color value. A number between 0 and 255. |
blue | number |
The blue color value. A number between 0 and 255. |
alpha | number |
The alpha color value. A number between 0 and 255. |
The combined color value.
Converts HSL (hue, saturation and lightness) values to a Phaser Color object.
name | type | description |
---|---|---|
h | number |
The hue value in the range 0 to 1. |
s | number |
The saturation value in the range 0 to 1. |
l | number |
The lightness value in the range 0 to 1. |
A Color object created from the results of the h, s and l values.
Generates an HSV color wheel which is an array of 360 Color objects, for each step of the wheel.
name | type | arguments | Default | description |
---|---|---|---|---|
s | number | <optional> | 1 |
The saturation, in the range 0 - 1. |
v | number | <optional> | 1 |
The value, in the range 0 - 1. |
An array containing 360 ColorObject elements, where each element contains a Color object corresponding to the color at that point in the HSV color wheel.
Converts a HSV (hue, saturation and value) color set to RGB.
Conversion formula from https://en.wikipedia.org/wiki/HSL_and_HSV
Assumes HSV values are contained in the set [0, 1].
name | type | arguments | description |
---|---|---|---|
h | number |
The hue, in the range 0 - 1. This is the base color. |
|
s | number |
The saturation, in the range 0 - 1. This controls how much of the hue will be in the final color, where 1 is fully saturated and 0 will give you white. |
|
v | number |
The value, in the range 0 - 1. This controls how dark the color is. Where 1 is as bright as possible and 0 is black. |
|
out | Phaser.Display.Color | Phaser.Types.Display.ColorObject | <optional> |
A Color object to store the results in. If not given a new ColorObject will be created. |
An object with the red, green and blue values set in the r, g and b properties.
Converts a hex string into a Phaser Color object.
The hex string can supplied as '#0033ff'
or the short-hand format of '#03f'
; it can begin with an optional "#" or "0x", or be unprefixed.
An alpha channel is not supported.
name | type | description |
---|---|---|
hex | string |
The hex color value to convert, such as |
A Color object populated by the values of the given string.
Converts a hue to an RGB color. Based on code by Michael Jackson (https://github.com/mjijackson)
name | type |
---|---|
p | number |
q | number |
t | number |
The combined color value.
Converts the given color value into an instance of a Color object.
name | type | description |
---|---|---|
input | number |
The color value to convert into a Color object. |
A Color object.
Return the component parts of a color as an Object with the properties alpha, red, green, blue.
Alpha will only be set if it exists in the given color (0xAARRGGBB)
name | type | description |
---|---|---|
input | number |
The color value to convert into a Color object. |
An object with the red, green and blue values set in the r, g and b properties.
Converts an object containing r
, g
, b
and a
properties into a Color class instance.
name | type | description |
---|---|---|
input | Phaser.Types.Display.InputColorObject |
An object containing |
A Color object.
Converts a CSS 'web' string into a Phaser Color object.
The web string can be in the format 'rgb(r,g,b)'
or 'rgba(r,g,b,a)'
where r/g/b are in the range [0..255] and a is in the range [0..1].
name | type | description |
---|---|---|
rgb | string |
The CSS format color string, using the |
A Color object.
Converts an RGB color value to HSV (hue, saturation and value). Conversion formula from http://en.wikipedia.org/wiki/HSL_color_space. Assumes RGB values are contained in the set [0, 255] and returns h, s and v in the set [0, 1]. Based on code by Michael Jackson (https://github.com/mjijackson)
name | type | arguments | description |
---|---|---|---|
r | number |
The red color value. A number between 0 and 255. |
|
g | number |
The green color value. A number between 0 and 255. |
|
b | number |
The blue color value. A number between 0 and 255. |
|
out | Phaser.Display.Color | Phaser.Types.Display.HSVColorObject | <optional> |
An object to store the color values in. If not given an HSV Color Object will be created. |
An object with the properties h
, s
and v
set.
Converts the color values into an HTML compatible color string, prefixed with either #
or 0x
.
name | type | arguments | Default | description |
---|---|---|---|---|
r | number |
The red color value. A number between 0 and 255. |
||
g | number |
The green color value. A number between 0 and 255. |
||
b | number |
The blue color value. A number between 0 and 255. |
||
a | number | <optional> | 255 |
The alpha value. A number between 0 and 255. |
prefix | string | <optional> | # |
The prefix of the string. Either |
A string-based representation of the color values.
Creates a new Color object where the r, g, and b values have been set to random values based on the given min max values.
name | type | arguments | Default | description |
---|---|---|---|---|
min | number | <optional> | 0 |
The minimum value to set the random range from (between 0 and 255) |
max | number | <optional> | 255 |
The maximum value to set the random range from (between 0 and 255) |
A Color object.
Converts the given source color value into an instance of a Color class.
The value can be either a string, prefixed with rgb
or a hex string, a number or an Object.
name | type | description |
---|---|---|
input | string | number | Phaser.Types.Display.InputColorObject |
The source color value to convert. |
A Color object.