Color
The shared color parser/converter. You rarely call it: everywhere the SDK accepts a color
(sprite.color, material colors, UI styles) it takes a ColorInput and converts internally
through this module. Reach for Color directly when you need a specific numeric form yourself —
e.g. feeding a packed int to a shader uniform or blending channels by hand.
At a glance
sprite.color = '#e33' // any ColorInput works on color properties
const [r, g, b] = Color.toRgb01('#10131a') // [0.062…, 0.074…, 0.101…]
const packed = Color.toPackedRgb([1, 0.5, 0]) // 0xff8000
const css = Color.toHexString(0xff8000) // '#ff8000'Accepted inputs (ColorInput)
'#e33' '#e33c' // hex shorthand — #rgb / #rgba, nibbles doubled
'#ff3333' '#ff3333cc' // hex — #rrggbb / #rrggbbaa (leading '#' optional)
0xff3333 // packed 0xRRGGBB int — alpha is always 1
[1, 0.2, 0.2] // [r, g, b] floats, 0..1
[1, 0.2, 0.2, 0.8] // [r, g, b, a] floats, 0..1Note
only hex strings are parsed. A CSS functional string ('rgba(255, 51, 51, 0.8)',
'red') is treated as malformed and falls back to opaque black — it does not throw. Use
the #rrggbbaa form for alpha in a string, or a float array.
Note
a packed input int carries no alpha — 0xff3333cc is read as 24-bit RGB, not
RGBA. To pass alpha, use a string ('#ff3333cc') or a 4-element array.
Converters
Color.toRgb01(c): [r, g, b] // floats 0..1 (alpha dropped)
Color.toRgba01(c): [r, g, b, a] // floats 0..1; float-array inputs pass through losslessly
Color.toPackedRgb(c): number // 0xRRGGBB
Color.toPackedRgba(c): number // 0xRRGGBBAA, unsigned (safe to compare/shift)
Color.toHexString(c): string // '#rrggbb', or '#rrggbbaa' when alpha < 1See also
- Conventions — where
ColorInputis accepted - Mathf —
lerp/clamp01for blending channels you've pulled out withtoRgba01