Libgdx tmx map processing tool gdx-tiled-preprocessor.jar (tiledmappacker) Revised Version

Source: Internet
Author: User
Tags libgdx

Recently want to do an android game, use libgdx, now research map this, make a map tmx file after processing libgdx to load, need to use tiledmappacker tool, the tool is placed in the gdx-tiled-preprocessor.jar, this is something that can throw me to death. I tried a variety of errors, such:

Failed to load main-class manifest attribute

 

Exception in thread "Main" com. badlogic. GDX. utils. gdxruntimeexception: Creating window failed
At com. badlogic. GDX. backends. jogl. joglapplication. <init> (joglapplication. Java: 86)
At com. badlogic. GDX. tiledmappacker. tiledmappacker. Main (tiledmappacker. Java: 329)
At com. skyd. tiledmappacker. tiledmappackertool. Main (tiledmappackertool. Java: 15)
Caused by: Java. Lang. Reflect. invocationtargetexception
At java. AWT. eventqueue. invokeandwait (unknown source)
At javax. Swing. swingutilities. invokeandwait (unknown source)
At com. badlogic. GDX. backends. jogl. joglapplication. <init> (joglapplication. Java: 80)
... 2 more
Caused by: Java. Lang. unsatisfiedlinkerror: No gdx64 in Java. Library. Path
At java. Lang. classloader. loadlibrary (unknown source)
At java. Lang. runtime. loadlibrary0 (unknown source)
At java. Lang. system. loadlibrary (unknown source)
At com. badlogic. GDX. utils. gdxnativesloader. Load (gdxnativesloader. Java: 118)
At com. badlogic. GDX. backends. jogl. joglnativesloader. Load (joglnativesloader. Java: 29)
At com. badlogic. GDX. backends. jogl. joglapplication. initialize (joglapplication. Java: 111)
At com. badlogic. GDX. backends. jogl. joglapplication $ 1.run( joglapplication. Java: 82)
At java. AWT. event. invocationevent. Dispatch (unknown source)
At java. AWT. eventqueue. dispatcheventimpl (unknown source)
At java. AWT. eventqueue. Access $000 (unknown source)
At java. AWT. eventqueue $ 1.run( unknown source)
At java. AWT. eventqueue $ 1.run( unknown source)
At java. Security. accesscontroller. doprivileged (native method)
At java. Security. accesscontrolcontext $1. dointersectionprivilege (unknown source)
At java. AWT. eventqueue. dispatchevent (unknown source)
At java. AWT. eventdispatchthread. pumponeeventforfilters (unknown source)
At java. AWT. eventdispatchthread. pumpeventsforfilter (unknown source)
At java. AWT. eventdispatchthread. pumpeventsforhierarchy (unknown source)
At java. AWT. eventdispatchthread. pumpevents (unknown source)
At java. AWT. eventdispatchthread. pumpevents (unknown source)
At java. AWT. eventdispatchthread. Run (unknown source)

 

Exception in thread "Main" Java. Lang. nullpointerexception
At com. badlogic. GDX. tiledmappacker. tiledmappacker. processmap (tiledmappac
Ker. Java: 92)
At com. skyd. tiledmappacker. Main. Main (main. Java: 38)

 

At the end, no one else can solve the problem on the internet, saying that this is all a mistake. They all use a separate block file to get the entire graph and packfile after the texturepacker is combined, then, take it into the map editor and edit it to output the tmx file. It is very troublesome to cut the image into smaller ones and splice it again. Then, try to correct this tool:

I created this project and introduced the relevant jar and gdx-tiled-preprocessor.jar source code, the tiledmappacker class is called in the primary function of the newly created main class following the calling method of the primary function of the original tiledmappacker class, but the section of the newly created window is removed.Code:

I really don't know if the window is constructed as a zombie and the fart is not executed in it. If it is still dead, an error will be reported. This is the main class code:

 
PackageCom. skyd. tiledmappacker;
 
 
 
ImportJava. Io. file;
 
ImportJava. Io. ioexception;
 
 
ImportCom. badlogic. GDX. tiledmappacker. tiledmappacker;
 
ImportCom. badlogic. GDX. Tools. imagepacker. texturepacker. settings;
 
 
Public ClassMain {
 
 
 
/**
 
* @ Param ARGs
 
*/
Public Static VoidMain (string [] ARGs ){
 
File tmxfile, inputdir, outputdir;
 
 
 
Settings settings =NewSettings ();
 
 
// Note: The settings below are now default...
 
Settings. Padding = 2;
 
Settings. duplicatepadding =True;
 
 
Tiledmappacker packer =NewTiledmappacker ();
 
 
 
If(ARGs. length! = 2 ){
 
System. Out. println ("Usage: inputdir outputdir");
System. Exit (0 );
 
}
 
 
 
Inputdir =NewFile (ARGs [0]);
 
Outputdir =NewFile (ARGs [1]);
 
 
System. Out. println ("Directory to be processed:"+ Inputdir +" "+ Inputdir. getabsolutepath ());
 
System. Out. println ("Directory to be processed:"+ Outputdir +" "+ Outputdir. getabsolutepath ());
 
 
If(! Inputdir. exists ()){
 
Throw NewRuntimeexception ("Input directory does not exist");
 
}
 
 
Try{
 
Packer. processmap (inputdir, outputdir, settings );
 
}Catch(Ioexception e ){
 
Throw NewRuntimeexception ("Error Processing Map:"+ E. getmessage ());
}
 
}
 
 
 
}
 
 

After the window problem is fixed, there is still a bug in execution. If the problem is executed in the processmap method of the tiledmappacker class, an error is reported. You need to modify the source code and create filehandle in the method "GDX. files. absolute (XXX. change getabsolutepath () to "New filehandle (XXX. in the form of getabsolutepath (), the changed code is as follows:

 

 
Public VoidProcessmap (File inputdir, file outputdir, settings)ThrowsIoexception {
 
Filehandle inputdirhandle =NewFilehandle (inputdir. getabsolutepath ());
 
File [] files = inputdir. listfiles (NewTmxfilter ());
 
 
For(File file: Files ){
 
System. Out. println ("Files to be processed:"+ File +" "+ File. getabsolutepath ());
 
Map = tiledloader. createmap (NewFilehandle (file. getabsolutepath ()));
 
 
For(Tileset set: map. tilesets ){
 
If(! Processedtilesets. Contains (set. imagename )){
 
Processedtilesets. Add (set. imagename );
Packtileset (set, inputdirhandle, outputdir, settings );
 
}
 
}
 
 
 
Writeupdatedtmx (outputdir, map. tmxfile );
}
 
}

 

Then export it as runnable JAR file:

Select the main class as the entry.

 

The modified test environment:

Place the clip image and the tmx file generated by the map editor in the in directory:

Command Line execution:

D: \ test> JAVA-jar tiledmappacker. jar in out

The out directory will get the processed file:

Now we can complete the rendering in libgdx.

 

Corrected tiledmappacker. Jar download: http://vdisk.weibo.com/s/4jXW0

 

Reference:

Http://www.cnblogs.com/htynkn/archive/2012/01/12/libgdx_12.html

Http://blog.csdn.net/cng1991/article/details/7288234

Https://code.google.com/p/libgdx/wiki/TiledMaps

Http://dpk.net/2011/05/01/libgdx-box2d-tiled-maps-full-working-example-part-1/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.