Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (406)
games submitted by our members
Games in WIP (293)
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 1114 times)
0 Members and 1 Guest are viewing this topic.
Offline vbrain

Junior Member


Medals: 3



« Posted 2013-02-14 05: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 libgdx.zip 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!!!):

1  
2  
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"
pause


Simplified version without all the CAPS:
1  
2  
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"
pause


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 http://code.google.com/p/libgdx/wiki/GraphicsTileMaps 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!
Online ra4king

JGO Kernel


Medals: 264
Projects: 2


I'm the King!


« Reply #1 - Posted 2013-02-15 05: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  
 
 

Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Browse for soundtracks for your game!

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
cubemaster21 (76 views)
2013-05-17 21:29:12

alaslipknot (87 views)
2013-05-16 21:24:48

gouessej (117 views)
2013-05-16 00:53:38

gouessej (112 views)
2013-05-16 00:17:58

theagentd (123 views)
2013-05-15 15:01:13

theagentd (112 views)
2013-05-15 15:00:54

StreetDoggy (156 views)
2013-05-14 15:56:26

kutucuk (178 views)
2013-05-12 17:10:36

kutucuk (177 views)
2013-05-12 15:36:09

UnluckyDevil (185 views)
2013-05-12 05:09:57
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
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!
Page created in 0.055 seconds with 20 queries.