Ejemplo n.º 1
0
        /// <summary>
        /// Prepares the specified <see cref="Tilemap"/> for user editing using the specified size.
        /// </summary>
        /// <param name="tilemap"></param>
        /// <param name="tilesetRef"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <param name="isUpperLayer"></param>
        public static void SetupTilemap(Tilemap tilemap, ContentRef<Tileset> tilesetRef, int width, int height, bool isUpperLayer)
        {
            Tileset tileset = tilesetRef.Res;

            // Determine the first tile index that matches the layer type.
            int fillTileIndex = GetDefaultTileIndex(tileset, isUpperLayer);

            // Resize the Tilemap and fill it with the first visually non-empty tile.
            tilemap.Tileset = tileset;
            tilemap.Resize(width, height);
            tilemap.BeginUpdateTiles().Fill(
                new Tile(fillTileIndex),
                0,
                0,
                tilemap.Size.X,
                tilemap.Size.Y);
            tilemap.EndUpdateTiles();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Runs the flood fill algorithm on the specified position and writes the result into the specified variables.
        /// </summary>
        /// <param name="tilemap"></param>
        /// <param name="pos"></param>
        /// <param name="preview">If true, the algorithm will cancel when taking too long for an interactive preview.</param>
        /// <param name="floodFillArea"></param>
        /// <param name="floodFillOrigin"></param>
        /// <returns>True, if the algorithm completed. False, if it was canceled.</returns>
        public bool GetFillArea(Tilemap tilemap, Point2 pos, bool preview, Grid <bool> floodFillArea, ref Point2 floodFillOrigin)
        {
            Grid <Tile> tiles = tilemap.BeginUpdateTiles();
            Point2      fillTopLeft;
            Point2      fillSize;
            bool        success = this.FillArea(ref this.activeFillBuffer, tiles, pos, preview ? (128 * 128) : 0, out fillTopLeft, out fillSize);

            tilemap.EndUpdateTiles(0, 0, 0, 0);

            // Find the filled areas boundaries and copy it to the active area
            if (success)
            {
                floodFillOrigin = fillTopLeft;
                floodFillArea.ResizeClear(fillSize.X, fillSize.Y);
                this.activeFillBuffer.CopyTo(floodFillArea, 0, 0, -1, -1, floodFillOrigin.X, floodFillOrigin.Y);
            }

            return(success);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Runs the flood fill algorithm on the specified position and writes the result into the specified variables.
        /// </summary>
        /// <param name="tilemap"></param>
        /// <param name="pos"></param>
        /// <param name="preview">If true, the algorithm will cancel when taking too long for an interactive preview.</param>
        /// <param name="floodFillArea"></param>
        /// <param name="floodFillOrigin"></param>
        /// <returns>True, if the algorithm completed. False, if it was canceled.</returns>
        private bool GetFloodFillArea(Tilemap tilemap, Point2 pos, bool preview, Grid<bool> floodFillArea, ref Point2 floodFillOrigin)
        {
            Grid<Tile> tiles = tilemap.BeginUpdateTiles();
            Point2 fillTopLeft;
            Point2 fillSize;
            bool success = FloodFillTiles(ref this.activeFillBuffer, tiles, pos, preview ? (128 * 128) : 0, out fillTopLeft, out fillSize);
            tilemap.EndUpdateTiles(0, 0, 0, 0);

            // Find the filled areas boundaries and copy it to the active area
            if (success)
            {
                floodFillOrigin = fillTopLeft;
                floodFillArea.ResizeClear(fillSize.X, fillSize.Y);
                this.activeFillBuffer.CopyTo(floodFillArea, 0, 0, -1, -1, floodFillOrigin.X, floodFillOrigin.Y);
            }

            return success;
        }