LayeredTileMap
Last updated
Last updated
The LayeredTileMap object is the runtime type for the TMX file format (the native file format for Tiled). Whenever a TMX file is added to FlatRedBall, it will (by default) be loaded into a LayeredTileMap at runtime. The LayeredTileMap represents a collection of MapDrawableBatches. It contains one MapDrawableBatch per layer in the source TMX file. The LayeredTileMap class inherits from FlatRedBall.PositionedObject so it can be moved and attached to other PositionedObjects. Each MapDrawableBatch is attached to its parent LayeredTileMap, and can be moved independently by changing its RelativePosition.
The easiest way to use a TMX file is to create a standard GameScreen and Level. This can be accomplished using one of the following methods:
Run the Wizard when creating a new project - this will automatically add TMX files to your project.
Existing (empty) projects can also run the wizard through the Quick Actions tab.
Create a GameScreen and Level screens and check the options for creating TMX files.
If you are not using the GameScreen/Level pattern, you can add your own TMX files to Screens manually. To add a LayeredTileMap from an existing TMX:
Create a TMX file in Tiled
Save the TMX file in a location relative to your game's content folder. Be sure that all PNG files and TSX files (tileset files) are also relative to the game content folder
Create a game screen
Drag+drop the TMX file into your Screen's Files folder
No additional code is necessary - your map will now show up in the screen.
If using the GameScreen/Level pattern, FlatRedBall will automatically set up a Map object which can be used to create entities. If you are creating your own map object manually and you would like to create entities from this map, a small amount of extra work is needed.
Once you have a TMX file in your screen's Files folder, you can create a Map object by drag+dropping the TMX onto the Screen's Objects folder.
Once the Map object has been created, its Create Entities From Tiles property can be checked.
The LayeredTileMap is mostly a List of MapDrawableBatches. For example, you can print out information about a MapDrawableBatch as follows:
[subpages depth="1"]