public ScrollingLogoBackground(Texture2D texture, Color color)
 {
     this.texture = texture;
     offsetIncrement = new Vector2(texture.Width, texture.Height);
     offsetIncrement.Normalize();
     this.backgroundColor = color;
     absoluteCamera = new Camera(GraphicsConstants.VIEWPORT_DIMENSIONS, Vector2.Zero);
 }
Exemple #2
0
        public static ParallaxBackgroundSet Build(AssetManager assets, Camera camera, Vector2 seamstressStart, string assetName)
        {
            TextDictionary assetDictionary = new TextDictionary(assets.GetText("parallax"));
            int layers = assetDictionary.LookupInt32(assetName, "layers");
            ParallaxBackground[] backgrounds = new ParallaxBackground[layers];
            BackgroundParticleSet particles = new BackgroundParticleSet(assets, camera.Dimensions, Convert.ToInt32(assetName.Substring(3)));
            int particleLayer = -1;
            for (int i = 0; i < layers; i++)
            {
                Texture2D tex;
                if (assetDictionary.CheckPropertyExists(assetName, "name" + i))
                    tex = assets.GetTexture(assetDictionary.LookupString(assetName, "name" + i));
                else
                    tex = assets.GetTexture(assetName + "_layer" + i);
                float dist, scale;
                Vector2 offset, velocity, repeat;
                Anchor anchor;
                try { dist = assetDictionary.LookupSingle(assetName, "dist" + i); }
                catch { dist = 1; }
                try { offset = assetDictionary.LookupVector2(assetName, "offset" + i); }
                catch { offset = Vector2.Zero; }
                try { velocity = assetDictionary.LookupVector2(assetName, "velocity" + i); }
                catch { velocity = Vector2.Zero; }
                try { scale = assetDictionary.LookupSingle(assetName, "scale" + i); }
                catch { scale = 1; }
                try { repeat = assetDictionary.LookupVector2(assetName, "repeat" + i); }
                catch { repeat = new Vector2(1, 0); }
                if (!assetDictionary.CheckPropertyExists(assetName, "anchor" + i) ||
                    !Enum.TryParse<Anchor>(assetDictionary.LookupString(assetName, "anchor" + i), out anchor))
                    anchor = Anchor.BottomLeft;
                backgrounds[i] = new ParallaxBackground(assets, tex, offset, velocity, dist, scale, anchor, repeat);
                if (dist > particles.Distance)
                    particleLayer = i;
            }
            ParallaxBackgroundSet pbs = new ParallaxBackgroundSet();
            pbs.backgrounds = backgrounds;
            pbs.camera = new Camera(camera.Dimensions, camera.Position, camera.Rotation, camera.Scale);
            pbs.color = assetDictionary.LookupColor(assetName, "color");
            pbs.particleLayer = particleLayer;
            pbs.particles = particles;
            pbs.seamstressStart = seamstressStart;

            return pbs;
        }