Skip to main content

FlixelColor

View source

class

org.flixelgdx.util.FlixelColor

public class FlixelColor

Mutable color wrapper that owns a single Color instance for stable tinting and tween endpoints without per-frame allocations.

Shared presets such as FlixelColor.WHITE and FlixelColor.RED point at the same instances as libGDX Color namesakes. Mutating a preset affects every place that uses that reference. For a private copy, use new FlixelColor(FlixelColor.RED) or FlixelColor.setColor(FlixelColor) on your own instance.

Use FlixelColor.getGdxColor() when you need component access, lerping, or batch tinting; use FlixelColor.getColor() when you need a compact RGBA8888 value.

Constructors

FlixelColor()

public FlixelColor()

Creates a new color with the default white color.


FlixelColor(int, int, int, float)

public FlixelColor(int r, int g, int b, float a)

Creates a new color with the given RGBA values. Values must be in the range 0-255 (with alpha being [0, 1]).

Parameters:

NameDescription
rThe red component.
gThe green component.
bThe blue component.
aThe alpha component (ranged from [0, 1]).

FlixelColor(float, float, float, float)

public FlixelColor(float r, float g, float b, float a)

Creates a new color with the given RGBA values. Values must be in the range 0-1.

Parameters:

NameDescription
rThe red component.
gThe green component.
bThe blue component.
aThe alpha component.

FlixelColor(int)

public FlixelColor(int rgba8888)

Creates a new color from the given packed RGBA8888 value.

Parameters:

NameDescription
rgba8888The packed RGBA8888 value.

FlixelColor(Color)

public FlixelColor(Color source)

Creates a new color from the given Color value.

Parameters:

NameDescription
sourceThe Color value to copy.

FlixelColor(FlixelColor)

public FlixelColor(FlixelColor source)

Creates a new color from the given FlixelColor value.

Parameters:

NameDescription
sourceThe FlixelColor value to copy.

Fields

WHITE

public static final FlixelColor WHITE

BLACK

public static final FlixelColor BLACK

RED

public static final FlixelColor RED

GREEN

public static final FlixelColor GREEN

BLUE

public static final FlixelColor BLUE

YELLOW

public static final FlixelColor YELLOW

CYAN

public static final FlixelColor CYAN

MAGENTA

public static final FlixelColor MAGENTA

GRAY

public static final FlixelColor GRAY

CLEAR

public static final FlixelColor CLEAR

ORANGE

public static final FlixelColor ORANGE

PINK

public static final FlixelColor PINK

PURPLE

public static final FlixelColor PURPLE

BROWN

public static final FlixelColor BROWN

OLIVE

public static final FlixelColor OLIVE

MAROON

public static final FlixelColor MAROON

NAVY

public static final FlixelColor NAVY

TEAL

public static final FlixelColor TEAL

Methods

getColor()

public int getColor()

Returns: Packed RGBA8888, same as libGDX Color.rgba8888(...) on the backing color.


setColor(Color)

public void setColor(Color other)

Copies RGBA from other into this wrapper.

Parameters:

NameDescription
otherThe libGDX color to copy. Must not be null.

setColor(FlixelColor)

public void setColor(FlixelColor other)

Copies RGBA from other into this wrapper.

Parameters:

NameDescription
otherThe Flixel color to copy. Must not be null.

setColor(String)

public void setColor(String hexFormat)

Sets this color from a hex string, same format accepted by libGDX Color.valueOf(...) (for example "ff0000" or "ff0000ff").

Parameters:

NameDescription
hexFormatThe hex string to parse. Must not be null.

getHue()

public float getHue()

Returns: The hue component of this color, in degrees [0, 360).


getSaturation()

public float getSaturation()

Returns: The saturation component of this color, in the range [0, 1].


getValue()

public float getValue()

Returns: The value (brightness) component of this color, in the range [0, 1].


setHue(float)

public void setHue(float hue)

Sets the hue component of this color, leaving saturation, value, and alpha unchanged.

Parameters:

NameDescription
hueThe new hue, in degrees [0, 360).

setSaturation(float)

public void setSaturation(float saturation)

Sets the saturation component of this color, leaving hue, value, and alpha unchanged.

Parameters:

NameDescription
saturationThe new saturation, in the range [0, 1].

setValue(float)

public void setValue(float value)

Sets the value (brightness) component of this color, leaving hue, saturation, and alpha unchanged.

Parameters:

NameDescription
valueThe new value, in the range [0, 1].

getGdxColor()

public Color getGdxColor()

Returns: The backing libGDX color (mutable).