During my game, you can save a map and store the tiles in the map into a xml file.
So far no problem. The problem starts when I try to save it it gives me a UnauthorizedAccessException
error somehow.
The folder is located in the installation dir of my game:
instal_dir/data/maps/
I checked to make sure, but the folder is created succesfully with the correct permissions (write, read and execute).
Am I doing something wrong?
Here is my code:
private void CreateXMLOfMap()
{
List<Tile> tiles = mapContainer.GetTileList();
XmlDocument doc = new XmlDocument();
XmlNode docNode = doc.CreateXmlDeclaration("1.0", "UTF-8", null);
doc.AppendChild(docNode);
XmlNode rootNode = doc.CreateElement("Map");
doc.AppendChild(rootNode);
XmlNode mapName = doc.CreateElement("Name");
mapName.AppendChild(doc.CreateTextNode("custom_map"));
rootNode.AppendChild(mapName);
XmlNode tilesNode = doc.CreateElement("Tiles");
rootNode.AppendChild(tilesNode);
for (int i = 0; i < tiles.Count; i++ )
{
XmlNode tileNode = doc.CreateElement("Tile");
tilesNode.AppendChild(tileNode);
XmlNode positionNode = doc.CreateElement("Position");
tileNode.AppendChild(positionNode);
XmlNode xNode = doc.CreateElement("X");
xNode.AppendChild(doc.CreateTextNode(tiles[i].GetTilePosition().X.ToString()));
positionNode.AppendChild(xNode);
XmlNode yNode = doc.CreateElement("Y");
yNode.AppendChild(doc.CreateTextNode(tiles[i].GetTilePosition().Y.ToString()));
positionNode.AppendChild(yNode);
XmlNode textureNode = doc.CreateElement("Texture");
textureNode.AppendChild(doc.CreateTextNode(tiles[i].GetTileInfo().Name.ToString()));
tileNode.AppendChild(textureNode);
XmlNode YFrameNode = doc.CreateElement("YFrame");
YFrameNode.AppendChild(doc.CreateTextNode(tiles[i].GetCurrentFrame().Y.ToString()));
tileNode.AppendChild(YFrameNode);
}
doc.Save(Constants.MAPS_DIRECTORY);
}