Setting color from RGB values


#1

Any idea how could I set color via rgb, not hex color? Like Color.RGB(1,1,1,1), where last is alpha.


#2

Maybe like this
var color:Int = (Std.int(255 * alpha) & 0xFF) << 24 | (255 & 0xFF) << 16 | (0 & 0xFF) << 8 | (0 & 0xFF);


#3

But, where to put r, g, b values?
like this ? var color:Int = (Std.int(255 * a) & 0xFF) << 24 | (r & 0xFF) << 16 | (g & 0xFF) << 8 | (b & 0xFF);


#4

Try this code:
var a:Int = 255; // alpha 0 - 255
var r:Int = 255; // 0 - 255
var g:Int = 255; // 0 - 255
var b:Int = 255; // 0 - 255
var color:Int = (a & 0xFF) << 24 | (r & 0xFF) << 16 | (g & 0xFF) << 8 | (b & 0xFF);


#5

you can use
var v = new h3d.Vector(r,g,b,a);
v.toColor(); // int value (hex)


#6

Thank you all :wink: