add the background layer

This commit is contained in:
Colin McMillen 2020-03-08 17:39:36 -04:00
parent 983a02b364
commit 9aa0d05eb2

View File

@ -102,6 +102,8 @@ namespace SemiColinGames {
public World(string json) {
JObject root = JObject.Parse(json);
List<Tile> decorationTiles = new List<Tile>();
List<Tile> backgroundTiles = new List<Tile>();
foreach (JToken layer in root.SelectToken("layers").Children()) {
string layerName = layer.SelectToken("name").Value<string>();
if (layerName == "entities") {
@ -110,13 +112,18 @@ namespace SemiColinGames {
continue;
}
List<Tile> tileList = ParseLayer(layer);
// TODO: add background layer
if (layerName == "obstacles") {
tiles = tileList.ToArray();
} else if (layerName == "decorations") {
decorations = tileList.ToArray();
decorationTiles = tileList;
} else if (layerName == "background") {
backgroundTiles = tileList;
}
}
// The background tiles are added before the rest of the decorations, so that they're drawn
// in the back.
backgroundTiles.AddRange(decorationTiles);
decorations = backgroundTiles.ToArray();
Debug.WriteLine("world size: {0}x{1}", gridWidth, gridHeight);
// Because we added tiles from left to right, the CollisionTargets are sorted by x-position.