My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for

Table of Contents

TiledMaps  
Demonstrates how to use the Tiled map support.
Updated May 26, 2011 by dfra...@gmail.com

Introduction

This 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 Maps

The 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 Maps

Now 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

  • Do not have an underscore character (_) in any map name or tile set name. This will cause issues with the TexturePacker extension that is used when packing the maps with TiledMapPacker.
  • All maps in the input directory for the TiledMapPacker should be able to be opened in Tiled without having to move them. This is a good way to test that your directory structure is valid.
Powered by Google Project Hosting