MapDrawableBatch
Introduction
Only painted tiles create vertices
MapDrawableBatch Color Values
Creating a MapDrawableBatch in Code
MapDrawableBatch CustomLayer;
void CustomInitialize()
{
var numberOfTilesWide = 32;
var numberOfTilesHigh = 32;
var totalTiles = numberOfTilesWide * numberOfTilesHigh;
CustomLayer = new MapDrawableBatch(totalTiles, 16, 16, FRBeefcakeSpritesheet);
// Adding the CustomLayer to managers enables its rendering...
CustomLayer.AddToManagers();
// Strictly speaking, it is not necessary to add CustomLayer to the Map's MapLayers.
// It is recommended so that any MapDrawableBatch added in code can be accessed through
// the Map, just like layers created through TMX. In other words, it keeps things the same
// and avoids gotchas.
Map.MapLayers.Add(CustomLayer);
// Attaching the CustomLayer to the Map enables moving the entire map as a single unit:
CustomLayer.AttachTo(Map);
CustomLayer.RelativeZ = 1;
CustomLayer.SortAxis = SortAxis.X;
// add tiles for the entire map:
for (int x = 0; x < numberOfTilesWide; x++)
{
for(int y = 0; y < numberOfTilesHigh; y++)
{
CustomLayer.AddTile(new Vector3(x * 16, (-y-1) * 16, 0), new Vector2(16, 16),
textureTopLeftX: 16,
textureTopLeftY: 176,
textureBottomRightX: 32,
textureBottomRightY: 192);
}
}
}
Creation Considerations
Last updated
Was this helpful?