Exemplo n.º 1
0
        /// <summary>
        /// Adds a map to a single actor.
        /// </summary>
        /// <param name="actor">The actor to place the map onto.</param>
        /// <param name="path">The path of the map inside content.</param>
        /// <param name="addTransform">If a new transform component should be added to the actir,</param>
        /// <returns>The map in form of a TiledMapComponent.</returns>
        public TiledMapComponent AddMap(Actor actor, string path, bool addTransform = false)
        {
            TmxMap map = InnerLoadMap(path);

            // Create the TiledMapComponent
            if (addTransform == true)
            {
                actor.AddComponent <Transform2>();
            }

            TiledMultiLayerComponent tiledMapComponent = actor.AddComponent <TiledMultiLayerComponent>();

            tiledMapComponent.Set(map, this);

            // Set the shared maps. In this case it is only the single multilayercomponent.
            List <TiledMapComponent> sharedMaps = new List <TiledMapComponent>
            {
                tiledMapComponent
            };

            tiledMapComponent.SetConnectedMaps(sharedMaps);
            loadedMaps.Add(map);

            // Load all objectss.
            NotifyLoadObjects(map, sharedMaps);

            return(tiledMapComponent);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Helper method for AddMap with stage. Creates either a TiledSingleLayer or TiledMultiLayer depending
        /// on how many layers should be created.
        /// </summary>
        /// <param name="map">A reference to the TiledMap of which the layer should be made from.</param>
        /// <param name="stage">A refernce to the stage where the actor comes from which has the new map component.</param>
        /// <param name="actorLayer">The layer of where the created actor should be placed upon.</param>
        /// <param name="from">First index of layer to be created.</param>
        /// <param name="to">Last index of layer to be created.</param>
        /// <returns>The new TiledMapComponent of the specified layers.</returns>
        private TiledMapComponent InnerAddMapWithActor(TmxMap map, Stage stage, int actorLayer, bool useSharedTrans, int from, int to)
        {
            // First create and actor on the specified layer and add a transform to it.
            Actor actor = stage.CreateActor(actorLayer);

            if (useSharedTrans == true)
            {
                actor.AddComponent <SharedPositionTransform2>();
            }
            else
            {
                actor.AddComponent <Transform2>();
            }

            int count = to - from;

            if (count == 0) // If only one layer should be made
            {
                TiledSingleLayerComponent singleLayer = actor.AddComponent <TiledSingleLayerComponent>();
                singleLayer.Set(map, this, from);
                return(singleLayer);
            }
            else // If more than one layer should be made
            {
                TiledMultiLayerComponent multiLayer = actor.AddComponent <TiledMultiLayerComponent>();
                multiLayer.Set(map, this, from, count + 1);
                return(multiLayer);
            }
        }