Class: Color

Phaser. Color

new Color()

A collection of methods useful for manipulating and comparing colors.

Source:

Methods

<static> colorToHexstring(color) → {string}

Return a string containing a hex representation of the given color.

Parameters:
Name Type Description
color number

The color channel to get the hex value for, must be a value between 0 and 255).

Source:
Returns:

A string of length 2 characters, i.e. 255 = FF, 0 = 00.

Type
string

<static> getAlpha(color) → {number}

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:
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) → {number}

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:
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) → {number}

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:
Returns:

The Blue component of the color, will be between 0 and 255 (0 being no color, 255 full Blue).

Type
number

<static> getColor(red, green, blue) → {number}

Given 3 color values this will return an integer representation of it.

Parameters:
Name Type Description
red number

The Red channel value (between 0 and 255).

green number

The Green channel value (between 0 and 255).

blue number

The Blue channel value (between 0 and 255).

Source:
Returns:

A native color value integer (format: 0xRRGGBB).

Type
number

<static> getColor32(alpha, red, green, blue) → {number}

Given an alpha and 3 color values this will return an integer representation of it.

Parameters:
Name Type Description
alpha number

The Alpha value (between 0 and 255).

red number

The Red channel value (between 0 and 255).

green number

The Green channel value (between 0 and 255).

blue number

The Blue channel value (between 0 and 255).

Source:
Returns:

A native color value integer (format: 0xAARRGGBB).

Type
number

<static> getColorInfo(color) → {string}

Returns a string containing handy information about the given color including string hex value, RGB format information and HSL information. Each section starts on a newline, 3 lines in total.

Parameters:
Name Type Description
color number

A color value in the format 0xAARRGGBB.

Source:
Returns:

String containing the 3 lines of information.

Type
string

<static> getGreen(color) → {number}

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:
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) → {number}

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 Description
min number

The lowest value to use for the color.

max number

The highest value to use for the color.

alpha number

The alpha value of the returning color (default 255 = fully opaque).

Source:
Returns:

32-bit color value with alpha.

Type
number

<static> getRed(color) → {number}

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:
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) → {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 exist in the given color (0xAARRGGBB)

Parameters:
Name Type Description
color number

Color in RGB (0xRRGGBB) or ARGB format (0xAARRGGBB).

Source:
Returns:

An Object with properties: alpha, red, green, blue.

Type
object

<static> getWebRGB(color) → {string}

Returns a CSS friendly string value from the given color.

Parameters:
Name Type Description
color number
Source:
Returns:

A string in the format: 'rgba(r,g,b,a)'

Type
string

<static> hexToRGB(h) → {number}

Converts the given hex string into an integer color value.

Parameters:
Name Type Description
h string

The string hex color to convert.

Source:
Returns:

The rgb color value.

Type
number

<static> interpolateColor(color1, color2, steps, currentStep, alpha) → {number}

Interpolates the two given colours based on the supplied step and currentStep properties.

Parameters:
Name Type 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

The alpha of the returned color.

Source:
Returns:

The interpolated color value.

Type
number

<static> interpolateColorWithRGB(color, r, g, b, steps, currentStep) → {number}

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:
Returns:

The interpolated color value.

Type
number

<static> interpolateRGB(r1, g1, b1, r2, g2, b2, steps, currentStep) → {number}

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:
Returns:

The interpolated color value.

Type
number

<static> RGBtoHexstring(color) → {string}

Return a string representation of the color in the format 0xAARRGGBB.

Parameters:
Name Type Description
color number

The color to get the string representation for

Source:
Returns:

A string of length 10 characters in the format 0xAARRGGBB

Type
string

<static> RGBtoWebstring(color) → {string}

Return a string representation of the color in the format #RRGGBB.

Parameters:
Name Type Description
color number

The color to get the string representation for.

Source:
Returns:

A string of length 10 characters in the format 0xAARRGGBB.

Type
string
Phaser Copyright © 2012-2014 Photon Storm Ltd.
Documentation generated by JSDoc 3.3.0-dev on Sat Feb 08 2014 07:19:43 GMT-0000 (GMT) using the DocStrap template.