Exemple #1
0
        /// <summary>
        ///   Adds a given background layer to the front of the background.
        /// </summary>
        /// <param name="layer">The background layer to add.</param>
        public void AddLayerToFront(BackgroundLayer layer)
        {
            Layers.Add(layer);

            if (isContentLoaded)
            {
                layer.LoadContent();
            }
        }
        private static Background GenerateBackground(Section owner)
        {
            Background result = new Background(owner);
            result.TopColor = result.BottomColor = new Color(0, 0, 0, 0);

            BackgroundLayer layer = new BackgroundLayer(GameServices.Camera, owner.Bounds);
            layer.BackgroundTextureResourceName = "Background";
            layer.ScrollDirection = (BackgroundScrollDirection)1;
            layer.ScrollRate = 0.5f;

            result.AddLayerToFront(layer);
            return result;
        }
Exemple #3
0
        public void Deserialize(string json)
        {
            JObject obj = JObject.Parse(json);

            // Deserialize the root objects first.
            TopColor = obj["topColor"].ToColor();
            BottomColor = obj["bottomColor"].ToColor();

            // Now, get the Layers.
            JArray layersData = (JArray)obj["layers"];

            foreach (var layerData in layersData)
            {
                BackgroundLayer layer = new BackgroundLayer(owner.Camera, owner.Bounds);
                layer.Deserialize(layerData.ToString());
                Layers.Add(layer);
            }
        }
Exemple #4
0
		internal List<BackgroundLayer> DeserializeBackgroundLayers(JArray layers, Camera2D ownerCamera, BoundingRectangle ownerBounds)
		{
			List<BackgroundLayer> result = new List<BackgroundLayer>(layers.Count);

			foreach (var layerData in layers)
			{
				BackgroundLayer layer = new BackgroundLayer(ownerCamera, ownerBounds);

				string resourceName = (string)layerData["resourceName"];
				BackgroundScrollDirection direction = (BackgroundScrollDirection)(int)layerData["scrollDirection"];
				float scrollRate = (float)layerData["scrollRate"];

				layer.BackgroundTextureResourceName = resourceName;
				layer.ScrollDirection = direction;
				layer.ScrollRate = scrollRate;

				result.Add(layer);
			}

			return result;
		}