public override void Initialize()
 {
     Contract.Requires <InvalidOperationException>(DiffuseMapKey != null);
     DiffuseMap = Content.Load <Texture>(DiffuseMapKey);
     if (!DiffuseMap.IsInited)
     {
         DiffuseMap.Initialize();
     }
     TextureMap.Add(TextureReference.Diffuse.ToString(), DiffuseMap);
 }
 public override void Initialize()
 {
     Contract.Requires <InvalidOperationException>(NormalMapKey != null);
     base.Initialize();
     NormalMap = Content.Load <Texture>(NormalMapKey);
     if (!NormalMap.IsInited)
     {
         NormalMap.Initialize();
     }
     TextureMap.Add(TextureReference.NormalMap.ToString(), NormalMap);
 }
Beispiel #3
0
        public static TextureMap <T> LoadTextures <T>(ContentManager content)
        {
            var loaded = new TextureMap <T>();

            foreach (var t in typeof(T).GetMembers())
            {
                var attrs = t.GetCustomAttributes(typeof(TextureAttribute), false);
                if (attrs != null && attrs.Any())
                {
                    T variant = (T)Enum.Parse(typeof(T), t.Name);
                    loaded.Add(variant, new List <Texture2D>());
                    foreach (var texture in attrs.Cast <TextureAttribute>().OrderBy(x => x.Index))
                    {
                        loaded[variant].Add(content.Load <Texture2D>(texture.ContentPath));
                    }
                }
            }
            return(loaded);
        }
Beispiel #4
0
        public ContentLoader()
        {
            var tex = Application.Content.Load <Texture2D>("BattleCityAtlas");

            TextureMap.Add(tex.Name, tex);

            string filePath = @"BattleCityAtlas.atlas";

            string[] lines;

            if (System.IO.File.Exists(filePath))
            {
                lines       = System.IO.File.ReadAllLines(filePath);
                RegionCount = (lines.Length - 6.0f) / 7.0f;

                if (RegionCount > 0) // Có ít nhất 1 rectangle trong texture.
                {
                    for (int i = 6; i < lines.Length; i += 7)
                    {
                        int    rectX, rectY, sizeX, sizeY;
                        string name = lines[i];

                        var xy   = Regex.Matches(lines[i + 2], @"\d+");
                        var size = Regex.Matches(lines[i + 3], @"\d+");

                        rectX = int.Parse(xy[0].ToString());
                        rectY = int.Parse(xy[1].ToString());

                        sizeX = int.Parse(size[0].ToString());
                        sizeY = int.Parse(size[1].ToString());

                        RectMap.Add(name, new Rectangle(rectX, rectY, sizeX, sizeY));
                    }
                }
            }
            else
            {
                Console.WriteLine("File does not exist");
            }


            Map = Application.Content.Load <TiledMap>("Battle_City");
        }