/// <summary /// >Default constructor creates a map from a .tmx file and creates any associated tileset textures by using the passed renderer. /// </summary> /// <param name="filePath">Path to the .tmx file to load</param> /// <param name="renderer">Renderer object used to load tileset textures</param> public TiledMap(string filePath, Renderer renderer, string contentRoot = "") { MapContent mapContent = new MapContent(filePath, renderer, contentRoot); TileWidth = mapContent.TileWidth; TileHeight = mapContent.TileHeight; PixelWidth = mapContent.Width * TileWidth; PixelHeight = mapContent.Height * TileHeight; HorizontalTileCount = mapContent.Width; VerticalTileCount = mapContent.Height; CreateLayers(mapContent); CalculateTilePositions(mapContent.Orientation); }
/// <summary> /// Create tile layers and object layers based on what we find in the Tiled Map TMX file. /// </summary> /// <param name="mapContent">Map contentManager.</param> private void CreateLayers(MapContent mapContent) { if (mapContent == null) throw new ArgumentNullException("mapContent"); foreach (LayerContent layerContent in mapContent.Layers) { if (layerContent is TileLayerContent) { TileLayer tileLayer = CreateTileLayer(layerContent, mapContent.TileSets); tileLayers.Add(tileLayer); } else if (layerContent is ObjectLayerContent) { MapObjectLayer mapObjectLayer = CreateObjectLayer(layerContent, mapContent.Orientation); mapObjectLayers.Add(mapObjectLayer); } } }