The IColorable interface defines properties for interacting with an object which can have its color dynamically modified and which can specify how it "blends" with objects behind it. Common objects which implement the IColorable interface include the Sprite and Text object.
ColorOperations can be used to change the color of a IColorable at runtime. ColorOperations require two pieces of information: the color specified by three values (Red, Green, and Blue) and the operation to perform with the specified color.
The default ColorOperation for most IColorables (like Sprites) is ColorOperation.None. Unless the ColorOperation is changed, the Red, Green, and Blue properties will have no effect on way the IColorable is rendered. The default ColorOperation for Texts is Modulate.
The Red, Green, and Blue properties provide access to the components of the color which is used to change the IColorable's color. The ColorOperation property specifies how to modify the color.
Color values range between 0 and 1 and are all set to 0 by default.
The exception is the Text object. The Text object has its Red, Green, and Blue color values set to 1 so that the text appears as white. Furthermore, the ColorOperation defaults to ColorOperation.Modulate for the Text object.
The following code will create five Sprites, each with a different ColorOperation.
For more information on specific ColorOperation values, see the ColorOperation page.
Color rates are values which change the Red, Green, and Blue values over time. The rates, just like all velocity values, indicate units changed per second. The following code creates 80 Sprites and randomly varies their colors using a SpriteCustomBehavior.
The Alpha and BlendOperation properties are related just as the components of color and ColorOperation properties. The Alpha property is used to control the transparency of an IColorable.
Unlike the color components, modifying the Alpha value will affect the appearance of an IColorable with its default BlendOperation.
BlendOperations control how IColorables blend with objects behind them. The following code shows two rows of Sprites - the first with the default BlendOperation.Regular and the second with BlendOperation.Add;
The AlphaRate property modifies the Alpha property similar to the ColorRate properties. AlphaRate can be used to fade an IColorable in and out.
Most IColorables are created with an Alpha value of 1. This generally represents full opacity. AlphaRate can change this value over time. A positive AlphaRate value will increase the Alpha property over time, and a negative AlphaRate value will decrease the Alpha property over time. The formula (which is generally applied automatically for managed objects) is:
Therefore, a fully opaque object with an AlphaRate of -1 will disappear in 1 second. Increasing the absolute value of the AlphaRate makes the object disappear faster. That is, an AlphaRate of -2 (twice as large in absolute value terms) will make an object disappear after .5 seconds (half as long). The formula is:
Therefore, we can see that an AlphaRate value of -2 will cause an object to disappear in
Did this article leave any questions unanswered? Post any question in our forums for a rapid response.
The Red, Green, and Blue values in an IColorable represent the three color components used when applying the ColorOperation. Since the ColorOperation impacts how color is applied, then the color represented by Red, Green, and Blue may not necessarily describe the color of the object on-screen.
The ColorOperation value controls how the color values in an IColoable (Red, Green, Blue) are applied to the IColorable to determine the resulting color. The ColorOperation variable is of type FlatRedBall.Graphics.ColorOperation. For more information see the ColorOperation page.
The Sprite's default ColorOperation is:
BlendOperation can control how an IColorable (such as a Sprite) will render on top of objects under it. The default ColorOperation for most renderable objects is BlendOperation.Regular. For examples on how BlendOperation is applied, see the BlendOperation page here: https://flatredball.com/documentation/api/flatredball/flatredball-graphics/flatredball-graphics-blendoperation/
The Alpha property represents the transparency (or opacity) of a given object. The default value is 1 (full opacity), and setting the value to 0 will make the object fully transparent.
For FRB MDX users: Color and alpha values range from 0 to 255 in FlatRedBall MDX.
The following code shows how to use the Alpha property on Text objects to control their transparency.