Skip to content

Instantiable FlxColors #209

@IQAndreas

Description

@IQAndreas

I touched on this in the FlxColor spreadsheet, here I will elaborate.

Right now, we have lots of static methods that all follow the same pattern (some of them I just added to make a point):

  • RGBtoHex(r, g, b):uint
  • RGBtoHexString(r, g, b):String
  • RGBtoHSV(r, g, b)
  • HexToHSV(uint)
  • RGBtoHSB()
  • HSVtoRGB()
  • etc.

Along with those we also find things like getGreen(uint), getBlue(uint), getAlpha(uint), getAlphaFloat(uint).

This all to me looks very messy, and we can keep adding conversion methods until the cows come home.

Instead, how about we allow people to create instances of FlxColor:

var royalBlue:FlxColor = new FlxColor(0xFF040585);
trace(royalBlue.red); // 4
trace(royalBlue.alphaFloat); // 1.0;

If they don't want to use a hex value, they can use one of the static helper methods:

var royalBlue = FlxColor.fromHSB(240, 97, 52);
var royalBlue = FlxColor.fromRGB(4, 5, 133);
var royalBlue = FlxColor.fromCMYK(97, 96, 0, 48);

And if they want to convert one color to another:

var royalBlue:FlxColor = new FlxColor(0x040585);
var hsv = royalBlue.toHSV();

Or put it on one line:

var hsv = FlxColor.fromRGB(4, 5, 133).toHSV();

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions