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

<p>Set the min value to start each channel from the given offset.</p> <p>Set the max value to restrict the maximum color used per channel</p>

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

<p>Alpha will only be set if it exist in the given color (0xAARRGGBB)</p>

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

Converts the given hex string into an object containing the RGB values.

Parameters:
Name Type Description
h string

The string hex color to convert.

Source:
Returns:

An object with 3 properties: r,g and b.

Type
object

<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

Description.

color2 number

Description.

steps number

Description.

currentStep number

Description.

alpha number

Description.

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

Description.

r number

Description.

g number

Description.

b number

Description.

steps number

Description.

currentStep number

Description.

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

Description.

g1 number

Description.

b1 number

Description.

r2 number

Description.

g2 number

Description.

b2 number

Description.

steps number

Description.

currentStep number

Description.

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-2013 Photon Storm Ltd.
Documentation generated by JSDoc 3.2.0-dev on Wed Oct 23 2013 13:51:59 GMT+0100 (BST) using the DocStrap template.