add the background layer
This commit is contained in:
parent
983a02b364
commit
9aa0d05eb2
@ -102,6 +102,8 @@ namespace SemiColinGames {
|
|||||||
public World(string json) {
|
public World(string json) {
|
||||||
JObject root = JObject.Parse(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()) {
|
foreach (JToken layer in root.SelectToken("layers").Children()) {
|
||||||
string layerName = layer.SelectToken("name").Value<string>();
|
string layerName = layer.SelectToken("name").Value<string>();
|
||||||
if (layerName == "entities") {
|
if (layerName == "entities") {
|
||||||
@ -110,13 +112,18 @@ namespace SemiColinGames {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
List<Tile> tileList = ParseLayer(layer);
|
List<Tile> tileList = ParseLayer(layer);
|
||||||
// TODO: add background layer
|
|
||||||
if (layerName == "obstacles") {
|
if (layerName == "obstacles") {
|
||||||
tiles = tileList.ToArray();
|
tiles = tileList.ToArray();
|
||||||
} else if (layerName == "decorations") {
|
} 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);
|
Debug.WriteLine("world size: {0}x{1}", gridWidth, gridHeight);
|
||||||
|
|
||||||
// Because we added tiles from left to right, the CollisionTargets are sorted by x-position.
|
// Because we added tiles from left to right, the CollisionTargets are sorted by x-position.
|
||||||
|
Loading…
Reference in New Issue
Block a user