public void LoadMap() { StringReader S = new StringReader(Data); using (XmlReader reader = XmlReader.Create(S)) { XmlSerializer XS = new XmlSerializer(typeof(TiledMap)); map = (TiledMap)XS.Deserialize(reader); } if (map.properties != null) { for (int i = 0; i < map.properties.Count; i++) { Properties.Add(map.properties[i].name, map.properties[i].value); } } for (int L = 0; L < map.allLayers.Count; L++) { map.allLayers[L].Load(); if (map.allLayers[L] is TiledObjectGroup) { TiledObjectGroup layer = (TiledObjectGroup)map.allLayers[L]; for (int O = 0; O < layer.objects.Count; O++) { layer.objects[O].Load(); } } } }
public void Generate() { for (int L = 0; L < Raw.map.allLayers.Count; L++) { if (Raw.map.allLayers[L] is TiledLayerTile) { TiledLayerTile layer = (TiledLayerTile)Raw.map.allLayers[L]; Entity t = App.world.CreateEntity(); t.Set(new TileMap() { Data = layer.data.value, Dimensions = new Point( layer.width, layer.height ), LayerID = L, LayerName = layer.name, spriteSheet = Raw.map.tileset.name, LayerDepth = 0, Solid = (layer.Property("collisions") == "true") }); } else if (Raw.map.allLayers[L] is TiledObjectGroup) { TiledObjectGroup layer = (TiledObjectGroup)Raw.map.allLayers[L]; for (int o = 0; o < layer.objects.Count; o++) { float Parallax; if (!float.TryParse(TiledProperty.prop(layer.properties, "parallax"), out Parallax)) { Parallax = 1; } App.Factories[layer.objects[o].type].Create( 0, L, Parallax, new Vector2( layer.objects[o].x, layer.objects[o].y ), layer.objects[o] ); } } } }