Class representing a color, based on Int. Provides a variety of methods for creating and converting colors.

FlxColors can be written as Ints. This means you can pass a hex value such as 0xff123456 to a function expecting a FlxColor, and it will automatically become a FlxColor "object". Similarly, FlxColors may be treated as Ints.

Note that when using properties of a FlxColor other than ARGB, the values are ultimately stored as ARGB values, so repeatedly manipulating HSB/HSL/CMYK values may result in a gradual loss of precision.

Static variables

@:value(0xFF000000)staticinlineread onlyBLACK:FlxColor = 0xFF000000

@:value(0xFF0000FF)staticinlineread onlyBLUE:FlxColor = 0xFF0000FF

@:value(0xFF8B4513)staticinlineread onlyBROWN:FlxColor = 0xFF8B4513

@:value(0xFF00FFFF)staticinlineread onlyCYAN:FlxColor = 0xFF00FFFF

@:value(0xFF808080)staticinlineread onlyGRAY:FlxColor = 0xFF808080

@:value(0xFF008000)staticinlineread onlyGREEN:FlxColor = 0xFF008000

@:value(0xFF00FF00)staticinlineread onlyLIME:FlxColor = 0xFF00FF00

@:value(0xFFFF00FF)staticinlineread onlyMAGENTA:FlxColor = 0xFFFF00FF

@:value(0xFFFFA500)staticinlineread onlyORANGE:FlxColor = 0xFFFFA500

@:value(0xFFFFC0CB)staticinlineread onlyPINK:FlxColor = 0xFFFFC0CB

@:value(0xFF800080)staticinlineread onlyPURPLE:FlxColor = 0xFF800080

@:value(0xFFFF0000)staticinlineread onlyRED:FlxColor = 0xFFFF0000

@:value(0x00000000)staticinlineread onlyTRANSPARENT:FlxColor = 0x00000000

@:value(0xFFFFFFFF)staticinlineread onlyWHITE:FlxColor = 0xFFFFFFFF

@:value(0xFFFFFF00)staticinlineread onlyYELLOW:FlxColor = 0xFFFFFF00

staticalpha:Int

staticblack:Float

staticblue:Int

staticbrightness:Float

The brightness (aka value) of the color (from 0 to 1)

@:value(FlxMacroUtil.buildMap("flixel.util.FlxColor"))staticread onlycolorLookup:Map<String, Int> = FlxMacroUtil.buildMap("flixel.util.FlxColor")

A Map<String, Int> whose values are the static colors of FlxColor. You can add more colors for FlxColor.fromString(String) if you need.

staticcyan:Float

staticgreen:Int

statichue:Float

The hue of the color in degrees (from 0 to 359)

staticlightness:Float

The lightness of the color (from 0 to 1)

staticred:Int

staticrgb:FlxColor

The red, green and blue channels of this color as a 24 bit integer (from 0 to 0xFFFFFF)

staticsaturation:Float

The saturation of the color (from 0 to 1)

Static methods

@:op(A + B)staticinlineadd(lhs:FlxColor, rhs:FlxColor):FlxColor

Add the RGB channels of two FlxColors

@:value({ Alpha : 1 })staticinlinefromCMYK(Cyan:Float, Magenta:Float, Yellow:Float, Black:Float, Alpha:Float = 1):FlxColor

Generate a color from CMYK values (0 to 1)

Parameters:

Cyan

The cyan value of the color from 0 to 1

Magenta

The magenta value of the color from 0 to 1

Yellow

The yellow value of the color from 0 to 1

Black

The black value of the color from 0 to 1

Alpha

How opaque the color should be, from 0 to 1

Returns:

The color as a FlxColor

@:value({ Alpha : 1 })staticfromHSB(Hue:Float, Saturation:Float, Brightness:Float, Alpha:Float = 1):FlxColor

Generate a color from HSB (aka HSV) components.

Parameters:

Hue

A number between 0 and 360, indicating position on a color strip or wheel.

Saturation

A number between 0 and 1, indicating how colorful or gray the color should be. 0 is gray, 1 is vibrant.

Brightness

(aka Value) A number between 0 and 1, indicating how bright the color should be. 0 is black, 1 is full bright.

Alpha

How opaque the color should be, either between 0 and 1 or 0 and 255.

Returns:

The color as a FlxColor

@:value({ Alpha : 1 })staticinlinefromHSL(Hue:Float, Saturation:Float, Lightness:Float, Alpha:Float = 1):FlxColor

