new Color()
The Phaser.Color class is a set of static methods that assist in color manipulation and conversion.
- Source:
- src/utils/Color.js line 12
Members
-
<static, constant> AQUA : number
-
Aqua (0x00ffff)
Type:
- number
- Default Value:
-
- 65535
- Source:
- src/utils/Color.js line 57
-
<static, constant> BLACK : number
-
Black (0x000000)
Type:
- number
- Source:
- src/utils/Color.js line 93
-
<static, constant> BLUE : number
-
Blue (0x0000ff)
Type:
- number
- Default Value:
-
- 255
- Source:
- src/utils/Color.js line 66
-
<static, constant> GRAY : number
-
Gray (0x666666)
Type:
- number
- Default Value:
-
- 6710886
- Source:
- src/utils/Color.js line 102
-
<static, constant> GREEN : number
-
Green (0x00ff00)
Type:
- number
- Default Value:
-
- 65280
- Source:
- src/utils/Color.js line 48
-
<static, constant> ORANGE : number
-
Orange (0xff9900)
Type:
- number
- Default Value:
-
- 16750848
- Source:
- src/utils/Color.js line 30
-
<static, constant> RED : number
-
Red (0xff0000)
Type:
- number
- Default Value:
-
- 16711680
- Source:
- src/utils/Color.js line 21
-
<static, constant> VIOLET : number
-
Violet/purple (0xff00ff)
Type:
- number
- Default Value:
-
- 16711935
- Source:
- src/utils/Color.js line 75
-
<static, constant> WHITE : number
-
White (0xffffff)
Type:
- number
- Default Value:
-
- 16777215
- Source:
- src/utils/Color.js line 84
-
<static, constant> YELLOW : number
-
Yellow (0xffff00)
Type:
- number
- Default Value:
-
- 16776960
- Source:
- src/utils/Color.js line 39
Methods
-
<static> blendAdd(a, b)
-
Adds the source and backdrop colors together and returns the value, up to a maximum of 255.
Parameters:
Name Type Description a
integer The source color to blend, in the range 1 to 255.
b
integer The backdrop color to blend, in the range 1 to 255.
- Source:
- src/utils/Color.js line 1248
Returns:
The blended color value, in the range 1 to 255.
- Type
- integer
-
<static> blendAverage(a, b)
-
Takes the average of the source and backdrop colors.
Parameters:
Name Type Description a
integer The source color to blend, in the range 1 to 255.
b
integer The backdrop color to blend, in the range 1 to 255.
- Source:
- src/utils/Color.js line 1234
Returns:
The blended color value, in the range 1 to 255.
- Type
- integer
-
<static> blendColorBurn(a, b)
-
Darkens the backdrop color to reflect the source color. Painting with white produces no change.
Parameters:
Name Type Description a
integer The source color to blend, in the range 1 to 255.
b
integer The backdrop color to blend, in the range 1 to 255.
- Source:
- src/utils/Color.js line 1417
Returns:
The blended color value, in the range 1 to 255.
- Type
- integer
-
<static> blendColorDodge(a, b)
-
Brightens the backdrop color to reflect the source color. Painting with black produces no change.
Parameters:
Name Type Description a
integer The source color to blend, in the range 1 to 255.
b
integer The backdrop color to blend, in the range 1 to 255.
- Source:
- src/utils/Color.js line 1402
Returns:
The blended color value, in the range 1 to 255.
- Type
- integer
-
<static> blendDarken(a, b)
-
Selects the darker of the backdrop and source colors.
Parameters:
Name Type Description a
integer The source color to blend, in the range 1 to 255.
b
integer The backdrop color to blend, in the range 1 to 255.
- Source:
- src/utils/Color.js line 1203
Returns:
The blended color value, in the range 1 to 255.
- Type
- integer
-
<static> blendDifference(a, b)
-
Subtracts the darker of the two constituent colors from the lighter.
Painting with white inverts the backdrop color; painting with black produces no change.
Parameters:
Name Type Description a
integer The source color to blend, in the range 1 to 255.
b
integer The backdrop color to blend, in the range 1 to 255.
- Source:
- src/utils/Color.js line 1276
Returns:
The blended color value, in the range 1 to 255.
- Type
- integer
-
<static> blendExclusion(a, b)
-
Produces an effect similar to that of the Difference mode, but lower in contrast. Painting with white inverts the backdrop color; painting with black produces no change.
Parameters:
Name Type Description a
integer The source color to blend, in the range 1 to 255.
b
integer The backdrop color to blend, in the range 1 to 255.
- Source:
- src/utils/Color.js line 1322
Returns:
The blended color value, in the range 1 to 255.
- Type
- integer
-
<static> blendGlow(a, b)
-
Glow blend mode. This mode is a variation of reflect mode with the source and backdrop colors swapped.
Parameters:
Name Type Description a
integer The source color to blend, in the range 1 to 255.
b
integer The backdrop color to blend, in the range 1 to 255.
- Source:
- src/utils/Color.js line 1539
Returns:
The blended color value, in the range 1 to 255.
- Type
- integer
-
<static> blendHardLight(a, b)
-
Multiplies or screens the colors, depending on the source color value.
If the source color is lighter than 0.5, the backdrop is lightened, as if it were screened; this is useful for adding highlights to a scene.
If the source color is darker than 0.5, the backdrop is darkened, as if it were multiplied; this is useful for adding shadows to a scene.
The degree of lightening or darkening is proportional to the difference between the source color and 0.5; if it is equal to 0.5, the backdrop is unchanged.
Painting with pure black or white produces pure black or white. The effect is similar to shining a harsh spotlight on the backdrop.
Parameters:
Name Type Description a
integer The source color to blend, in the range 1 to 255.
b
integer The backdrop color to blend, in the range 1 to 255.
- Source:
- src/utils/Color.js line 1377
Returns:
The blended color value, in the range 1 to 255.
- Type
- integer
-
<static> blendHardMix(a, b)
-
Runs blendVividLight on the source and backdrop colors. If the resulting color is 128 or more, it receives a value of 255; if less than 128, a value of 0. Therefore, all blended pixels have red, green, and blue channel values of either 0 or 255. This changes all pixels to primary additive colors (red, green, or blue), white, or black.
Parameters:
Name Type Description a
integer The source color to blend, in the range 1 to 255.
b
integer The backdrop color to blend, in the range 1 to 255.
- Source:
- src/utils/Color.js line 1508
Returns:
The blended color value, in the range 1 to 255.
- Type
- integer
-
<static> blendLighten(a, b)
-
Selects the lighter of the backdrop and source colors.
Parameters:
Name Type Description a
integer The source color to blend, in the range 1 to 255.
b
integer The backdrop color to blend, in the range 1 to 255.
- Source:
- src/utils/Color.js line 1189
Returns:
The blended color value, in the range 1 to 255.
- Type
- integer
-
<static> blendLinearBurn(a, b)
-
An alias for blendSubtract, it simply sums the values of the two colors and subtracts 255.
Parameters:
Name Type Description a
integer The source color to blend, in the range 1 to 255.
b
integer The backdrop color to blend, in the range 1 to 255.
- Source:
- src/utils/Color.js line 1446
Returns:
The blended color value, in the range 1 to 255.
- Type
- integer
-
<static> blendLinearDodge(a, b)
-
An alias for blendAdd, it simply sums the values of the two colors.
Parameters:
Name Type Description a
integer The source color to blend, in the range 1 to 255.
b
integer The backdrop color to blend, in the range 1 to 255.
- Source:
- src/utils/Color.js line 1432
Returns:
The blended color value, in the range 1 to 255.
- Type
- integer
-
<static> blendLinearLight(a, b)
-
This blend mode combines Linear Dodge and Linear Burn (rescaled so that neutral colors become middle gray). Dodge applies to values of top layer lighter than middle gray, and burn to darker values. The calculation simplifies to the sum of bottom layer and twice the top layer, subtract 128. The contrast decreases.
Parameters:
Name Type Description a
integer The source color to blend, in the range 1 to 255.
b
integer The backdrop color to blend, in the range 1 to 255.
- Source:
- src/utils/Color.js line 1460
Returns:
The blended color value, in the range 1 to 255.
- Type
- integer
-
<static> blendMultiply(a, b)
-
Multiplies the backdrop and source color values. The result color is always at least as dark as either of the two constituent colors. Multiplying any color with black produces black; multiplying with white leaves the original color unchanged.
Parameters:
Name Type Description a
integer The source color to blend, in the range 1 to 255.
b
integer The backdrop color to blend, in the range 1 to 255.
- Source:
- src/utils/Color.js line 1217
Returns:
The blended color value, in the range 1 to 255.
- Type
- integer
-
<static> blendNegation(a, b)
-
Negation blend mode.
Parameters:
Name Type Description a
integer The source color to blend, in the range 1 to 255.
b
integer The backdrop color to blend, in the range 1 to 255.
- Source:
- src/utils/Color.js line 1292
Returns:
The blended color value, in the range 1 to 255.
- Type
- integer
-
<static> blendNormal(a, b)
-
Blends the source color, ignoring the backdrop.
Parameters:
Name Type Description a
integer The source color to blend, in the range 1 to 255.
b
integer The backdrop color to blend, in the range 1 to 255.
- Source:
- src/utils/Color.js line 1175
Returns:
The blended color value, in the range 1 to 255.
- Type
- integer
-
<static> blendOverlay(a, b)
-
Multiplies or screens the colors, depending on the backdrop color. Source colors overlay the backdrop while preserving its highlights and shadows. The backdrop color is not replaced, but is mixed with the source color to reflect the lightness or darkness of the backdrop.
Parameters:
Name Type Description a
integer The source color to blend, in the range 1 to 255.
b
integer The backdrop color to blend, in the range 1 to 255.
- Source:
- src/utils/Color.js line 1337
Returns:
The blended color value, in the range 1 to 255.
- Type
- integer
-
<static> blendPhoenix(a, b)
-
Phoenix blend mode. This subtracts the lighter color from the darker color, and adds 255, giving a bright result.
Parameters:
Name Type Description a
integer The source color to blend, in the range 1 to 255.
b
integer The backdrop color to blend, in the range 1 to 255.
- Source:
- src/utils/Color.js line 1553
Returns:
The blended color value, in the range 1 to 255.
- Type
- integer
-
<static> blendPinLight(a, b)
-
If the backdrop color (light source) is lighter than 50%, the blendDarken mode is used, and colors lighter than the backdrop color do not change. If the backdrop color is darker than 50% gray, colors lighter than the blend color are replaced, and colors darker than the blend color do not change.
Parameters:
Name Type Description a
integer The source color to blend, in the range 1 to 255.
b
integer The backdrop color to blend, in the range 1 to 255.
- Source:
- src/utils/Color.js line 1493
Returns:
The blended color value, in the range 1 to 255.
- Type
- integer
-
<static> blendReflect(a, b)
-
Reflect blend mode. This mode is useful when adding shining objects or light zones to images.
Parameters:
Name Type Description a
integer The source color to blend, in the range 1 to 255.
b
integer The backdrop color to blend, in the range 1 to 255.
- Source:
- src/utils/Color.js line 1525
Returns:
The blended color value, in the range 1 to 255.
- Type
- integer
-
<static> blendScreen(a, b)
-
Multiplies the complements of the backdrop and source color values, then complements the result. The result color is always at least as light as either of the two constituent colors. Screening any color with white produces white; screening with black leaves the original color unchanged.
Parameters:
Name Type Description a
integer The source color to blend, in the range 1 to 255.
b
integer The backdrop color to blend, in the range 1 to 255.
- Source:
- src/utils/Color.js line 1306
Returns:
The blended color value, in the range 1 to 255.
- Type
- integer
-
<static> blendSoftLight(a, b)
-
Darkens or lightens the colors, depending on the source color value.
If the source color is lighter than 0.5, the backdrop is lightened, as if it were dodged; this is useful for adding highlights to a scene.
If the source color is darker than 0.5, the backdrop is darkened, as if it were burned in. The degree of lightening or darkening is proportional to the difference between the source color and 0.5; if it is equal to 0.5, the backdrop is unchanged.
Painting with pure black or white produces a distinctly darker or lighter area, but does not result in pure black or white. The effect is similar to shining a diffused spotlight on the backdrop.
Parameters:
Name Type Description a
integer The source color to blend, in the range 1 to 255.
b
integer The backdrop color to blend, in the range 1 to 255.
- Source:
- src/utils/Color.js line 1353
Returns:
The blended color value, in the range 1 to 255.
- Type
- integer
-
<static> blendSubtract(a, b)
-
Combines the source and backdrop colors and returns their value minus 255.
Parameters:
Name Type Description a
integer The source color to blend, in the range 1 to 255.
b
integer The backdrop color to blend, in the range 1 to 255.
- Source:
- src/utils/Color.js line 1262
Returns:
The blended color value, in the range 1 to 255.
- Type
- integer
-
<static> blendVividLight(a, b)
-
This blend mode combines Color Dodge and Color Burn (rescaled so that neutral colors become middle gray). Dodge applies when values in the top layer are lighter than middle gray, and burn to darker values. The middle gray is the neutral color. When color is lighter than this, this effectively moves the white point of the bottom layer down by twice the difference; when it is darker, the black point is moved up by twice the difference. The perceived contrast increases.
Parameters:
Name Type Description a
integer The source color to blend, in the range 1 to 255.
b
integer The backdrop color to blend, in the range 1 to 255.
- Source:
- src/utils/Color.js line 1476
Returns:
The blended color value, in the range 1 to 255.
- Type
- integer
-
<static> componentToHex(color)
-
Return a string containing a hex representation of the given color component.
Parameters:
Name Type Description color
number The color channel to get the hex value for, must be a value between 0 and 255.
- Source:
- src/utils/Color.js line 802
Returns:
A string of length 2 characters, i.e. 255 = ff, 100 = 64.
- Type
- string
-
<static> createColor( [r] [, g] [, b] [, a] [, h] [, s] [, l] [, v])
-
A utility function to create a lightweight 'color' object with the default components. Any components that are not specified will default to zero.
This is useful when you want to use a shared color object for the getPixel and getPixelAt methods.
Parameters:
Name Type Argument Default Description r
number <optional>
0 The red color component, in the range 0 - 255.
g
number <optional>
0 The green color component, in the range 0 - 255.
b
number <optional>
0 The blue color component, in the range 0 - 255.
a
number <optional>
1 The alpha color component, in the range 0 - 1.
h
number <optional>
0 The hue, in the range 0 - 1.
s
number <optional>
0 The saturation, in the range 0 - 1.
l
number <optional>
0 The lightness, in the range 0 - 1.
v
number <optional>
0 The value, in the range 0 - 1.
- Source:
- src/utils/Color.js line 550
Returns:
The resulting object with r, g, b, a properties and h, s, l and v.
- Type
- object
-
<static> fromRGBA(rgba [, out])
-
A utility to convert an integer in 0xRRGGBBAA format to a color object. This does not rely on endianness.
Parameters:
Name Type Argument Description rgba
number An RGBA hex
out
object <optional>
The object to use, optional.
- Source:
- src/utils/Color.js line 185
Returns:
A color object.
- Type
- object
-
<static> getAlpha(color)
-
Given a native color value (in the format 0xAARRGGBB) this will return the Alpha component, as a value between 0 and 255.
Parameters:
Name Type Description color
number In the format 0xAARRGGBB.
- Source:
- src/utils/Color.js line 1110
Returns:
The Alpha component of the color, will be between 0 and 1 (0 being no Alpha (opaque), 1 full Alpha (transparent)).
- Type
- number
-
<static> getAlphaFloat(color)
-
Given a native color value (in the format 0xAARRGGBB) this will return the Alpha component as a value between 0 and 1.
Parameters:
Name Type Description color
number In the format 0xAARRGGBB.
- Source:
- src/utils/Color.js line 1123
Returns:
The Alpha component of the color, will be between 0 and 1 (0 being no Alpha (opaque), 1 full Alpha (transparent)).
- Type
- number
-
<static> getBlue(color)
-
Given a native color value (in the format 0xAARRGGBB) this will return the Blue component, as a value between 0 and 255.
Parameters:
Name Type Description color
number In the format 0xAARRGGBB.
- Source:
- src/utils/Color.js line 1162
Returns:
The Blue component of the color, will be between 0 and 255 (0 being no color, 255 full Blue).
- Type
- number
-
<static> getColor(r, g, b)
-
Given 3 color values this will return an integer representation of it.
Parameters:
Name Type Description r
number The red color component, in the range 0 - 255.
g
number The green color component, in the range 0 - 255.
b
number The blue color component, in the range 0 - 255.
- Source:
- src/utils/Color.js line 609
Returns:
A native color value integer (format: 0xRRGGBB).
- Type
- number
-
<static> getColor32(a, r, g, b)
-
Given an alpha and 3 color values this will return an integer representation of it.
Parameters:
Name Type Description a
number The alpha color component, in the range 0 - 255.
r
number The red color component, in the range 0 - 255.
g
number The green color component, in the range 0 - 255.
b
number The blue color component, in the range 0 - 255.
- Source:
- src/utils/Color.js line 593
Returns:
A native color value integer (format: 0xAARRGGBB).
- Type
- number
-
<static> getGreen(color)
-
Given a native color value (in the format 0xAARRGGBB) this will return the Green component, as a value between 0 and 255.
Parameters:
Name Type Description color
number In the format 0xAARRGGBB.
- Source:
- src/utils/Color.js line 1149
Returns:
The Green component of the color, will be between 0 and 255 (0 being no color, 255 full Green).
- Type
- number
-
<static> getRandomColor( [min] [, max] [, alpha])
-
Returns a random color value between black and white Set the min value to start each channel from the given offset. Set the max value to restrict the maximum color used per channel.
Parameters:
Name Type Argument Default Description min
number <optional>
0 The lowest value to use for the color.
max
number <optional>
255 The highest value to use for the color.
alpha
number <optional>
255 The alpha value of the returning color (default 255 = fully opaque).
- Source:
- src/utils/Color.js line 1017
Returns:
32-bit color value with alpha.
- Type
- number
-
<static> getRed(color)
-
Given a native color value (in the format 0xAARRGGBB) this will return the Red component, as a value between 0 and 255.
Parameters:
Name Type Description color
number In the format 0xAARRGGBB.
- Source:
- src/utils/Color.js line 1136
Returns:
The Red component of the color, will be between 0 and 255 (0 being no color, 255 full Red).
- Type
- number
-
<static> getRGB(color)
-
Return the component parts of a color as an Object with the properties alpha, red, green, blue.
Alpha will only be set if it exist in the given color (0xAARRGGBB)
Parameters:
Name Type Description color
number Color in RGB (0xRRGGBB) or ARGB format (0xAARRGGBB).
- Source:
- src/utils/Color.js line 1048
Returns:
An Object with properties: alpha, red, green, blue (also r, g, b and a). Alpha will only be present if a color value > 16777215 was given.
- Type
- object
-
<static> getWebRGB(color)
-
Returns a CSS friendly string value from the given color.
Parameters:
Name Type Description color
number | Object Color in RGB (0xRRGGBB), ARGB format (0xAARRGGBB) or an Object with r, g, b, a properties.
- Source:
- src/utils/Color.js line 1089
Returns:
A string in the format: 'rgba(r,g,b,a)'
- Type
- string
-
<static> hexToColor(hex [, out])
-
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.
Parameters:
Name Type Argument Description hex
string The color string in a hex format.
out
object <optional>
An object into which 3 properties will be created or set: r, g and b. If not provided a new object will be created.
- Source:
- src/utils/Color.js line 670
Returns:
An object with the red, green and blue values set in the r, g and b properties.
- Type
- object
-
<static> hexToRGB(hex)
-
Converts a hex string into an integer color value.
Parameters:
Name Type Description hex
string The hex string to convert. Can be in the short-hand format
#03f
or#0033ff
.- Source:
- src/utils/Color.js line 652
Returns:
The rgb color value in the format 0xAARRGGBB.
- Type
- number
-
<static> hexToRGBArray(color)
-
Converts a hex color value to an [R, G, B] array.
Parameters:
Name Type Description color
number The color to convert to an RGB array. In the format 0xRRGGBB.
- Source:
- src/utils/Color.js line 246
Returns:
An array with element 0 containing the Red value, 1 containing Green, and 2 containing Blue.
- Type
- array
-
<static> HSLColorWheel( [s] [, l])
-
Get HSL color wheel values in an array which will be 360 elements in size.
Parameters:
Name Type Argument Default Description s
number <optional>
0.5 The saturation, in the range 0 - 1.
l
number <optional>
0.5 The lightness, in the range 0 - 1.
- Source:
- src/utils/Color.js line 841
Returns:
An array containing 360 elements corresponding to the HSL color wheel.
- Type
- array
-
<static> HSLtoRGB(h, s, l [, out])
-
Converts an HSL (hue, saturation and lightness) color value to RGB. Conversion forumla from http://en.wikipedia.org/wiki/HSL_color_space. Assumes HSL values are contained in the set [0, 1] and returns r, g and b values in the set [0, 255]. Based on code by Michael Jackson (https://github.com/mjijackson)
Parameters:
Name Type Argument Description h
number The hue, in the range 0 - 1.
s
number The saturation, in the range 0 - 1.
l
number The lightness, in the range 0 - 1.
out
object <optional>
An object into which 3 properties will be created: r, g and b. If not provided a new object will be created.
- Source:
- src/utils/Color.js line 334
Returns:
An object with the red, green and blue values set in the r, g and b properties.
- Type
- object
-
<static> HSVColorWheel( [s] [, v])
-
Get HSV color wheel values in an array which will be 360 elements in size.
Parameters:
Name Type Argument Default Description s
number <optional>
1 The saturation, in the range 0 - 1.
v
number <optional>
1 The value, in the range 0 - 1.
- Source:
- src/utils/Color.js line 817
Returns:
An array containing 360 elements corresponding to the HSV color wheel.
- Type
- array
-
<static> HSVtoRGB(h, s, v [, out])
-
Converts an HSV (hue, saturation and value) color value to RGB. Conversion forumla from http://en.wikipedia.org/wiki/HSL_color_space. Assumes HSV values are contained in the set [0, 1] and returns r, g and b values in the set [0, 255]. Based on code by Michael Jackson (https://github.com/mjijackson)
Parameters:
Name Type Argument Description h
number The hue, in the range 0 - 1.
s
number The saturation, in the range 0 - 1.
v
number The value, in the range 0 - 1.
out
object <optional>
An object into which 3 properties will be created: r, g and b. If not provided a new object will be created.
- Source:
- src/utils/Color.js line 441
Returns:
An object with the red, green and blue values set in the r, g and b properties.
- Type
- object
-
<static> hueToColor(p, q, t)
-
Converts a hue to an RGB color. Based on code by Michael Jackson (https://github.com/mjijackson)
Parameters:
Name Type Description p
number q
number t
number - Source:
- src/utils/Color.js line 509
Returns:
The color component value.
- Type
- number
-
<static> interpolateColor(color1, color2, steps, currentStep [, alpha] [, colorSpace])
-
Interpolates the two given colours based on the supplied step and currentStep properties.
Parameters:
Name Type Argument Default Description color1
number The first color value.
color2
number The second color value.
steps
number The number of steps to run the interpolation over.
currentStep
number The currentStep value. If the interpolation will take 100 steps, a currentStep value of 50 would be half-way between the two.
alpha
number <optional>
The alpha of the returned color.
colorSpace
number <optional>
0 The color space to interpolate in. 0 = RGB, 1 = HSV.
- Source:
- src/utils/Color.js line 865
Returns:
The interpolated color value.
- Type
- number
-
<static> interpolateColorWithRGB(color, r, g, b, steps, currentStep)
-
Interpolates the two given colours based on the supplied step and currentStep properties.
Parameters:
Name Type Description color
number The first color value.
r
number The red color value, between 0 and 0xFF (255).
g
number The green color value, between 0 and 0xFF (255).
b
number The blue color value, between 0 and 0xFF (255).
steps
number The number of steps to run the interpolation over.
currentStep
number The currentStep value. If the interpolation will take 100 steps, a currentStep value of 50 would be half-way between the two.
- Source:
- src/utils/Color.js line 932
Returns:
The interpolated color value.
- Type
- number
-
<static> interpolateRGB(r1, g1, b1, r2, g2, b2, steps, currentStep)
-
Interpolates the two given colours based on the supplied step and currentStep properties.
Parameters:
Name Type Description r1
number The red color value, between 0 and 0xFF (255).
g1
number The green color value, between 0 and 0xFF (255).
b1
number The blue color value, between 0 and 0xFF (255).
r2
number The red color value, between 0 and 0xFF (255).
g2
number The green color value, between 0 and 0xFF (255).
b2
number The blue color value, between 0 and 0xFF (255).
steps
number The number of steps to run the interpolation over.
currentStep
number The currentStep value. If the interpolation will take 100 steps, a currentStep value of 50 would be half-way between the two.
- Source:
- src/utils/Color.js line 955
Returns:
The interpolated color value.
- Type
- number
-
<static> linear(color1, color2, t)
-
Calculates a linear (interpolation) value of two colors over t.
This is a slightly simpler interface to Phaser.Color.interpolateColor.
The arguments are similar to Phaser.Math.linear.
Parameters:
Name Type Description color1
number The first color value.
color2
number The second color value.
t
number A value between 0 and 1.
- Source:
- src/utils/Color.js line 978
Returns:
The interpolated color value.
- Type
- number
-
<static> linearInterpolation(colors, t)
-
Calculates a linear (interpolation) value of an array of colors over t.
The arguments are similar to Phaser.Math.linearInterpolation.
This can be used as a Phaser.TweenData#interpolationFunction.
Parameters:
Name Type Description colors
Array.<number> The input array of color values to interpolate between.
t
number The amount of interpolation, between 0 (start) and 1 (end).
- Source:
- src/utils/Color.js line 996
Returns:
The interpolated color value.
- Type
- number
-
<static> packPixel(r, g, b, a)
-
Packs the r, g, b, a components into a single integer, for use with Int32Array. If device is little endian then ABGR order is used. Otherwise RGBA order is used.
Parameters:
Name Type Description r
number The red color component, in the range 0 - 255.
g
number The green color component, in the range 0 - 255.
b
number The blue color component, in the range 0 - 255.
a
number The alpha color component, in the range 0 - 255.
- Source:
- src/utils/Color.js line 104
Returns:
The packed color as uint32
- Type
- number
-
<static> RGBArrayToHex(rgb)
-
Converts an RGB color array, in the format: [R, G, B], to a hex color value.
Parameters:
Name Type Description rgb
array An array with element 0 containing the Red value, 1 containing Green, and 2 containing Blue.
- Source:
- src/utils/Color.js line 263
Returns:
The color value, in the format 0xRRGGBB.
- Type
- number
-
<static> RGBtoHSL(r, g, b [, out])
-
Converts an RGB color value to HSL (hue, saturation and lightness). Conversion forumla from http://en.wikipedia.org/wiki/HSL_color_space. Assumes RGB values are contained in the set [0, 255] and returns h, s and l in the set [0, 1]. Based on code by Michael Jackson (https://github.com/mjijackson)
Parameters:
Name Type Argument Description r
number The red color component, in the range 0 - 255.
g
number The green color component, in the range 0 - 255.
b
number The blue color component, in the range 0 - 255.
out
object <optional>
An object into which 3 properties will be created, h, s and l. If not provided a new object will be created.
- Source:
- src/utils/Color.js line 276
Returns:
An object with the hue, saturation and lightness values set in the h, s and l properties.
- Type
- object
-
<static> RGBtoHSV(r, g, b [, out])
-
Converts an RGB color value to HSV (hue, saturation and value). Conversion forumla 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)
Parameters:
Name Type Argument Description r
number The red color component, in the range 0 - 255.
g
number The green color component, in the range 0 - 255.
b
number The blue color component, in the range 0 - 255.
out
object <optional>
An object into which 3 properties will be created, h, s and v. If not provided a new object will be created.
- Source:
- src/utils/Color.js line 386
Returns:
An object with the hue, saturation and value set in the h, s and v properties.
- Type
- object
-
<static> RGBtoString(r, g, b [, a] [, prefix])
-
Converts the given color values into a string. If prefix was '#' it will be in the format
#RRGGBB
otherwise0xAARRGGBB
.Parameters:
Name Type Argument Default Description r
number The red color component, in the range 0 - 255.
g
number The green color component, in the range 0 - 255.
b
number The blue color component, in the range 0 - 255.
a
number <optional>
255 The alpha color component, in the range 0 - 255.
prefix
string <optional>
'#' The prefix used in the return string. If '#' it will return
#RRGGBB
, else0xAARRGGBB
.- Source:
- src/utils/Color.js line 624
Returns:
A string containing the color values. If prefix was '#' it will be in the format
#RRGGBB
otherwise0xAARRGGBB
.- Type
- string
-
<static> toABGR(r, g, b, a)
-
Converts RGBA components to a 32 bit integer in AABBGGRR format.
Parameters:
Name Type Description r
number The red color component, in the range 0 - 255.
g
number The green color component, in the range 0 - 255.
b
number The blue color component, in the range 0 - 255.
a
number The alpha color component, in the range 0 - 255.
- Source:
- src/utils/Color.js line 230
Returns:
A RGBA-packed 32 bit integer
- Type
- number
-
<static> toRGBA(r, g, b, a)
-
A utility to convert RGBA components to a 32 bit integer in RRGGBBAA format.
Parameters:
Name Type Description r
number The red color component, in the range 0 - 255.
g
number The green color component, in the range 0 - 255.
b
number The blue color component, in the range 0 - 255.
a
number The alpha color component, in the range 0 - 255.
- Source:
- src/utils/Color.js line 213
Returns:
A RGBA-packed 32 bit integer
- Type
- number
-
<static> unpackPixel(rgba [, out] [, hsl] [, hsv])
-
Unpacks the r, g, b, a components into the specified color object, or a new object, for use with Int32Array. If little endian, then ABGR order is used when unpacking, otherwise, RGBA order is used. The resulting color object has the
r, g, b, a
properties which are unrelated to endianness.Note that the integer is assumed to be packed in the correct endianness. On little-endian the format is 0xAABBGGRR and on big-endian the format is 0xRRGGBBAA. If you want a endian-independent method, use fromRGBA(rgba) and toRGBA(r, g, b, a).
Parameters:
Name Type Argument Default Description rgba
number The integer, packed in endian order by packPixel.
out
object <optional>
An object into which 3 properties will be created: r, g and b. If not provided a new object will be created.
hsl
boolean <optional>
false Also convert the rgb values into hsl?
hsv
boolean <optional>
false Also convert the rgb values into hsv?
- Source:
- src/utils/Color.js line 129
Returns:
An object with the red, green and blue values set in the r, g and b properties.
- Type
- object
-
<static> updateColor(out)
-
Takes a color object and updates the rgba, color and color32 properties.
Parameters:
Name Type Description out
object The color object to update.
- Source:
- src/utils/Color.js line 576
Returns:
A native color value integer (format: 0xAARRGGBB).
- Type
- number
-
<static> valueToColor(value [, out])
-
Converts a value - a "hex" string, a "CSS 'web' string", or a number - into red, green, blue, and alpha components.
The value can be a string (see
hexToColor
andwebToColor
for the supported formats) or a packed integer (seegetRGB
).An alpha channel is not supported when specifying a hex string.
Parameters:
Name Type Argument Description value
string | number The color expressed as a recognized string format or a packed integer.
out
object <optional>
The object to use for the output. If not provided a new object will be created.
- Source:
- src/utils/Color.js line 746
Returns:
The (
out
) object with the red, green, blue, and alpha values set as the r/g/b/a properties.- Type
- object
-
<static> webToColor(web [, out])
-
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].Parameters:
Name Type Argument Description web
string The color string in CSS 'web' format.
out
object <optional>
An object into which 4 properties will be created: r, g, b and a. If not provided a new object will be created.
- Source:
- src/utils/Color.js line 714
Returns:
An object with the red, green, blue and alpha values set in the r, g, b and a properties.
- Type
- object