Class DataTextureAtlas
This class represents an atlas of TextureRegion objects which are loaded from a special texture atlas file. To load a data texture atlas, you can use LoadTextureAtlas(ContentManager, string, string, bool).
Data texture atlases are designed to be easy to write by hand. Because of this, their structure is very simple. Each texture region defined in the atlas consists of its names (where multiple names can be separated by whitespace), followed by a set of possible instructions and their arguments, also separated by whitespace. Any whitespace can be escaped by wrapping the region name or argument in single or double quotes.
- The
loc(orlocation) instruction defines the Area of the texture region as a rectangle whose origin is its top-left corner. It requires four arguments: x, y, width and height of the rectangle. - The (optional)
piv(orpivot) instruction defines the PivotPixels of the texture region. It requires two arguments: x and y. If it is not supplied, the pivot defaults to the top-left corner of the texture region. - The (optional)
off(ofoffset) instruction defines an offset that is added onto the location and pivot of this texture region. This is useful when duplicating a previously defined texture region to create a second region that has a constant offset. It requires two arguments: The x and y offset. - The (optional and repeatable)
cpy(orcopy) instruction defines an additional texture region that should also be generated from the same data, but with a given offset that will be applied to the location and pivot. It requires three arguments: the copy region's name and the x and y offsets. - The (optional and repeatable)
dat(ordata) instruction defines a custom data point that can be added to the resulting TextureRegion's GenericDataHolder data. It requires two arguments: the data point's name and the data point's value, the latter of which is also stored as a string value. - The (optional)
frm(orfrom) instruction defines a texture region (defined before the current region) whose data should be copied. All data from the region will be copied, but adding additional instructions afterwards modifies the data. It requires one argument: the name of the region whose data to copy. If this instruction is used, thelocinstruction is not required.
LongTableRight and LongTableUp, whose Area will be a rectangle with X=32, Y=30, Width=64, Height=48, and whose PivotPixels will be a vector with X=80, Y=46.
LongTableRight LongTableUp
loc 32 30 64 48
piv 80 46
public class DataTextureAtlas
- Inheritance
-
DataTextureAtlas
- Inherited Members
Remarks
To see a Data Texture Atlas in action, you can check out the sandbox project: https://github.com/Ellpeck/MLEM/blob/main/Sandbox/Content/Textures/Furniture.atlas. Additionally, if you are using Aseprite, there is a script to automatically populate it: https://gist.github.com/Ellpeck/e597c1412465c10f41a42050ec117ea2.
Fields
Texture
The texture to use for this atlas
public readonly TextureRegion Texture
Field Value
Properties
this[string]
Returns the texture region with the given name, or null if it does not exist.
public TextureRegion this[string name] { get; }
Parameters
namestringThe region's name
Property Value
RegionNames
Returns an enumerable of all of the TextureRegion names in this atlas.
public IEnumerable<string> RegionNames { get; }
Property Value
Regions
Returns an enumerable of all of the TextureRegion values in this atlas.
public IEnumerable<TextureRegion> Regions { get; }
Property Value
Methods
LoadAtlasData(TextureRegion, ContentManager, string, bool)
Loads a DataTextureAtlas from the given loaded texture and texture data file. For more information on data texture atlases, see the DataTextureAtlas type documentation.
public static DataTextureAtlas LoadAtlasData(TextureRegion texture, ContentManager content, string infoPath, bool pivotRelative = false)
Parameters
textureTextureRegionThe texture to use for this data texture atlas
contentContentManagerThe content manager to use for loading
infoPathstringThe path, including extension, to the atlas info file
pivotRelativeboolIf this value is true, then the pivot points passed in the info file will be relative to the coordinates of the texture region, not relative to the entire texture's origin.
Returns
- DataTextureAtlas
A new data texture atlas with the given settings
ToDictionary()
Converts this data texture atlas to a Dictionary<TKey, TValue> and returns the result. The resulting dictionary will contain all named regions that this data texture atlas contains.
public Dictionary<string, TextureRegion> ToDictionary()
Returns
- Dictionary<string, TextureRegion>
The dictionary representation of this data texture atlas.