Using Tiled to add objects Guide - UQdeco2800/2021-studio-2 GitHub Wiki
Download Tiled: https://www.mapeditor.org/
How to download current Tiled Map
Go to map improvement branch. Open level from one of the tmx files in source\core\assets\maps\RawTiled\*.tmx and ensure testset is set to the testset in source\core\assets\Tileset\tileset.png
Please ensure others are not editing at the same time as changes in Tiled file will be difficult to compare and merge.
Main Steps
Step 1: Upon entering game go to menu, View --> Snapping --> Snap to Grid
Step 2: In the layers section create a new Object Layer named objectnameObjects (This name will be the one that is used to access the objects within the game engine)
Step 3: While the layer you want to put objects into is selected, click on the Insert Rectangle button on the top toolbar (Shortcut: r).
Step 4: If you are placing on object which already has a defined size (like an enemy) click on the bottom-left corner of where you want the object to be placed.
If you want to place an object which does not have a predefined size, click and drag.
NOTE: Tiled uses coordinates from the top-left, whereas the game engine uses coordinates from the bottom-left.
Step 5: When done, go to File --> Export As then select JSON as the file type.
Step 6: Run source\core\assets\ProcessMaps.exe to process the files into ProdMap
Step 7: Add new object type to map reader in source/core/src/main/com/deco2800/game/areas/terrain/Map.java by adding the below in the public class Map.
private HashMap<String, Float>[] objectnameObjects;
and
public HashMap<String, Float>[] getObjectnameObjects() {
return objectnameObjects;
}
Step 8: In the game area you have added the object, add the following
private void spawnObject() {
HashMap<String, Float>[] objects = map.getObjectnameObjects();
for (HashMap<String, Float> object : objects) {
int x = object.get("x").intValue();
int y = object.get("y").intValue();
//if adding object without predetermined size also add:
float width = spikeTrap.get("width");
float height = spikeTrap.get("height");
int unitHeight = (int) ((height / 32f));
spawnEntityAt(
ObstacleFactory.createYourAlreadyCreatedObject,
new GridPoint2(x, map.getDimensions().get("n_tiles_height") - y), *note if object without predetermined size x, use map.getDimensions().get("n_tiles_height") - (y + unitHeight)
false,
false);
}
}
and assuming you want these object to spawn at the creation of the room, place the function in the create() function
Step 9: Add the image pngs and atlas files to the map that the objects will spawn in
Possible Issues: The name of the Game area does not match with the level of the map. E.g. GameArea3 uses lvl_2.json for spawning.
If you have any difficulties or need help please contact team4 on discord.