MapDrawableBatch
Introduction
The MapDrawableBatch class represents a single layer in a .tmx file. It implements the IDrawableBatch class to perform custom rendering. It internally creates a single vertex buffer which is drawn all at once with no render state changes for maximum performance. Usually .tmx files are loaded into a LayeredTileMap, which contains one or more MapDrawableBatch instances.
Only painted tiles create vertices
When the MapDrawableBatch is created it will only create vertices for tiles which exist. Therefore tiles which are not painted or which have been erased in Tiled will not create vertices.
MapDrawableBatch Color Values
MapDrawableBatch supports a Modulate color operation through its Red, Green, and Blue values. By default these values are all set to 1.0f, but they can be modified at runtime to tint or darken the map.
Creating a MapDrawableBatch in Code
MapDrawableBatch instances are typically created by adding a TMX file to your project. By default FlatRedBall top down and platformer projects contain TMX files for each level. MapDrawableBatch instances can also be created in code. The following code shows how to create a new MapDrawableBatch which is filled with a pattern from a texture called FRBeefcakeSpritesheet The following code assumes that an existing Map exists (although this is not necessary), that the code has access to a Texture called FRBeefcakeSpritesheet, and that this code exists in the CustomInitialize of a Screen such as Level1.
Creation Considerations
The code above includes some subtle considerations:
The CustomLayer MapDrawableBatch uses X axis sorting. Therefore, all tiles must be added in order of X, largest to small. Breaking this order will result in incorrect rendering and other unpredictable behavior.
The entire tile set is filled. This enables painting later without having to add tiles. If tiles are added on paint, this can make sorting far more difficult.
Last updated