Options
All
  • Public
  • Public/Protected
  • All
Menu

Provides standard colors (e.g. Color.Black) but you can also create custom colors using RGB, HSL, or Hex. Also provides useful color operations like Color.lighten, Color.darken, and more.

Creating colors

// RGBA
new ex.Color(r, g, b, a);
ex.Color.fromRGB(r, g, b, a);

// HSLA
ex.Color.fromHSL(h, s, l, a);
// Hex, alpha optional
ex.Color.fromHex('#000000');
ex.Color.fromHex('#000000FF');

// String representation of a color with rgb as default
// Options include rgb,hsl,hex
ex.Color.toString('rgb');

Working with colors

Since Javascript does not support structs, if you change a color "constant" like Color.Black it will change it across the entire game. You can safely use the color operations like Color.lighten and Color.darken because they clone the color to return a new color. However, be aware that this can use up memory if used excessively.

Just be aware that if you directly alter properties (i.e. Color.r, etc.) , this will change it for all the code that uses that instance of Color.

Hierarchy

  • Color

Index

Constructors

constructor

  • new Color(r: number, g: number, b: number, a?: number): Color
  • Creates a new instance of Color from an r, g, b, a

    Parameters

    • r: number

      The red component of color (0-255)

    • g: number

      The green component of color (0-255)

    • b: number

      The blue component of color (0-255)

    • Optional a: number

      The alpha component of color (0-1.0)

    Returns Color

Properties

a

a: number

Alpha channel (between 0 and 1)

b

b: number

Blue channel

g

g: number

Green channel

h

h: number

Hue

l

l: number

Lightness

r

r: number

Red channel

s

s: number

Saturation

Static Azure

Azure: Color = Color.fromHex('#007FFF')

Azure (#007FFF)

Static Black

Black: Color = Color.fromHex('#000000')

Black (#000000)

Static Blue

Blue: Color = Color.fromHex('#0000FF')

Blue (#0000FF)

Static Chartreuse

Chartreuse: Color = Color.fromHex('#7FFF00')

Chartreuse (#7FFF00)

Static Cyan

Cyan: Color = Color.fromHex('#00FFFF')

Cyan (#00FFFF)

Static DarkGray

DarkGray: Color = Color.fromHex('#A9A9A9')

Dark gray (#A9A9A9)

Static Gray

Gray: Color = Color.fromHex('#808080')

Gray (#808080)

Static Green

Green: Color = Color.fromHex('#00FF00')

Green (#00FF00)

Static LightGray

LightGray: Color = Color.fromHex('#D3D3D3')

Light gray (#D3D3D3)

Static Magenta

Magenta: Color = Color.fromHex('#FF00FF')

Magenta (#FF00FF)

Static Orange

Orange: Color = Color.fromHex('#FFA500')

Orange (#FFA500)

Static Red

Red: Color = Color.fromHex('#FF0000')

Red (#FF0000)

Static Rose

Rose: Color = Color.fromHex('#FF007F')

Rose (#FF007F)

Static Transparent

Transparent: Color = Color.fromHex('#FFFFFF00')

Transparent (#FFFFFF00)

Static Vermillion

Vermillion: Color = Color.fromHex('#FF5B31')

Vermillion (#FF5B31)

Static Violet

Violet: Color = Color.fromHex('#7F00FF')

Violet (#7F00FF)

Static Viridian

Viridian: Color = Color.fromHex('#59978F')

Viridian (#59978F)

Static White

White: Color = Color.fromHex('#FFFFFF')

White (#FFFFFF)

Static Yellow

Yellow: Color = Color.fromHex('#FFFF00')

Yellow (#FFFF00)

Methods

average

clone

darken

  • darken(factor?: number): Color
  • Darkens the current color by a specified amount

    Parameters

    • Default value factor: number = 0.1

      The amount to darken by [0-1]

    Returns Color

desaturate

  • desaturate(factor?: number): Color
  • Desaturates the current color by a specified amount

    Parameters

    • Default value factor: number = 0.1

      The amount to desaturate by [0-1]

    Returns Color

fillStyle

  • fillStyle(): string

invert

lighten

  • lighten(factor?: number): Color
  • Lightens the current color by a specified amount

    Parameters

    • Default value factor: number = 0.1

      The amount to lighten by [0-1]

    Returns Color

mulitiply

saturate

  • saturate(factor?: number): Color
  • Saturates the current color by a specified amount

    Parameters

    • Default value factor: number = 0.1

      The amount to saturate by [0-1]

    Returns Color

screen

toHSLA

  • toHSLA(): string

toHex

  • toHex(): string

toRGBA

  • toRGBA(): string

toString

  • toString(format?: "rgb" | "hsl" | "hex"): string
  • Returns a CSS string representation of a color.

    Parameters

    • Default value format: "rgb" | "hsl" | "hex" = "rgb"

      Color representation, accepts: rgb, hsl, or hex

    Returns string

Static fromHSL

  • fromHSL(h: number, s: number, l: number, a?: number): Color
  • Creats a new instance of Color from hsla values

    Parameters

    • h: number

      Hue is represented [0-1]

    • s: number

      Saturation is represented [0-1]

    • l: number

      Luminance is represented [0-1]

    • Default value a: number = 1

      Alpha is represented [0-1]

    Returns Color

Static fromHex

  • fromHex(hex: string): Color
  • Creates a new inscance of Color from a hex string

    Parameters

    • hex: string

      CSS color string of the form #ffffff, the alpha component is optional

    Returns Color

Static fromRGB

  • fromRGB(r: number, g: number, b: number, a?: number): Color
  • Creates a new instance of Color from an r, g, b, a

    Parameters

    • r: number

      The red component of color (0-255)

    • g: number

      The green component of color (0-255)

    • b: number

      The blue component of color (0-255)

    • Optional a: number

      The alpha component of color (0-1.0)

    Returns Color