コード例 #1
0
 public void Dispose()
 {
     ConnectedMaps.Remove(this);
     if (ConnectedMaps.Count == 0)
     {
         TiledBase.RemoveMap(Map);
     }
 }
コード例 #2
0
        /// <summary>
        /// Loads all mapLayers onto this component.
        /// </summary>
        /// <param name="map">The reference of the tiled map that should be loaded.</param>
        /// <param name="tiledBase">A reference to the base from where the load call was made.</param>
        public new void Set(TmxMap map, TiledBase tiledBase)
        {
            base.Set(map, tiledBase);

            Layers = new TiledLayer[map.TileLayers.Count];
            for (int i = 0; i < Layers.Length; i++)
            {
                Layers[i] = new TiledLayer(tiledBase, Map, this, i);
            }
        }
コード例 #3
0
        /// <summary>
        /// Loads the specified mapLayers onto this component.
        /// </summary>
        /// <param name="map">The reference of the tiled map that should be loaded.</param>
        /// <param name="tiledBase">A reference to the base from where the load call was made.</param>
        /// <param name="fromLayer">Layer to start loading from.</param>
        /// <param name="amountToLoad">How many layers to load.</param>
        public void Set(TmxMap map, TiledBase tiledBase, int fromLayer, int amountToLoad)
        {
            Set(map, tiledBase);

            // Create all layers
            Layers = new TiledLayer[amountToLoad];
            int index = -1;

            for (int i = fromLayer; i < fromLayer + amountToLoad; i++)
            {
                Layers[++index] = new TiledLayer(tiledBase, Map, this, i);
            }
        }
コード例 #4
0
        /// <summary>
        /// Sets all internal variables.
        /// </summary>
        /// <param name="map">The reference of the tiled map that should be loaded.</param>
        /// <param name="tiledBase">A reference to the base from where the load call was made.</param>
        protected void Set(TmxMap map, TiledBase tiledBase)
        {
            Map = map;

            // If the actor does not have a transform then print an error.
            if (Actor.TryGetComponent(out transform) == false)
            {
                Log.Error("There is no transform on TiledMap!");
            }

            TileWidth  = map.TileWidth;
            TileHeight = map.TileHeight;

            Width  = map.Width;
            Height = map.Height;

            TiledBase = tiledBase;
        }
コード例 #5
0
        /// <summary>
        /// Loads the specififed Layer onto this component.
        /// </summary>
        /// <param name="map">The reference of the tiled map that should be loaded.</param>
        /// <param name="tiledBase">A reference to the base from where the load call was made.</param>
        /// <param name="layer">Which layer to load.</param>
        public void Set(TmxMap map, TiledBase tiledBase, int layer)
        {
            Set(map, tiledBase);

            Layer = new TiledLayer(tiledBase, map, this, layer);
        }
コード例 #6
0
ファイル: TiledLayer.cs プロジェクト: RhythNS/MonoNet
        /// <summary>
        /// Creates a new TiledLayer with given parameters.
        /// </summary>
        /// <param name="tiledBase">Instance of the tiledBase from where this map was created.</param>
        /// <param name="map">Instance of the map from where this layer is from.</param>
        /// <param name="layerIndex">The index of the layer that should be loaded from the map.</param>
        /// <param name="enabled">If it should be rendered after initialization.</param>
        public TiledLayer(TiledBase tiledBase, TmxMap map, TiledMapComponent mapComponent, int layerIndex, bool enabled = true)
        {
            TmxLayer   layer     = map.TileLayers[layerIndex];
            Transform2 transform = mapComponent.Actor.GetComponent <Transform2>();

            this.enabled = enabled;
            tiles        = new List <Tile>();

            int tileWidth  = map.TileWidth;
            int tileHeight = map.TileHeight;
            int width      = map.Width;

            // Go through all tiles
            for (int i = 0; i < layer.Tiles.Count; i++)
            {
                TmxLayerTile layerTile = layer.Tiles[i];
                int          gid       = layerTile.Gid;

                // Empty tile, do nothing
                if (gid == 0)
                {
                    continue;
                }

                // Get the acctual gid value
                gid--;

                // Get the correct tileset with the gid value
                TmxTileset toFindTileset = null;
                for (int j = 0; j < map.Tilesets.Count; j++)
                {
                    gid -= map.Tilesets[j].TileCount ?? 0;
                    if (gid <= 0)
                    {
                        toFindTileset = map.Tilesets[j];
                        break;
                    }
                }


                // set gid to a positive value again
                gid += toFindTileset.TileCount ?? 0;


                Texture2D tilesetImage = tiledBase.GetTilesetImage(toFindTileset.Image.Source);

                int columns = toFindTileset.Columns.Value;

                int column = gid % columns;
                int row    = gid / columns;

                float x = layerTile.X * tileWidth;
                float y = layerTile.Y * tileHeight;

                if (toFindTileset.Tiles.TryGetValue(gid, out TmxTilesetTile tilesetTile) == true)
                {
                    // Get all hitboxes
                    for (int groupIndex = 0; groupIndex < tilesetTile.ObjectGroups.Count; groupIndex++)
                    {
                        for (int objectIndex = 0; objectIndex < tilesetTile.ObjectGroups[groupIndex].Objects.Count; objectIndex++)
                        {
                            tiledBase.NotifyHitboxLoaded(mapComponent, transform, tilesetTile.ObjectGroups[groupIndex].Objects[objectIndex], x, y);
                        }
                    }
                }
                // TODO: Add AnimationTile
                tiles.Add(new StaticTile(x, y, new TextureRegion(tilesetImage, column * tileWidth, row * tileHeight, tileWidth, tileHeight)));
            }
        }