There is no spoon
Difference between revisions of "Color"
(Created page with 'The type '''color''' is not a built-in type, but a struct defined in the {{classgames|Object}} class of all Unreal Engine games. <br><br> The '''color''' struct is used …') |
m (Minor tweaks) |
||
Line 1: | Line 1: | ||
The type '''color''' is not a built-in type, but a [[struct]] defined in the {{classgames|Object}} class of all Unreal Engine games. | The type '''color''' is not a built-in type, but a [[struct]] defined in the {{classgames|Object}} class of all Unreal Engine games. | ||
<br><br> | <br><br> | ||
− | The '''color''' [[struct]] is used for drawing certain things with the | + | 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 [[Types#Byte|byte]](or [[Types#Float|float]] for [[UE3:Object structs (UT3)#LinearColor|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 [[UE3:Object structs (UT3)#LinearColor|LinearColor]]. | '''Note:''' [[Unreal Engine 3]] games may also define other color-like structs, such as [[UE3:Object structs (UT3)#LinearColor|LinearColor]]. | ||
==Color operations== | ==Color operations== | ||
− | In [[Unreal Engine 2]] there are no built-in operators for color [[struct|structs]] except a few in | + | In [[Unreal Engine 2]] there are no built-in operators for color [[struct|structs]] except a few in [[Actor]]. |
===Making a color=== | ===Making a color=== | ||
− | [[Unreal Engine 3]] provides a <code>MakeColor()</code> function in | + | [[Unreal Engine 3]] provides a <code>MakeColor()</code> function in [[Object]] that can be used to make a color [[struct]] instance by passing independant RGBA components e.g. <uscript>local Color BlueColor; |
BlueColor = MakeColor( 0, 0, 255, 255 );</uscript> ''this will create a blue color and assign it to '''BlueColor'''''. | BlueColor = MakeColor( 0, 0, 255, 255 );</uscript> ''this will create a blue color and assign it to '''BlueColor'''''. | ||
− | '''Note:''' [[Unreal Engine 2]] doesn't have function <code>MakeColor()</code> accessible from | + | '''Note:''' [[Unreal Engine 2]] doesn't have function <code>MakeColor()</code> accessible from the [[Object]] class, but instead in the [[Canvas]] class, so change the <code>MakeColor()</code> code to <code>Class'Canvas'.static.MakeColor()</code>. |
===Color operators=== | ===Color operators=== | ||
− | [[Unreal Engine 3]] provides Provides the <code>-</code> <code>*</code> <code>+</code> operators for colors and [[Unreal Engine 2]] only provides them if extending from | + | [[Unreal Engine 3]] provides Provides the <code>-</code> <code>*</code> <code>+</code> operators for colors and [[Unreal Engine 2]] only provides them if extending from [[Actor]]. |
<code>-</code> Substracts a color by another color e.g. <uscript>local Color BlueColor; | <code>-</code> Substracts a color by another color e.g. <uscript>local Color BlueColor; | ||
Line 39: | Line 39: | ||
===Utilities=== | ===Utilities=== | ||
− | Because of the lack of many color operations you can view a list of community made color operations at [[UnrealScript | + | Because of the lack of many color operations you can view a list of community made color operations at [[:Category:UnrealScript utils|UnrealScript utils]] to use in your project. |
==See also== | ==See also== |
Revision as of 15:38, 25 August 2010
The type color is not a built-in type, but a struct defined in the Object(RTNP, U1, UT, U2, U2XMP, UE2Runtime, UT2003, UT2004, UDK, UT3) 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.
Contents
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 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
Declarations | Preprocessor • Classes • Interfaces • Cpptext • Constants • Enums • Structs • Variables (Metadata) • Replication block • Operators • Delegates • Functions • States • Defaultproperties (Subobjects) |
---|---|
Types | bool • byte • float • int • name • string • Object • Class • Enums • Structs (Vector ⋅ Rotator ⋅ Quat ⋅ Color) • Static arrays • Dynamic arrays • Delegates • Typecasting |
Literals | Boolean • Float • Integer • Names • Objects (None ⋅ Self) • Vectors • Rotators • Strings |
Flow | GoTo • If • Assert • Return • Stop • Switch • While • Do...Until • For • ForEach • Break • Continue |
Specifiers | Super • Global • Static • Default • Const |
UnrealScript | Syntax • .UC • .UCI • .UPKG • Comments • #directives • Native |