public LoadMap ( String path, String mapname ) : void | ||
path | String | The path of the map, WITHOUT a trailing slash. |
mapname | String | The mapname. |
return | void |
public void LoadMap(String path, String mapname)
{
for (int i = 0; i < this.mapWidth / this.tree.quadWidth; i++)
{
for (int j = 0; j < this.mapHeight / this.tree.quadHeight; j++)
{
FileStream stream = new FileStream(path + "/" + mapname + "/" +
mapname + "_" + i + "_" + j +".png", FileMode.Open);
if (stream.Length == 0)
{
this.tree.GetQuadByIndex(new Point(i, j)).collisionTexture.texture =
new Texture2D(this.graphicsDevice, (int)this.tree.quadWidth, (int)this.tree.quadHeight);
} else this.tree.GetQuadByIndex(new Point(i, j)).collisionTexture.texture = Texture2D.FromStream(this.graphicsDevice, stream);
stream.Close();
stream.Dispose();
if (onMapTileLoadListeners != null) onMapTileLoadListeners(this);
}
}
}
private void loadToolStripMenuItem_Click(object sender, EventArgs e) { OpenFileDialog openfile = new OpenFileDialog(); //savefile.InitialDirectory = "../Tilesets"; openfile.Filter = "XML Document (*.xml)|*.xml"; openfile.Title = "Save map"; if (openfile.ShowDialog() == DialogResult.OK) { Players.Clear(); tileMap = new TileMap.TileMap(1, 1); tileMap = tileMap.opentilemap(openfile.FileName); //load Collisionmap PathfindingNodeManager.GetInstance().ClearNodes(); CollisionMap = new CollisionMap(GraphicsDevice, tileMap.MapWidth * Engine.TileWidth, tileMap.MapHeight * Engine.TileHeight, true, Util.GetQuadDepth(tileMap.MapWidth)); CollisionMap.LoadMap(openfile.FileName.Substring(0, openfile.FileName.LastIndexOf('\\')), openfile.FileName.Substring(openfile.FileName.LastIndexOf('\\')).Replace(".xml", "")); PathfindingNodeManager.GetInstance().ClearNodes(); Util.LoadNodes(openfile.FileName, GraphicsDevice); Util.LoadPlayers(openfile.FileName); CollisionData = new int[(tileMap.MapWidth * Engine.TileWidth) * (tileMap.MapHeight * Engine.TileHeight)]; currentLayer = tileMap.layers[0]; } }