public static ImageLayer ImageLayerFromXml(GameResourceManager gameResourceManager, XElement layerElement) { var name = layerElement.Attribute("name").Value; var textureName = layerElement.Element("Texture").Value; var rectangleValue = layerElement.Element("Rectangle").Value; return new ImageLayer(name, gameResourceManager.GetTexture(textureName), MathUtil.ParseRectangle(rectangleValue)); }
private static TileSheet LoadTileset(TmxTileset tileset, Size tilesSize, GameResourceManager gameResourceManager) { var texturePath = Path.Combine(Path.GetDirectoryName(tileset.Image.Source), Path.GetFileNameWithoutExtension(tileset.Image.Source)) .Remove(0, ContentFolder.Length + 1); //var texture = gameResourceManager.GetTexture(@"Tiled\tmw_desert_spacing"); var texture = gameResourceManager.GetTexture(texturePath); //var sheet = new TileSheet(texture, "Desert", new Size(tmxMap.TileWidth, tmxMap.TileHeight)); var sheet = gameResourceManager.GetTileSheet(tileset.Name); if (sheet == null) { sheet = new TileSheet(texture, tileset.Name, tilesSize); var margin = tileset.Margin; var spacing = tileset.Spacing; var numTileWidth = (tileset.Image.Width - (2 * margin) + spacing) / (tileset.TileWidth + spacing); var numTileHeight = (tileset.Image.Height - (2 * margin) + spacing) / (tileset.TileHeight + spacing); for (var j = 0; j < numTileHeight; j++) for (var i = 0; i < numTileWidth; i++) sheet.CreateTileDefinition((tileset.FirstGid + i + numTileWidth * j).ToString(), new Point(margin + i * (tileset.TileWidth + spacing), margin + j * (tileset.TileHeight + spacing))); gameResourceManager.AddTileSheet(sheet); } return sheet; }