A Texture2D is a 2D array of pixel information which can be used by FlatRedBall Sprites, as well as other types of visual objects such as Tiled maps and Gum elements. All FlatRedBall platforms support textures up to a max size of 2048x2048, and as of 2024 most hardware supports texture sizes of 4096x4096.
A Texture2D by itself cannot be displayed in FlatRedBall. The Texutre2D must be drawn by a FlatRedBall object. The most common object for displaying Texture2Ds are Sprite. The following code shows how to render a Texture2D using a Sprite.
The following code loads a Texture2D from a file:
Add the following using statement:
Call the following sometime after FlatRedBall is initialized
For more information on the Texture2D class, see the MSDN entry.
Each pixel in a Texture2D can be fully opaque, completely transparent, or have partial transparency. Typically textures are loaded from .PNG files which can include transparency.
When a texture is loaded into FlatRedBall, the source image width and height should be a power of two. Non-power of two image can be loaded, but they may be up-scaled which can result in blurry textures and wasted memory. The following lists common powers of 2:
8
16
32
64
128
256
512
1024
2048
4096
The easiest way to create a Texture2D is to drop a Texture2D into the FlatRedBall Editor. It generates code for loading the Texture2D.
Alternatively you can load a graphical file and create a Texture2D using FlatRedBallServices as follows:
While this code addresses many common scenarios, you may want to create your own textures programatically. This section discusses various topics on how to create Texture2Ds in code.
The following code creates a Texture2D which is all red, then displays the Texture2D using a Sprite.
Add the following using statement: