A utility for JGameEgnine that can be used to easily import and add maps created using the Tiled Map Editor (version 1.0 and 1.2 tested). To develop NES/SNES styled games like Mario and The Legend of Zelda, maps made using tiled may be used to simplify the game creation process. The Utility requires JGameEngine and the Gson library to work.
The following code adds a map sets untitled.json
as the game space. This will create and display the tiles starting at 0, 0. See Detailed Tutorial
public class Driver {
public static void main(String[] args) {
MapTest d = new MapTest();
}
}
class MapTest extends JGameEngine {
MapTest() {
this.setWindow("Test Tiled Map");
JTiledUtility u = new JTiledUtility(this);
u.setGameSpace("untitled.json");
}
}
The implementation is quite bare-bone and implements features selectively. Most maps made in tiled will not be compatible.
- Only Orthogonal maps with render the right down render order are supported.
- Infinite maps not supported.
- Map needs to be saved as an uncompressed CSV JSON file (when a new map is being created the settings can be changed to this).
- A tileset must not have margins, and should be kept in the same drive as the map.
- Only tile layers and object layers are supported.
- In objects, only rectangle and ellipse are supported (ellipse is rounded to a circle). They are taken as collisions and they will get the class
JTiledObject
which is a basic Game Object that has a collision mask.
Basic orthogonal maps with collisions that can be added from the tiled editor itself. The collisions can be given a custom class for advanced usage.
All such classes must have a constructor that accepts an object that is or extends from JGameEngine
. Each object layer will be assigned a class that resides on each index of the object layer. JTiledObject.class
may be used for object layers with no extra properties.
class MapTest extends JGameEngine {
MapTest() {
this.setWindow("Test Tiled Map");
JTiledUtility u = new JTiledUtility(this);
ArrayList<Class> list = new ArrayList<>();
list.add(Player.class); // object layer 1 needs to be a player class object.
list.add(JTiledObject.class); // don't care about object layer 2.
u.setGameSpace("untitled.json", list);
}
}
class Player extends JGameEngine.Object implements JGameEngine.Collision {
JGameEngine e;
public Player(JGameEngine e) {
this.e = e;
name = "Player";
}
... Code Omitted ...
This project is licensed under the MIT License - see the LICENSE.md file for details
Ammar Aslam
The image tilemap.png is produced by RedVoxel, it requires an attribution to be used.