Color
Color stores the red, green, blue, and alpha components of a color. It is used by UI, ImGui, WorldVisuals, and other APIs that accept a color.
Purpose and processing
Section titled “Purpose and processing”Color is a data value, not a draw command. Construction and changes to r/g/b/a are handled by the Lua wrapper and display nothing by themselves. A color affects the game only after it is passed to a consumer such as a UI style, ImGui, or LineRenderer:SetColor().
Changing a local Color after a call does not automatically update an object that was already configured. Pass the new value to the consumer again.
Quick example
Section titled “Quick example”local cyan = Color.new(0.2, 0.8, 1)local translucentRed = Color.new(1, 0, 0, 0.5)
print(cyan.a) -- 1When only RGB is provided, the constructor automatically sets a = 1.
Creating a color
Section titled “Creating a color”Color.new(r: number, g: number, b: number): ColorColor.new(r: number, g: number, b: number, a: number): Color| Parameter | Type | Description |
|---|---|---|
r |
number |
Red component. |
g |
number |
Green component. |
b |
number |
Blue component. |
a |
number |
Alpha component. Defaults to 1 when omitted. |
Components
Section titled “Components”| Property | Type | Access | Description |
|---|---|---|---|
r |
number |
get/set |
Red component. |
g |
number |
get/set |
Green component. |
b |
number |
get/set |
Blue component. |
a |
number |
get/set |
Alpha component. |
Components can be changed after construction:
local color = Color.new(1, 1, 1)color.g = 0.5color.a = 0.75Common mistakes
Section titled “Common mistakes”Using values from 0 to 255
Section titled “Using values from 0 to 255”The usual representation uses values from 0 to 1. For the RGB color 128, 200, 255, divide each component by 255:
local color = Color.new(128 / 255, 200 / 255, 1)Unexpected opacity
Section titled “Unexpected opacity”The three-component constructor sets a = 1. Pass the fourth argument when you need a different alpha value.