Generate a color from HSL components.

Parameters:

Hue

A number between 0 and 360, indicating position on a color strip or wheel.

Saturation

A number between 0 and 1, indicating how colorful or gray the color should be. 0 is gray, 1 is vibrant.

Lightness

A number between 0 and 1, indicating the lightness of the color

Alpha

How opaque the color should be, either between 0 and 1 or 0 and 255.

Returns:

The color as a FlxColor

staticinlinefromInt(Value:Int):FlxColor

Create a color from the least significant four bytes of an Int

Parameters:

Value

And Int with bytes in the format 0xAARRGGBB

Returns:

The color as a FlxColor

@:value({ Alpha : 255 })staticinlinefromRGB(Red:Int, Green:Int, Blue:Int, Alpha:Int = 255):FlxColor

Generate a color from integer RGB values (0 to 255)

Parameters:

Red

The red value of the color from 0 to 255

Green

The green value of the color from 0 to 255

Blue

The green value of the color from 0 to 255

Alpha

How opaque the color should be, from 0 to 255

Returns:

The color as a FlxColor

@:value({ Alpha : 1 })staticinlinefromRGBFloat(Red:Float, Green:Float, Blue:Float, Alpha:Float = 1):FlxColor

Generate a color from float RGB values (0 to 1)

Parameters:

Red

The red value of the color from 0 to 1

Green

The green value of the color from 0 to 1

Blue

The green value of the color from 0 to 1

Alpha

How opaque the color should be, from 0 to 1

Returns:

The color as a FlxColor

@:has_untypedstaticfromString(str:String):Null<FlxColor>

Parses a String and returns a FlxColor or null if the String couldn't be parsed.

Examples (input -> output in hex):

  • 0x00FF00 -> 0xFF00FF00
  • 0xAA4578C2 -> 0xAA4578C2
  • #0000FF -> 0xFF0000FF
  • #3F000011 -> 0x3F000011
  • GRAY -> 0xFF808080
  • blue -> 0xFF0000FF

Parameters:

str

The string to be parsed

Returns:

A FlxColor or null if the String couldn't be parsed

@:value({ Threshold : 30 })staticinlinegetAnalogousHarmony(this:Int, Threshold:Int = 30):Harmony

Returns an Analogous Color Harmony for the given color. An Analogous harmony are hues adjacent to each other on the color wheel

Parameters:

Threshold

Control how adjacent the colors will be (default +- 30 degrees)

Returns:

Object containing 3 properties: original (the original color), warmer (the warmer analogous color) and colder (the colder analogous color)

staticgetColorInfo(this:Int):String

Get a string of color information about this color

Returns:

A string containing information about this color

staticinlinegetComplementHarmony(this:Int):FlxColor

Returns a Complementary Color Harmony of this color. A complementary hue is one directly opposite the color given on the color wheel

Returns:

The complimentary color

@:value({ Factor : 0.2 })staticgetDarkened(this:Int, Factor:Float = 0.2):FlxColor

Get a darkened version of this color

Parameters:

Factor

Value from 0 to 1 of how much to progress toward black.

Returns:

A darkened version of this color

@:value({ Alpha : 255 })staticgetHSBColorWheel(Alpha:Int = 255):Array<FlxColor>

Get HSB color wheel values in an array which will be 360 elements in size

Parameters:

Alpha

Alpha value for each color of the color wheel, between 0 (transparent) and 255 (opaque)

Returns:

HSB color wheel as Array of FlxColors

staticinlinegetInverted(this:Int):FlxColor

Get the inversion of this color

Returns:

The inversion of this color

@:value({ Factor : 0.2 })staticinlinegetLightened(this:Int, Factor:Float = 0.2):FlxColor

Get a lightened version of this color

Parameters:

Factor

Value from 0 to 1 of how much to progress toward white.

Returns:

A lightened version of this color

@:value({ Threshold : 30 })staticinlinegetSplitComplementHarmony(this:Int, Threshold:Int = 30):Harmony

Returns an Split Complement Color Harmony for this color. A Split Complement harmony are the two hues on either side of the color's Complement

Parameters:

Threshold

Control how adjacent the colors will be to the Complement (default +- 30 degrees)

Returns:

Object containing 3 properties: original (the original color), warmer (the warmer analogous color) and colder (the colder analogous color)

staticinlinegetTriadicHarmony(this:Int):TriadicHarmony

Returns a Triadic Color Harmony for this color. A Triadic harmony are 3 hues equidistant from each other on the color wheel.

