protected TiledLayer(string name) { Name = name; Properties = new TiledProperties(); IsVisible = true; Opacity = 1.0f; }
public TiledTileset(Texture2D texture, int firstId, int tileWidth, int tileHeight, int spacing = 2, int margin = 2) { //if (texture.Width % tileWidth != 0 || texture.Height % tileHeight != 0) // throw new InvalidOperationException("The tileset texture must be an exact multiple of the tile size"); Texture = texture; FirstId = firstId; TileWidth = tileWidth; TileHeight = tileHeight; Spacing = spacing; Margin = margin; Properties = new TiledProperties(); var id = FirstId; _regions = new Dictionary<int, TextureRegion2D>(); for (var y = Margin; y < texture.Height - Margin; y += TileHeight + Spacing) { for (var x = Margin; x < texture.Width - Margin; x += TileWidth + Spacing) { _regions.Add(id, new TextureRegion2D(Texture, x, y, TileWidth, TileHeight)); id++; } } }
public TiledLayer(TiledMap tiledMap, GraphicsDevice graphicsDevice, string name, int width, int height, int[] data) { Name = name; Width = width; Height = height; Properties = new TiledProperties(); _tiledMap = tiledMap; _spriteBatch = new SpriteBatch(graphicsDevice); _tiles = CreateTiles(data); }
public TiledMap(GraphicsDevice graphicsDevice, int width, int height, int tileWidth, int tileHeight) { Width = width; Height = height; TileWidth = tileWidth; TileHeight = tileHeight; Properties = new TiledProperties(); _graphicsDevice = graphicsDevice; _layers = new List<TiledLayer>(); _tilesets = new List<TiledTileset>(); }
public TiledObject(TiledObjectType objectType, int id, int? gid, float x, float y, float width, float height) { ObjectType = objectType; Id = id; Gid = gid; X = x; Y = y; Width = width; Height = height; Points = new List<Vector2>(); Properties = new TiledProperties(); }
public TiledMap(GraphicsDevice graphicsDevice, int width, int height, int tileWidth, int tileHeight, TiledMapOrientation orientation = TiledMapOrientation.Orthogonal) { Width = width; Height = height; TileWidth = tileWidth; TileHeight = tileHeight; Properties = new TiledProperties(); _graphicsDevice = graphicsDevice; _layers = new List<TiledLayer>(); _tilesets = new List<TiledTileset>(); Orientation = orientation; }
public TiledTileset(Texture2D texture, int firstId, int tileWidth, int tileHeight, int spacing = 2, int margin = 2) { Texture = texture; FirstId = firstId; TileWidth = tileWidth; TileHeight = tileHeight; Spacing = spacing; Margin = margin; Properties = new TiledProperties(); var id = FirstId; _regions = new Dictionary<int, TextureRegion2D>(); for (var y = Margin; y < texture.Height - Margin; y += TileHeight + Spacing) { for (var x = Margin; x < texture.Width - Margin; x += TileWidth + Spacing) { _regions.Add(id, new TextureRegion2D(Texture, x, y, TileWidth, TileHeight)); id++; } } }
public TiledTileset(Texture2D texture, int firstId, int tileWidth, int tileHeight, int spacing = 2, int margin = 2) { Texture = texture; FirstId = firstId; TileWidth = tileWidth; TileHeight = tileHeight; Spacing = spacing; Margin = margin; Properties = new TiledProperties(); var id = FirstId; _regions = new Dictionary <int, TextureRegion2D>(); for (var y = Margin; y < texture.Height - Margin; y += TileHeight + Spacing) { for (var x = Margin; x < texture.Width - Margin; x += TileWidth + Spacing) { _regions.Add(id, new TextureRegion2D(Texture, x, y, TileWidth, TileHeight)); id++; } } }
protected TiledLayer(string name) { Name = name; Properties = new TiledProperties(); }
public TiledObjectGroup(string name, TiledObject[] objects) { Name = name; Objects = objects; Properties = new TiledProperties(); }
public void AddProperties(TiledProperties properties) => Properties += properties;
public static MapLayer Load(XmlReader xr, GraphicsDevice graphicsDevice, TileSetManager tileSets, string directory) { xr.Read(); MapLayer result = new MapLayer(); result.tileSets = tileSets; result.name = xr["name"]; result.width = int.Parse(xr["width"]); result.height = int.Parse(xr["height"]); result.animatedOrInteractiveTiles = new List <BasicTile>(); while (xr.Read()) { if (xr.Name == "data" && xr.NodeType == XmlNodeType.Element) { string[] data = xr.ReadElementContentAsString().Split(','); result.data = new int[data.Length]; for (int i = 0; i < data.Length; i++) { result.data[i] = int.Parse(data[i]); } } if (xr.Name == "properties" && xr.NodeType == XmlNodeType.Element) //Properties { using (StringReader sr = new StringReader(xr.ReadOuterXml())) using (XmlReader r = XmlReader.Create(sr)) result.properties = TiledProperties.Load(r); } if (xr.Name == "layer" && xr.NodeType == XmlNodeType.EndElement) //The End { break; } } Texture2D t = new Texture2D(graphicsDevice, result.width * BasicTile.Size, result.height * BasicTile.Size); for (int i = 0; i < result.data.Length; i++) { int x = i % result.width; int y = i / result.width; bool interactive = result.tileSets.IsInteractive(result.data[i]); bool animated = result.tileSets.IsAnimation(result.data[i]); if (animated || interactive) { TiledProperties properties = result.tileSets.GetProperties(result.data[i]); result.animatedOrInteractiveTiles.Add(BasicTile.LoadTile(interactive, animated, properties, new Index2(x, y))); continue; } Color[] data = result.tileSets.GetData(result.data[i]); if (data == null) { data = new Color[BasicTile.Size * BasicTile.Size]; for (int j = 0; j < BasicTile.Size * BasicTile.Size; j++) { data[j] = Color.Transparent; } } t.SetData(0, new Rectangle(x * BasicTile.Size, y * BasicTile.Size, BasicTile.Size, BasicTile.Size), data, 0, data.Length); } foreach (var tiles in result.animatedOrInteractiveTiles) { if (tiles is InteractiveTile interactive) { interactive.Load(Path.Combine(directory, @".\..\TileSets", interactive.Properties.GetPropertyAsFile("AnimationFile")), graphicsDevice); } } result.Prerendered = t; //result.Prerendered.SaveAsPng(new FileStream(".\\prerendered" + result.name + ".png", FileMode.Create), result.Prerendered.Width, result.Prerendered.Height); //Console.WriteLine("prerendered" + result.name + "Saved"); return(result); }