Color

From Unreal Wiki, The Unreal Engine Documentation Site
Revision as of 17:55, 6 April 2011 by 113.22.250.67 (talk) (Color operators: In the first paragraph, changed "provides Provides" to "provides" only.)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

The type color is not a built-in type, but a struct defined in the Object

()

class of all Unreal Engine games.



The color struct is used for drawing certain things with the Canvas and HUD with a specified color that is set with the 4 members of type byte(or float for LinearColor struct) which are R(Red), G(Green), B(Blue) and A(Alpha).

Note: Unreal Engine 3 games may also define other color-like structs, such as LinearColor.

Color operations

In Unreal Engine 2 there are no built-in operators for color structs except a few in Actor.

Making a color

Unreal Engine 3 provides a MakeColor() function in Object that can be used to make a color struct instance by passing independant RGBA components e.g.

local Color BlueColor;

BlueColor = MakeColor( 0, 0, 255, 255 );

this will create a blue color and assign it to BlueColor.

Note: Unreal Engine 2 doesn't have function MakeColor() accessible from the Object class, but instead in the Canvas class, so change the MakeColor() code to Class'Canvas'.static.MakeColor().

Color operators

Unreal Engine 3 provides the - * + operators for colors and Unreal Engine 2 only provides them if extending from Actor.

- Substracts a color by another color e.g.

local Color BlueColor;
local Color BlackColor;

BlueColor = MakeColor( 0, 0, 255, 255 );
BlackColor = BlueColor - MakeColor( 0, 0, 255, 255 );

Subtracts the blue color from BlueColor and would become a black color assigned to BlackColor.


* Multiplies a color by the scalar (i.e. float) value e.g.

local Color BlueColor;

BlueColor = MakeColor( 0, 0, 255, 255 );
BlueColor = BlueColor * 0.5f;

Multiplies BlueColor by half thus BlueColor will become darkblue.


+ Adds a color to a color e.g.

local Color BlueColor;
local Color PurpleColor;

BlueColor = MakeColor( 0, 0, 255, 255 );
PurpleColor = BlueColor + MakeColor( 255, 0, 0, 255 );

Merges BlueColor with a red color and becomes purple then assigns to PurpleColor.

Performance

Because the above operators are slow it is recommend to convert them to a Vector first and then use the vector operators instead of the color operators when you are making use of the same color and same operators a lot in one function.

Utilities

Because of the lack of many color operations you can view a list of community made color operations at UnrealScript utils to use in your project.

See also