Browse Source

add the background layer

master
Colin McMillen 4 years ago
parent
commit
9aa0d05eb2
  1. 11
      Shared/World.cs

11
Shared/World.cs

@ -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.

Loading…
Cancel
Save