Returns:

Object containing 3 properties: color1 (the original color), color2 and color3 (the equidistant colors)

staticgradient(Color1:FlxColor, Color2:FlxColor, Steps:Int, ?Ease:Float ‑> Float):Array<FlxColor>

Create a gradient from one color to another

Parameters:

Color1

The color to shift from

Color2

The color to shift to

Steps

How many colors the gradient should have

Ease

An optional easing function, such as those provided in FlxEase

Returns:

An array of colors of length Steps, shifting from Color1 to Color2

@:value({ Factor : 0.5 })staticinlineinterpolate(Color1:FlxColor, Color2:FlxColor, Factor:Float = 0.5):FlxColor

Get an interpolated color based on two different colors.

Parameters:

Color1

The first color

Color2

The second color

Factor

Value from 0 to 1 representing how much to shift Color1 toward Color2

Returns:

The interpolated color

@:op(A * B)staticinlinemultiply(lhs:FlxColor, rhs:FlxColor):FlxColor

Multiply the RGB channels of two FlxColors

@:value({ Alpha : 1 })staticinlinesetCMYK(this:Int, Cyan:Float, Magenta:Float, Yellow:Float, Black:Float, Alpha:Float = 1):FlxColor

Set CMYK values as floats (0 to 1)

Parameters:

Cyan

The cyan value of the color from 0 to 1

Magenta

The magenta value of the color from 0 to 1

Yellow

The yellow value of the color from 0 to 1

Black

The black value of the color from 0 to 1

Alpha

How opaque the color should be, from 0 to 1

Returns:

This color

staticinlinesetHSB(this:Int, Hue:Float, Saturation:Float, Brightness:Float, Alpha:Float):FlxColor

Set HSB (aka HSV) components

Parameters:

Hue

A number between 0 and 360, indicating position on a color strip or wheel.

Saturation

A number between 0 and 1, indicating how colorful or gray the color should be. 0 is gray, 1 is vibrant.

Brightness

(aka Value) A number between 0 and 1, indicating how bright the color should be. 0 is black, 1 is full bright.

Alpha

How opaque the color should be, either between 0 and 1 or 0 and 255.

Returns:

This color

staticinlinesetHSL(this:Int, Hue:Float, Saturation:Float, Lightness:Float, Alpha:Float):FlxColor

Set HSL components.

Parameters:

Hue

A number between 0 and 360, indicating position on a color strip or wheel.

Saturation

A number between 0 and 1, indicating how colorful or gray the color should be. 0 is gray, 1 is vibrant.

Lightness

A number between 0 and 1, indicating the lightness of the color

Alpha

How opaque the color should be, either between 0 and 1 or 0 and 255

Returns:

This color

@:value({ Alpha : 255 })staticinlinesetRGB(this:Int, Red:Int, Green:Int, Blue:Int, Alpha:Int = 255):FlxColor

Set RGB values as integers (0 to 255)

Parameters:

Red

The red value of the color from 0 to 255

Green

The green value of the color from 0 to 255

Blue

The green value of the color from 0 to 255

Alpha

How opaque the color should be, from 0 to 255

Returns:

This color

@:value({ Alpha : 1 })staticinlinesetRGBFloat(this:Int, Red:Float, Green:Float, Blue:Float, Alpha:Float = 1):FlxColor

Set RGB values as floats (0 to 1)

Parameters:

Red

The red value of the color from 0 to 1

Green

The green value of the color from 0 to 1

Blue

The green value of the color from 0 to 1

Alpha

How opaque the color should be, from 0 to 1

Returns:

This color

@:op(A - B)staticinlinesubtract(lhs:FlxColor, rhs:FlxColor):FlxColor

Subtract the RGB channels of one FlxColor from another

staticinlineto24Bit(this:Int):FlxColor

Return a 24 bit version of this color (i.e. without an alpha value)

Returns:

A 24 bit version of this color

@:value({ Prefix : true, Alpha : true })staticinlinetoHexString(this:Int, Alpha:Bool = true, Prefix:Bool = true):String

Return a String representation of the color in the format

Parameters:

Alpha

Whether to include the alpha value in the hex string

Prefix

Whether to include "0x" prefix at start of string

Returns:

A string of length 10 in the format 0xAARRGGBB

staticinlinetoWebString(this:Int):String

Return a String representation of the color in the format #RRGGBB

Returns:

A string of length 7 in the format #RRGGBB