private void LoadTexture(XmlReader reader, ContentManager theContent, Background theTile) { string currentElement = string.Empty; while (reader.Read()) { //Exit the While loop when the end node is encountered and add the Tile if (reader.NodeType == XmlNodeType.EndElement && reader.Name.Equals("picture", StringComparison.OrdinalIgnoreCase)) { break; } if (reader.NodeType == XmlNodeType.Element) { currentElement = reader.Name; switch (currentElement) { case "name": { string aAssetName = reader.ReadElementContentAsString(); theTile.texture = theContent.Load<Texture2D>("Background/"+aAssetName); theTile.position = new Vector2(theTile.texture.Width, theTile.texture.Height); break; } } } } }
//Load information about the tile defined in the Level XML file private void LoadTile(XmlReader reader) { string currentElement = string.Empty; Background texture = new Background(); while (reader.Read()) { //Exit the While loop when the end node is encountered and add the Tile if (reader.NodeType == XmlNodeType.EndElement && reader.Name.Equals("texture", StringComparison.OrdinalIgnoreCase)) { mTextures.Add(texture.id, texture); break; } if (reader.NodeType == XmlNodeType.Element) { currentElement = reader.Name; switch (currentElement) { case "id": { texture.id = reader.ReadElementContentAsString().ToCharArray()[0]; break; } case "picture": { LoadTexture(reader, content, texture); break; } case "properties": { LoadProperties(reader, texture); break; } } } } }
private void LoadProperties(XmlReader theReader, Background theTile) { string aCurrentElement = string.Empty; while (theReader.Read()) { if (theReader.NodeType == XmlNodeType.EndElement && theReader.Name.Equals("properties", StringComparison.OrdinalIgnoreCase)) { break; } if (theReader.NodeType == XmlNodeType.Element) { aCurrentElement = theReader.Name; switch (aCurrentElement) { case "walkable": { theTile.walkable = theReader.ReadElementContentAsBoolean(); break; } } } } }