Example #1
0
        private void Resize(int newWidth, int newHeight)
        {
            newWidth = FlaiMath.Max(EditorMap.MinimumWidth, newWidth);
            newHeight = FlaiMath.Max(EditorMap.MinimumHeight, newHeight);
            if (newWidth == _width && newHeight == _height)
            {
                return;
            }

            TileType[] newTiles = new TileType[newWidth * newHeight];
            newTiles.Populate(TileType.Air); // not very fast. could be done faster

            int lastY = Math.Min(_height, newHeight);
            int lastX = Math.Min(_width, newWidth);
            for (int y = 0; y < lastY; y++)
            {
                for (int x = 0; x < lastX; x++)
                {
                    newTiles[x + y * newWidth] = _tiles[x + y * _width];
                }
            }

            _width = newWidth;
            _height = newHeight;
            _tiles = newTiles;
        }