|
TiledMaps
Demonstrates how to use the Tiled map support.
IntroductionThis tutorial will demonstrate how to use the Tiled map support in LibGDX. This tutorial assumes you have the libgdx core API and the tiled-preprocessor extension set up, and have some maps and tile sets ready to use. Packing the MapsThe first step to getting Tiled maps into libgdx is packing them in a format that is more easily used by the library. This is done through the tiled-preprocessor extension on the desktop. The TiledMapPacker class is pretty straight forward to use. Be sure to also have the TexturePacker extension, as it is required for the packer to work. The simplest way to use the TiledMapPacker is through the main method. You also have the option of directly calling TiledMapPacker.processMap(File inputDir, File outputDir, Settings settings) following similar usage. When calling the main method, it will take two arguments. The first argument is your input directory, which should contain the TMX files and your tile set images. The second argument is the output directory, which should be empty before running the packer. It is important to remove all files from the output directory, otherwise the packer will not properly pack the maps and you will have to run it again. Once you have run the packer, you will get a set of new files in the output directory. You will have an image and packfile for each tile set. These were packed using the TexturePacker extension (thanks Nate!) in order to ensure that the images are a power of two in dimensions, and indexes the location of each tile. New TMX files will also be in the output directory. The only thing added to the TMX files is a property ("blended tiles") that shows which tiles will need to be alpha blended. You can safely modify the TMX files directly without running the packer again, as long as you do not modify tile sets at all. Rendering the MapsNow that you have packed up the tile maps, the next step is to bring it into your final project. Follow the TiledMapTest in the gdx tests section (more to come, this section is a WIP). Common Issues & Tips
| |