The ColorOperation enumeration defines possible color operations which can be used by an IColorable to modify its appearance. For more information, see the IColorable wiki entry.
The following table lists color operations and supported platforms:
* As of August 15 2024 the only color operation supported is Texture. These will likely be expanded in future versions of FlatRedBall Web.
The Add color operation allows the addition of the Color (Red, Green, Blue) values to the texture drawn by an object. This can be used to "lighten", or simulate light shining on an object.
The following code can be used to set a Sprite's color operation to Add when the space bar is pressed.
The ColorOperation.Color option makes the drawn object completely ignore its Texture and use only the color. For objects like Sprites, this results in a colored quad (no texture). Alpha is ignored completely as well, so even if the Sprite's Texture has transparency, it will appear as a solid rectangle when using this color operation. Sprites that use .Color do not need to have a Texture. Therefore, the following code is acceptable:
The Texture color operation results in an object being drawn with its unmodified texture. Color values (red, green and blue) on the IColorable are completely ignored, unless the object has no texture. The Texture color operation is the default color operation for FlatRedBall types like Sprite and Text.
Texture color operation can be assigned on any IColorable, such as Sprite:
As mentioned above, the Red, Green, and Blue values have no impact on an object which uses the Texture color operation.
Images which are grayscale can be colored using the Modulate color operation. This is a fast way to create variety for entities such as enemies or equipment. The following animation shows tinting using the FlatRedBall Editor on a Sprite with Modulate color operation.
The following code creates 10 bears, starting with a color of pure black (0,0,0) and ending with white (1,1,1). The bears start dark (as if in shadow), then become progressively brighter.
ColorOperation | PC (DesktopGL) | iOS | Android | Web * |
---|---|---|---|---|
The ColorOperation.Modulate option makes the drawn object "multiply" all of its texture color values by the Red, Green, and Blue of the IColorable. Setting a Modulate with Red, Green, Blue values of 1,1,1 will result in the object drawn regularly. Setting the values to .5, .5, .5 will result in the object being drawn at half-brightness. Setting values to 1,0,0 will result in only red values being drawn. Blue and green will draw as black. The following code example renders the Bear.png graphic with no Modulate operation, then with 3 different values to show how Modulate works. Image used:
X
X
X
X
X
X
X
X
X
X
ColorTextureAlpha
X
X
X
X
Subtract
X
InverseTexture
X
Modulate2X
X
Modulate4X
X
X