Ejemplo n.º 1
0
            public Sequence(XNode node)
            {
                XNodeAttributes attr = new XNodeAttributes(node);

                Name = attr.AsString("Name");
                Fps  = attr.AsInt32("Fps", 1);
                Loop = attr.AsBoolean("Loop", false);

                string sequence = attr.AsString("ImageSequence");
                int    start    = attr.AsInt32("Start", 0);
                int    end      = attr.AsInt32("End", 0);

                List <PartialTexture2D> list = new List <PartialTexture2D>();

                for (int idx = start; idx <= end; ++idx)
                {
                    PartialTexture2D texture = ContentLoader.Current.Load <PartialTexture2D>(sequence.Replace("*", idx.ToString()));

                    if (idx > start)
                    {
                        if (texture.Width != list[0].Width || texture.Height != list[0].Height)
                        {
                            throw new InvalidDataException("Sprite must have same size frames.");
                        }
                    }

                    list.Add(texture);
                }

                Images = list.AsReadOnly();
            }
Ejemplo n.º 2
0
        public static void LoadTextureAtlas(string path)
        {
            Texture2D texture = ContentLoader.Current.Load <Texture2D>(path);

            Type type = typeof(PartialTexture2D);

            using (Stream stream = ContentLoader.Current.Open(path + ".ta"))
            {
                using (BinaryReader reader = new BinaryReader(stream))
                {
                    int count = reader.ReadInt32();

                    while (count > 0)
                    {
                        string    id   = reader.ReadString();
                        Rectangle rect = new Rectangle();

                        rect.X      = reader.ReadInt32();
                        rect.Y      = reader.ReadInt32();
                        rect.Width  = reader.ReadInt32();
                        rect.Height = reader.ReadInt32();

                        PartialTexture2D mapped = new PartialTexture2D(texture, rect);
                        ContentLoader.Current.AddContent(id, type, mapped);

                        count--;
                    }
                }
            }
        }