static TiledMapImageLayer ParseImageLayer(XmlNode layerXml) { var imageXml = layerXml["image"]; if (imageXml == null) { return(null); // Without image, layer is empty, so we won't need it. } var layer = new TiledMapImageLayer(); ParseBaseLayer(layerXml, layer); layer.TexturePath = XmlHelper.GetXmlStringSafe(imageXml, "source"); if (layer.TexturePath == "") { return(null); // Same thing. No path == no image. } if (imageXml.Attributes["trans"] != null) { layer.TransparentColor = XmlHelper.StringToColor(imageXml.Attributes["trans"].Value); } return(layer); }
private IEnumerable <TiledMapLayerModel> CreateImageLayerModels(TiledMapImageLayer imageLayer) { var modelBuilder = new TiledMapStaticLayerModelBuilder(); modelBuilder.AddSprite(imageLayer.Image, imageLayer.Position, imageLayer.Image.Bounds, TiledMapTileFlipFlags.None); yield return(modelBuilder.Build(_graphicsDevice, imageLayer.Image)); }
void ReadImageLayers(ContentReader input, TiledMap map) { var layersCount = input.ReadInt32(); var layers = new TiledMapImageLayer[layersCount]; for (var i = 0; i < layersCount; i += 1) { var layer = new TiledMapImageLayer(); ReadLayer(input, layer); layer.TexturePath = Path.Combine(Path.GetDirectoryName(input.AssetName), input.ReadString()); layer.Texture = input.ContentManager.Load <Texture2D>(input.ReadString()); layer.TransparentColor = input.ReadColor(); layers[i] = layer; } map.ImageLayers = layers; }
void ReadImageLayers(ContentReader input, TiledMap map) { var layersCount = input.ReadInt32(); var layers = new TiledMapImageLayer[layersCount]; for (var i = 0; i < layersCount; i += 1) { var layer = new TiledMapImageLayer(); ReadLayer(input, layer); layer.TexturePath = input.ReadString(); layer.Texture = input.ReadExternalReference <Texture2D>(); layer.TransparentColor = input.ReadColor(); layers[i] = layer; } map.ImageLayers = layers; }
/// <summary> /// Create the tile image layer as a child entity /// </summary> /// <param name="tmxImageLayer">The tmx image layer.</param> /// <param name="layerIndex">The layer index</param> private void CreateChildTileImageLayer(TmxImageLayer tmxImageLayer, int layerIndex) { var tag = "TileImageLayer_" + layerIndex; var tmxLayerName = tmxImageLayer.Name; var tiledMapImageLayer = new TiledMapImageLayer(tmxImageLayer, this); Entity layerEntity = null; layerEntity = this.Owner.FindChildrenByTag(tag).FirstOrDefault(); var tileLayerOffset = new Vector2((float)tmxImageLayer.OffsetX, (float)tmxImageLayer.OffsetY); if (layerEntity != null) { var tileMapTransform = layerEntity.FindComponent<Transform2D>(); var sprite = layerEntity.FindComponent<Sprite>(); if (tileMapTransform != null && sprite != null) { tileMapTransform.LocalPosition = tileLayerOffset; sprite.TexturePath = tiledMapImageLayer.ImagePath; layerEntity.Name = tmxLayerName; } else { this.Owner.RemoveChild(layerEntity.Name); layerEntity = null; } } if (layerEntity == null) { layerEntity = new Entity(tmxLayerName) { Tag = tag } .AddComponent(new Sprite(tiledMapImageLayer.ImagePath)) .AddComponent(new Transform2D() { LocalPosition = tileLayerOffset, Origin = this.transform.Origin, Opacity = (float)tmxImageLayer.Opacity }) .AddComponent(new SpriteRenderer()); this.Owner.AddChild(layerEntity); } this.imageLayers.Add(tmxLayerName, tiledMapImageLayer); }