Libgdx and File Chooser / Picker ( + MOD + .TMX )

Hey Guys!

Well… im in a dillema right now, looking at my book where i make annotations of my game and at the screen;;;
Heres the thing, my game load maps from tmx, which, right now, im able to load enemies from MapObjects and etc, making modding possible without messing with the code… Except, well,
since my game run in both android and desktop , should i make both be able to load maps ? I mean, can i load files from outside the .apk in android? Will that bring security risks?

Also, if i only run in desktop, can i use JFileChooser or should i use something else to load the .tmx that users make?

Thanks! :smiley:

What do you mean load both maps? You only specified you are using .tmx files, so what’s the issue. Your maps should work on both platforms.

As for the file chooser, do what you want, that’s more of a personal preference. I don’t understand why that’s even a question, JFileChooser is more than capable enough to do anything you’ll need. You aren’t using a JFrame though, so you can’t use it.

Ok, sorry, i guess i wasnt clear enough.

I want users to be able to make their own maps to play in-game.
But they need to put the location in the game to load the maps, Correct?

How will they do that? File Picker?

Get what i mean? JFileChooser wont work in android, right? Thats why i asked that.

You could always code a map editor into your game. Store the tiles in a list or an array and when the map is saved convert that into a format that you can load.

Libgdx already has a .tmx loader and tiled is already a decent .tmx editor. Rewriting your own (or writing your own format) is a waste of time if you’re not going to do anything different.

You might have to make your own file chooser widget, however, because I don’t believe tablelayout comes with one. You could go the TWL path with FileSelector, or you can make your own - not that complicated, honestly, just use FileHandle to define a directory, then use list() to get everything in that directory.

How many users are going to want to install tiled to create their own maps, especially if it’s an android game?
You could still use the tmx loader but create your own inbuilt editor.

Tiled 0.9.1 is 5.8 MB. I don’t think anyone will have a problem downloading it. Steam’s Hammer editor (from 2006) for editing source maps is 2063 MB. Inbuilt editors just bloat the size of the eventual game, because most of your users probably aren’t going to be editing maps.

Thanks for mentioning TWL, i didnt notice that api before.
Is there any drawbacks i should be aware?

It’s not as easy to use as tablelayout.

I was going to use TWL but then i spoke with dermet fan and well, i went libgdx again and was building my own file chooser…

Well, im with a problem that im unsure in how to “fix?”

Specifically, code like this that tries to walk an 'internal' directory:

FileHandle dirHandle = Gdx.files.internal("some/directory");
for (FileHandle entry: dirHandle.list()) {
   // yadda ...
}
will not work when running on the Desktop. In particular, the list() call will always return an empty list, and isDirectory() will return false.

http://bitiotic.com/blog/2012/05/15/libgdx-internal-files-hacks/

  FileHandle[] dirHandle = Gdx.files.internal("levels/Mod").list();

        System.out.println("List : " + dirHandle[0].name());

Exception in thread “LWJGL Application” java.lang.ArrayIndexOutOfBoundsException: 0

How can i solve that?

Because it doesn’t detect any files in that directory, just follow the fix in that link you posted.