예제 #1
0
        private static void ReadLayers(ContentReader input, TiledMap map)
        {
            var layerCount = input.ReadInt32();

            for (var i = 0; i < layerCount; i++)
            {
                TiledMapLayer layer;

                var layerType = (TiledMapLayerType)input.ReadByte();
                switch (layerType)
                {
                case TiledMapLayerType.ImageLayer:
                    layer = new TiledMapImageLayer(input);
                    break;

                case TiledMapLayerType.TileLayer:
                    layer = new TiledMapTileLayer(input, map);
                    break;

                case TiledMapLayerType.ObjectLayer:
                    layer = new TiledMapObjectLayer(input, map);
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }

                if (layerType != TiledMapLayerType.ObjectLayer)
                {
                    ReadModels(input, layer, map);
                }

                map.AddLayer(layer);
            }
        }
예제 #2
0
        public Tile GetTileAt(TiledMapTileLayer layer, int x, int y)
        {
            if (x < 0 || x >= Width || y < 0 || y >= Height)
            {
                return(null);
            }

            TiledMapTile?tiledTile;

            if (!layer.TryGetTile(x, y, out tiledTile) || tiledTile.Value.GlobalIdentifier == 0)
            {
                return(null);
            }

            var globalId         = tiledTile.Value.GlobalIdentifier;
            var tileset          = GetTilesetByTileGlobalIdentifier(globalId);
            var localId          = globalId - tileset.FirstGlobalIdentifier;
            var tiledTilesetTile = tileset.GetTileByLocalTileIdentifier(localId);

            if (tiledTilesetTile == null)
            {
                return(new Tile(globalId, localId, x, y));
            }
            else
            {
                return(new Tile(globalId, tiledTilesetTile.LocalTileIdentifier, x, y, tiledTilesetTile.Properties));
            }
        }
        private static TiledMapTileLayer ReadTileLayer(ContentReader reader, string name, Vector2 offset, float opacity, bool isVisible, TiledMap map)
        {
            var width      = reader.ReadInt32();
            var height     = reader.ReadInt32();
            var tileWidth  = map.TileWidth;
            var tileHeight = map.TileHeight;

            var tileCount = reader.ReadInt32();
            var layer     = new TiledMapTileLayer(name, width, height, tileWidth, tileHeight, offset, opacity, isVisible);

            for (var i = 0; i < tileCount; i++)
            {
                var globalTileIdentifierWithFlags = reader.ReadUInt32();
                var x = reader.ReadUInt16();
                var y = reader.ReadUInt16();

                layer.Tiles[x + y * width] = new TiledMapTile(globalTileIdentifierWithFlags, x, y);
            }

            return(layer);
        }