phaser - v4.0.0-rc.4
    Preparing search index...

    The Color class holds a single color value and allows for easy modification and reading of it.

    Index

    Constructors

    • Parameters

      • Optionalred: number

        The red color value. A number between 0 and 255. Default 0.

      • Optionalgreen: number

        The green color value. A number between 0 and 255. Default 0.

      • Optionalblue: number

        The blue color value. A number between 0 and 255. Default 0.

      • Optionalalpha: number

        The alpha value. A number between 0 and 255. Default 255.

      Returns Display.Color

    Properties

    alpha: number

    The alpha color value, normalized to the range 0 to 255.

    alphaGL: number

    The alpha color value, normalized to the range 0 to 1.

    blue: number

    The blue color value, normalized to the range 0 to 255.

    blueGL: number

    The blue color value, normalized to the range 0 to 1.

    color: number

    The color of this Color component, not including the alpha channel.

    color32: number

    The color of this Color component, including the alpha channel.

    gl: number[]

    An array containing the calculated color values for WebGL use.

    green: number

    The green color value, normalized to the range 0 to 255.

    greenGL: number

    The green color value, normalized to the range 0 to 1.

    h: number

    The hue color value. A number between 0 and 1. This is the base color.

    red: number

    The red color value, normalized to the range 0 to 255.

    redGL: number

    The red color value, normalized to the range 0 to 1.

    rgba: string

    The color of this Color component as a string which can be used in CSS color values.

    s: number

    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.

    v: number

    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.

    Methods

    • Brighten this Color by the percentage amount given.

      Parameters

      • amount: number

        The percentage amount to change this color by. A value between 0 and 100.

      Returns Display.Color

    • Decrease the lightness of this Color by the percentage amount given.

      Parameters

      • amount: number

        The percentage amount to change this color by. A value between 0 and 100.

      Returns Display.Color

    • Decrease the saturation of this Color by the percentage amount given. The saturation is the amount of the base color in the hue.

      Parameters

      • amount: number

        The percentage amount to change this color by. A value between 0 and 100.

      Returns Display.Color

    • Increase the lightness of this Color by the percentage amount given.

      Parameters

      • amount: number

        The percentage amount to change this color by. A value between 0 and 100.

      Returns Display.Color

    • Sets this Color object to be a random color between the min and max values given.

      Parameters

      • Optionalmin: number

        The minimum random color value. Between 0 and 255. Default 0.

      • Optionalmax: number

        The maximum random color value. Between 0 and 255. Default 255.

      Returns Display.Color

    • Sets this Color object to be a random grayscale color between the min and max values given.

      Parameters

      • Optionalmin: number

        The minimum random color value. Between 0 and 255. Default 0.

      • Optionalmax: number

        The maximum random color value. Between 0 and 255. Default 255.

      Returns Display.Color

    • Increase the saturation of this Color by the percentage amount given. The saturation is the amount of the base color in the hue.

      Parameters

      • amount: number

        The percentage amount to change this color by. A value between 0 and 100.

      Returns Display.Color

    • Sets the color based on the hue, saturation and lightness values given.

      Parameters

      • 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.

      Returns Display.Color

    • Sets the red, green, blue and alpha GL values of this Color component.

      Parameters

      • 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.

      • Optionalalpha: number

        The alpha value. A number between 0 and 1. Default 1.

      Returns Display.Color

    • Sets the color of this Color component.

      Parameters

      • 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.

      • Optionalalpha: number

        The alpha value. A number between 0 and 255. Default 255.

      • OptionalupdateHSV: boolean

        Update the HSV values after setting the RGB values? Default true.

      Returns Display.Color

    • 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.

      Parameters

      • Optionallimit: number

        How many colors should be returned? The maximum is 1024 but you can set a smaller quantity if required. Default 1024.

      Returns ColorObject[]

    • Converts the given color value into an Object containing r,g,b and a properties.

      Parameters

      • color: number

        A color value, optionally including the alpha value.

      Returns ColorObject

    • Returns a string containing a hex representation of the given color component.

      Parameters

      • color: number

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

      Returns string

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

      Parameters

      • 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.

      Returns number

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

      Parameters

      • 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.

      Returns number

    • 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

      • hex: string

        The hex color value to convert, such as #0033ff or the short-hand format: #03f.

      Returns Display.Color

    • Converts HSL (hue, saturation and lightness) values to a Phaser Color object.

      Parameters

      • 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.

      Returns Display.Color

    • Generates an HSV color wheel which is an array of 360 Color objects, for each step of the wheel.

      Parameters

      • Optionals: number

        The saturation, in the range 0 - 1. Default 1.

      • Optionalv: number

        The value, in the range 0 - 1. Default 1.

      Returns ColorObject[]

    • 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].

      Parameters

      • 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.

      • Optionalout: Display.Color | ColorObject

        A Color object to store the results in. If not given a new ColorObject will be created.

      Returns Display.Color | ColorObject

    • Converts the given color value into an instance of a Color object.

      Parameters

      • input: number

        The color value to convert into a Color object.

      Returns Display.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 exists in the given color (0xAARRGGBB)

      Parameters

      • input: number

        The color value to convert into a Color object.

      Returns ColorObject

    • 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.

      Parameters

      • Optionalmin: number

        The minimum value to set the random range from (between 0 and 255) Default 0.

      • Optionalmax: number

        The maximum value to set the random range from (between 0 and 255) Default 255.

      Returns Display.Color

    • 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

      • rgb: string

        The CSS format color string, using the rgb or rgba format.

      Returns Display.Color

    • Converts the color values into an HTML compatible color string, prefixed with either # or 0x.

      Parameters

      • 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.

      • Optionala: number

        The alpha value. A number between 0 and 255. Default 255.

      • Optionalprefix: string

        The prefix of the string. Either # or 0x. Default #.

      Returns string