CEngineSharp_Editor.World.Map.ResizeMap C# (CSharp) Метод

ResizeMap() публичный Метод

public ResizeMap ( int newWidth, int newHeight ) : void
newWidth int
newHeight int
Результат void
        public void ResizeMap(int newWidth, int newHeight)
        {
            Tile[,] newArray = new Tile[newWidth, newHeight];
            int minX = Math.Min(this.tiles.GetLength(0), newArray.GetLength(0));
            int minY = Math.Min(this.tiles.GetLength(1), newArray.GetLength(1));

            for (int i = 0; i < minX; ++i)
                Array.Copy(this.tiles, i * this.tiles.GetLength(1), newArray, i * newArray.GetLength(1), minY);

            this.tiles = newArray;
        }

Usage Example

Пример #1
0
        public static Map LoadMap(string filePath, List<Texture> tileSetTextures)
        {
            Map map = new Map();

            using (FileStream fileStream = new FileStream(filePath, FileMode.Open))
            {
                using (BinaryReader binaryReader = new BinaryReader(fileStream))
                {
                    map.Name = binaryReader.ReadString();

                    map.Version = binaryReader.ReadInt32();

                    int mapWidth = binaryReader.ReadInt32();
                    int mapHeight = binaryReader.ReadInt32();

                    map.ResizeMap(mapWidth, mapHeight);

                    for (int x = 0; x < mapWidth; x++)
                    {
                        for (int y = 0; y < mapHeight; y++)
                        {
                            map.tiles[x, y] = new Tile();

                            map.tiles[x, y].Blocked = binaryReader.ReadBoolean();

                            if (map.tiles[x, y].Blocked)
                            {
                                map.tiles[x, y].BlockedCover = new RectangleShape(new Vector2f(32, 32));
                                map.tiles[x, y].BlockedCover.FillColor = new Color(255, 0, 0, 100);
                                map.tiles[x, y].BlockedCover.Position = new Vector2f(x * 32, y * 32);
                            }

                            foreach (Layers layer in Enum.GetValues(typeof(Map.Layers)))
                            {
                                if (binaryReader.ReadBoolean() == false) continue;

                                int tileSetTextureIndex = binaryReader.ReadInt32();
                                int tileLeft = binaryReader.ReadInt32();
                                int tileTop = binaryReader.ReadInt32();
                                int tileWidth = binaryReader.ReadInt32();
                                int tileHeight = binaryReader.ReadInt32();

                                map.tiles[x, y].Layers[(int)layer] = new Tile.Layer(new Sprite(tileSetTextures[tileSetTextureIndex], new IntRect(tileLeft, tileTop, tileWidth, tileHeight)), x, y);
                            }
                        }
                    }
                }
            }

            return map;
        }
All Usage Examples Of CEngineSharp_Editor.World.Map::ResizeMap