Пример #1
0
        public static Atlas Load(string atlasResource, string contentManagerName)
        {
            var contentManager = FlatRedBall.FlatRedBallServices.GetContentManagerByName(contentManagerName);
            // See if this thing is already loaded:
            bool isAlreadyLoaded = contentManager.IsAssetLoadedByName<Atlas>(atlasResource);

            if (isAlreadyLoaded)
            {
                return contentManager.GetDisposable<Atlas>(atlasResource);
            }
            else
            {
                string absoluteFileName = FileManager.MakeAbsolute(atlasResource);


                var directory = FileManager.GetDirectory(atlasResource, RelativeType.Relative);

                var texture = contentManager.Load<Microsoft.Xna.Framework.Graphics.Texture2D>(Path.ChangeExtension(atlasResource, "png"));
                
                var dataFileLines = ReadDataFile(atlasResource);

                var atlas = new Atlas();

                foreach(var cols in dataFileLines
                    .Where(item=>!string.IsNullOrWhiteSpace(item) && !item.StartsWith("#"))
                    .Select(item=>item.Split(';'))
                    )
                {
                    if (cols.Length != 10)
                    {
                        throw new InvalidDataException("Incorrect format data in spritesheet data file");
                    }

                    var isRotated = int.Parse(cols[1]) == 1;
                    var slashIndex = cols[0].IndexOf("/");
                    var name = cols[0].Substring(slashIndex + 1).ToLower();

                    var sourceRectangle = new Microsoft.Xna.Framework.Rectangle(
                        int.Parse(cols[2]),
                        int.Parse(cols[3]),
                        int.Parse(cols[4]),
                        int.Parse(cols[5]));
                    var size = new Microsoft.Xna.Framework.Vector2(
                        int.Parse(cols[6]),
                        int.Parse(cols[7]));
                    var pivotPoint = new Microsoft.Xna.Framework.Vector2(
                        float.Parse(cols[8]),
                        float.Parse(cols[9]));
                    var sprite = new AtlasedTexture(name, texture, sourceRectangle, size, pivotPoint, isRotated);

                    atlas.Add(name, sprite);
                }

                contentManager.AddDisposable(atlasResource, atlas);

                loadedAtlases.Add(atlas);

                return atlas;
            }
        }
Пример #2
0
        public static Atlas Load(string atlasResource, string contentManagerName)
        {
            var contentManager = FlatRedBall.FlatRedBallServices.GetContentManagerByName(contentManagerName);
            // See if this thing is already loaded:
            bool isAlreadyLoaded = contentManager.IsAssetLoadedByName <Atlas>(atlasResource);

            if (isAlreadyLoaded)
            {
                return(contentManager.GetDisposable <Atlas>(atlasResource));
            }
            else
            {
                string absoluteFileName = FileManager.MakeAbsolute(atlasResource);


                var directory = FileManager.GetDirectory(atlasResource, RelativeType.Relative);

                var texture = contentManager.Load <Microsoft.Xna.Framework.Graphics.Texture2D>(Path.ChangeExtension(atlasResource, "png"));

                var dataFileLines = ReadDataFile(atlasResource);

                var atlas = new Atlas();

                foreach (var cols in dataFileLines
                         .Where(item => !string.IsNullOrWhiteSpace(item) && !item.StartsWith("#"))
                         .Select(item => item.Split(';'))
                         )
                {
                    if (cols.Length != 10)
                    {
                        throw new InvalidDataException("Incorrect format data in spritesheet data file");
                    }

                    var isRotated  = int.Parse(cols[1]) == 1;
                    var slashIndex = cols[0].IndexOf("/");
                    var name       = cols[0].Substring(slashIndex + 1).ToLower();

                    var sourceRectangle = new Microsoft.Xna.Framework.Rectangle(
                        int.Parse(cols[2]),
                        int.Parse(cols[3]),
                        int.Parse(cols[4]),
                        int.Parse(cols[5]));
                    var size = new Microsoft.Xna.Framework.Vector2(
                        int.Parse(cols[6]),
                        int.Parse(cols[7]));
                    var pivotPoint = new Microsoft.Xna.Framework.Vector2(
                        float.Parse(cols[8]),
                        float.Parse(cols[9]));
                    var sprite = new AtlasedTexture(name, texture, sourceRectangle, size, pivotPoint, isRotated);

                    atlas.Add(name, sprite);
                }

                contentManager.AddDisposable(atlasResource, atlas);

                loadedAtlases.Add(atlas);

                return(atlas);
            }
        }
Пример #3
0
 public void Add(string name, AtlasedTexture sprite)
 {
     spriteList.Add(name, sprite);
 }
Пример #4
0
 public void Add(string name, AtlasedTexture sprite)
 {
     spriteList.Add(name, sprite);
 }