Cubicforest: using Tiled

In a second post I was writting about creating my own level editor. A lot has happended since then (thank You reality, You’re a perfect teacher): games is being written in Java using http://libgdx.badlogicgames.com/ right now and for editing levels I’m using Tiled editor http://www.mapeditor.org/.

I’m very happy from that solution. Level is exported to Json.

Loading done with gson https://sites.google.com/site/gson/gson-user-guide. Just a few classes reflecting Json’s file structure and I was ready to go…

public class TiledMap {

	private Integer width;
	private Integer height;
	private Integer tileheight;
	private Integer tilewidth;
	private List<TiledLayer> layers;
...
public class TiledLayer {

	private String name;	
	private Integer height;
	List<TiledObject> objects;
...
public class TiledObject {

	private Integer gid;
	private String name;
	private String type;
	private Integer x;
	private Integer y;

What’s interesting: loading is done with one line!

public class MapsLoader {

	TiledMap tiledMap;
...
tiledMap = new Gson().fromJson(mapFileString, TiledMap.class);

… and TiledMap class is filled with a data about designed level

Project’s repository: https://github.com/adamskopl/cubicforest-java.

Tiled editor:

tiled.png

Level loaded in a game:

tiled-cubic.png

2 Replies to “Cubicforest: using Tiled”

Leave a Reply

Your email address will not be published. Required fields are marked *