Hi !
Featured games (85)
games approved by the League of Dukes
Games in Showcase (636)
Games in Android Showcase (178)
games submitted by our members
Games in WIP (687)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  LibGDX - Packing Tile maps (.tmx) for use in code  (Read 7944 times)
0 Members and 1 Guest are viewing this topic.
Offline vbrain
« Posted 2013-02-14 04:00:45 »

The LibGDX wiki on this topic is quite confusing and may be hard to understand.

I will assume you have already created your map in Tiled and saved it (.tmx) and your tileset images in a folder.

Save location of your original (.tmx) map and resources:
We'll call this "resources\images"

In that folder we have the .tmx map file, the mapterrain.png (the tileset used in the Tiled application), and a .bat file called "map_command.bat" which we will go into later.

Now let's go into our game project's asset folder:
Be sure you are in the "-android" folder!

Create a NEW folder called "maps" in the assets folder. This is important because when we pack the map file, the folder must be EMPTY!

Go to the location of your file. The location where you downloaded the zipped folder for libgdx.

Navigate into the "extensions" folder and you should see these folders:

If you don't see them, then you dun goofed.

Here comes the trickiest part. Hold on to your seat.

Open up Notepad and using the folder locations, fill this code in (BE SURE TO USE FULL FILE PATHS!!! FROM THE CODE BELOW, YOU SHOULD BE ABLE TO FIGURE OUT WHICH FOLDERS THEY'RE REFERRING TO!!!):

java -classpath "***LOCATION_TO_LIBGDX_FOLDER***\libgdx-0.9.8\gdx.jar";"***LOCATION_TO_LIBGDX_FOLDER***\libgdx-0.9.8\extensions\gdx-tools\gdx-tools.jar";"***LOCATION_TO_LIBGDX_FOLDER***\libgdx-0.9.8\extensions\gdx-tiled-preprocessor\gdx-tiled-preprocessor.jar" com.badlogic.gdx.tiledmappacker.TiledMapPacker "***LOCATION_TO_SAVE_LOCATION_OF_ORIGINAL_MAP_AND_TILESETS***\resources\images" "***LOCATION_TO_WORKSPACE_GAME_FOLDER***\Game-android\assets\maps"

Simplified version without all the CAPS:
java -classpath "libgdx-0.9.8\gdx.jar";"libgdx-0.9.8\extensions\gdx-tools\gdx-tools.jar";"libgdx-0.9.8\extensions\gdx-tiled-preprocessor\gdx-tiled-preprocessor.jar" com.badlogic.gdx.tiledmappacker.TiledMapPacker "resources\images" "Game-android\assets\maps"

Now, save it as a .bat (This is what that "map_command.bat" was in one of the pictures above).

Run it!

In your game's workspace folder, the "assets\maps" folder should look something like this now:

Now you are ready to go to and continue following the wiki on how to use tile maps in your code.

Each time you create a new map or modify an existing one, you MUST clear out the "assets\maps" folder before running the .bat file.

Hopefully this tutorial helped you!
Offline ra4king

JGO Kernel

Medals: 409
Projects: 3
Exp: 5 years

I'm the King!

« Reply #1 - Posted 2013-02-15 04:50:26 »

Something that's irking me a bit: please show the file extensions. I don't know why everyone doesn't do that.

Otherwise, thanks for the tutorials!

Pages: [1]
  ignore  |  Print  
You cannot reply to this message, because it is very, very old.

Dwinin (72 views)
2015-11-07 13:29:08

Rems19 (81 views)
2015-10-31 01:36:56

Rems19 (77 views)
2015-10-31 01:32:37

williamwoles (107 views)
2015-10-23 10:42:59

williamwoles (93 views)
2015-10-23 10:42:45

Jervac_ (110 views)
2015-10-18 23:29:12

DarkCart (135 views)
2015-10-16 00:58:11

KaiHH (117 views)
2015-10-11 14:10:14

KaiHH (156 views)
2015-10-11 13:26:18

BurntPizza (172 views)
2015-10-08 03:11:46
Rendering resources
by Roquen
2015-11-13 14:37:59

Rendering resources
by Roquen
2015-11-13 14:36:58

Math: Resources
by Roquen
2015-10-22 07:46:10

Networking Resources
by Roquen
2015-10-16 07:12:30

Rendering resources
by Roquen
2015-10-15 07:40:48

Math: Inequality properties
by Roquen
2015-10-01 13:30:46

Math: Inequality properties
by Roquen
2015-09-30 16:06:05

HotSpot Options
by Roquen
2015-08-29 11:33:11 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!