Exemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Tileset" /> class.
        /// </summary>
        /// <param name="tmxTileset">The TMX parsed tileset</param>
        /// <param name="tiledMap">The tiled map</param>
        public Tileset(TmxTileset tmxTileset, TiledMap tiledMap)
        {
            this.tiledMap = tiledMap;

            this.Name = tmxTileset.Name;
            this.TileWidth = tmxTileset.TileWidth;
            this.TileHeight = tmxTileset.TileHeight;
            this.Spacing = tmxTileset.Spacing;
            this.Margin = tmxTileset.Margin;
            this.XTilesCount = (int)(tmxTileset.Image.Width - (2 * this.Margin) + this.Spacing) / (this.TileWidth + this.Spacing);
            this.YTilesCount = (int)(tmxTileset.Image.Height - (2 * this.Margin) + this.Spacing) / (this.TileHeight + this.Spacing);

            this.FirstGid = tmxTileset.FirstGid;
            this.LastGid = tmxTileset.FirstGid + (this.XTilesCount * this.YTilesCount) - 1;

            this.terrains = new Dictionary<string, TilesetTerrain>();
            this.Terrains = new ReadOnlyDictionary<string, TilesetTerrain>(this.terrains);
            foreach (var tmxTerrain in tmxTileset.Terrains)
            {
                this.terrains.Add(tmxTerrain.Name, new TilesetTerrain(tmxTerrain));
            }

            this.tiles = new List<TilesetTile>();
            this.TilesTable = new TilesetTile[this.XTilesCount * this.YTilesCount];
            foreach (var tmxTilesetTile in tmxTileset.Tiles)
            {
                var tilesetTile = new TilesetTile(tmxTilesetTile, this);

                this.tiles.Add(tilesetTile);
                this.TilesTable[tilesetTile.ID] = tilesetTile;
            }

            this.Image = this.tiledMap.Owner.Scene.Assets.LoadAsset<Texture2D>(tmxTileset.Image.Source);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Tileset" /> class.
        /// </summary>
        /// <param name="tmxTileset">The TMX parsed tileset</param>
        /// <param name="tiledMap">The tiled map</param>
        public Tileset(TmxTileset tmxTileset, TiledMap tiledMap)
        {
            this.tiledMap = tiledMap;

            this.Name        = tmxTileset.Name;
            this.TileWidth   = tmxTileset.TileWidth;
            this.TileHeight  = tmxTileset.TileHeight;
            this.Spacing     = tmxTileset.Spacing;
            this.Margin      = tmxTileset.Margin;
            this.XTilesCount = (int)(tmxTileset.Image.Width - (2 * this.Margin) + this.Spacing) / (this.TileWidth + this.Spacing);
            this.YTilesCount = (int)(tmxTileset.Image.Height - (2 * this.Margin) + this.Spacing) / (this.TileHeight + this.Spacing);

            this.FirstGid = tmxTileset.FirstGid;
            this.LastGid  = tmxTileset.FirstGid + (this.XTilesCount * this.YTilesCount) - 1;

            this.terrains = new Dictionary <string, TilesetTerrain>();
            this.Terrains = new ReadOnlyDictionary <string, TilesetTerrain>(this.terrains);
            foreach (var tmxTerrain in tmxTileset.Terrains)
            {
                this.terrains.Add(tmxTerrain.Name, new TilesetTerrain(tmxTerrain));
            }

            this.tiles      = new List <TilesetTile>();
            this.TilesTable = new TilesetTile[this.XTilesCount * this.YTilesCount];
            foreach (var tmxTilesetTile in tmxTileset.Tiles)
            {
                var tilesetTile = new TilesetTile(tmxTilesetTile, this);

                this.tiles.Add(tilesetTile);
                this.TilesTable[tilesetTile.ID] = tilesetTile;
            }

            this.Image = this.tiledMap.Owner.Scene.Assets.LoadAsset <Texture2D>(tmxTileset.Image.Source);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="LayerTile" /> class.
        /// </summary>>
        /// <param name="tmxTile">The TMX parsed tile.</param>
        /// <param name="tileset">Th</param>
        public LayerTile(TmxLayerTile tmxTile, Tileset tileset)
        {
            this.Gid            = tmxTile.Gid;
            this.X              = tmxTile.X;
            this.Y              = tmxTile.Y;
            this.HorizontalFlip = tmxTile.HorizontalFlip;
            this.VerticalFlip   = tmxTile.VerticalFlip;
            this.DiagonalFlip   = tmxTile.DiagonalFlip;

            if (tileset != null)
            {
                this.Tileset = tileset;
                int tileId = this.Gid - this.Tileset.FirstGid;

                this.TilesetTile = this.Tileset.TilesTable[tileId];
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Tileset" /> class.
        /// </summary>
        /// <param name="tmxTileset">The TMX parsed tileset</param>
        /// <param name="tiledMap">The tiled map</param>
        public Tileset(TmxTileset tmxTileset, TiledMap tiledMap)
        {
            this.tiledMap = tiledMap;

            this.Name           = tmxTileset.Name;
            this.TileWidth      = tmxTileset.TileWidth;
            this.TileHeight     = tmxTileset.TileHeight;
            this.Spacing        = tmxTileset.Spacing;
            this.Margin         = tmxTileset.Margin;
            this.XTilesCount    = (int)(tmxTileset.Image.Width - (2 * this.Margin) + this.Spacing) / (this.TileWidth + this.Spacing);
            this.YTilesCount    = (int)(tmxTileset.Image.Height - (2 * this.Margin) + this.Spacing) / (this.TileHeight + this.Spacing);
            this.XDrawingOffset = (int)tmxTileset.TileOffset.X;
            this.YDrawingOffset = (int)tmxTileset.TileOffset.Y;

            if (tmxTileset.Colums.HasValue)
            {
                this.Colums = tmxTileset.Colums.Value;
            }

            this.FirstGid = tmxTileset.FirstGid;
            this.LastGid  = tmxTileset.FirstGid + (this.XTilesCount * this.YTilesCount) - 1;

            this.terrains = new Dictionary <string, TilesetTerrain>();
            this.Terrains = new ReadOnlyDictionary <string, TilesetTerrain>(this.terrains);
            foreach (var tmxTerrain in tmxTileset.Terrains)
            {
                this.terrains.Add(tmxTerrain.Name, new TilesetTerrain(tmxTerrain));
            }

            this.tiles      = new List <TilesetTile>();
            this.TilesTable = new TilesetTile[this.XTilesCount * this.YTilesCount];
            foreach (var tmxTilesetTile in tmxTileset.Tiles)
            {
                var tilesetTile = new TilesetTile(tmxTilesetTile, this);

                this.tiles.Add(tilesetTile);
                this.TilesTable[tilesetTile.ID] = tilesetTile;
            }

            string fullPath     = tmxTileset.Image.Source;
            string relativePath = fullPath.Substring(fullPath.IndexOf("Content"));

            this.Image = this.tiledMap.Owner.Scene.Assets.LoadAsset <Texture2D>(relativePath);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Tileset" /> class.
        /// </summary>
        /// <param name="tmxTileset">The TMX parsed tileset</param>
        /// <param name="tiledMap">The tiled map</param>
        public Tileset(TmxTileset tmxTileset, TiledMap tiledMap)
        {
            this.tiledMap = tiledMap;

            this.Name = tmxTileset.Name;
            this.TileWidth = tmxTileset.TileWidth;
            this.TileHeight = tmxTileset.TileHeight;
            this.Spacing = tmxTileset.Spacing;
            this.Margin = tmxTileset.Margin;
            this.XTilesCount = (int)(tmxTileset.Image.Width - (2 * this.Margin) + this.Spacing) / (this.TileWidth + this.Spacing);
            this.YTilesCount = (int)(tmxTileset.Image.Height - (2 * this.Margin) + this.Spacing) / (this.TileHeight + this.Spacing);
            this.XDrawingOffset = (int)tmxTileset.TileOffset.X;
            this.YDrawingOffset = (int)tmxTileset.TileOffset.Y;

            if (tmxTileset.Colums.HasValue)
            {
                this.Colums = tmxTileset.Colums.Value;
            }

            this.FirstGid = tmxTileset.FirstGid;
            this.LastGid = tmxTileset.FirstGid + (this.XTilesCount * this.YTilesCount) - 1;

            this.terrains = new Dictionary<string, TilesetTerrain>();
            this.Terrains = new ReadOnlyDictionary<string, TilesetTerrain>(this.terrains);
            foreach (var tmxTerrain in tmxTileset.Terrains)
            {
                this.terrains.Add(tmxTerrain.Name, new TilesetTerrain(tmxTerrain));
            }

            this.tiles = new List<TilesetTile>();
            this.TilesTable = new TilesetTile[this.XTilesCount * this.YTilesCount];
            foreach (var tmxTilesetTile in tmxTileset.Tiles)
            {
                var tilesetTile = new TilesetTile(tmxTilesetTile, this);

                this.tiles.Add(tilesetTile);
                this.TilesTable[tilesetTile.ID] = tilesetTile;
            }

            string fullPath = tmxTileset.Image.Source;
            string relativePath = fullPath.Substring(fullPath.IndexOf("Content"));
            this.Image = this.tiledMap.Owner.Scene.Assets.LoadAsset<Texture2D>(relativePath);
        }