Exemplo n.º 1
0
        /// <summary>
        /// This method can be used to figure out the source rect on a Tileset image for rendering tiles.
        /// </summary>
        /// <param name="mapTileset"></param>
        /// <param name="tileset"></param>
        /// <param name="gid"></param>
        /// <returns>An instance of the class TiledSourceRect that represents a rectangle. Returns null if the provided gid was not found within the tileset.</returns>
        public TiledSourceRect GetSourceRect(TiledMapTileset mapTileset, TiledTileset tileset, int gid)
        {
            var tileHor  = 0;
            var tileVert = 0;

            for (var i = 0; i < tileset.TileCount; i++)
            {
                if (i == gid - mapTileset.firstgid)
                {
                    var result = new TiledSourceRect();
                    result.x      = tileHor * tileset.TileWidth;
                    result.y      = tileVert * tileset.TileHeight;
                    result.width  = tileset.TileWidth;
                    result.height = tileset.TileHeight;

                    return(result);
                }

                // Update x and y position
                tileHor++;

                if (tileHor == tileset.Image.width / tileset.TileWidth)
                {
                    tileHor = 0;
                    tileVert++;
                }
            }

            return(null);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Locates a specific TiledTile object
        /// </summary>
        /// <param name="mapTileset">An element within the Tilesets array</param>
        /// <param name="tileset">An instance of the TiledTileset class</param>
        /// <param name="gid">An element from within a TiledLayer.data array</param>
        /// <returns>An entry of the TiledTileset.tiles array or null if none of the tile id's matches the gid</returns>
        /// <remarks>Tip: Use the GetTiledMapTileset and GetTiledTilesets methods for retrieving the correct TiledMapTileset and TiledTileset objects</remarks>
        public TiledTile GetTiledTile(TiledMapTileset mapTileset, TiledTileset tileset, int gid)
        {
            foreach (var tile in tileset.Tiles)
            {
                if (tile.id == gid - mapTileset.firstgid)
                {
                    return(tile);
                }
            }

            return(null);
        }
Exemplo n.º 3
0
        private TiledMapTileset[] ParseTilesets(XmlNodeList nodeList)
        {
            var result = new List <TiledMapTileset>();

            foreach (XmlNode node in nodeList)
            {
                var tileset = new TiledMapTileset();
                tileset.firstgid = int.Parse(node.Attributes["firstgid"].Value);
                tileset.source   = node.Attributes["source"].Value;

                result.Add(tileset);
            }

            return(result.ToArray());
        }
Exemplo n.º 4
0
        public int[] GetSourceVector(TiledMapTileset mapTileset, TiledTileset tileset, int gid)
        {
            var tileHor  = 0;
            var tileVert = 0;

            for (var i = 0; i < tileset.TileCount; i++)
            {
                if (i == gid - mapTileset.firstgid)
                {
                    return(new[] { tileHor, tileVert });
                }

                // Update x and y position
                tileHor++;

                if (tileHor == tileset.Image.width / tileset.TileWidth)
                {
                    tileHor = 0;
                    tileVert++;
                }
            }

            return(null);
        }