Пример #1
0
        public static Sprite GenerateSprite(LibrarySprite lib)
        {
            Sprite s = new Sprite();
            s.X = lib.X;
            s.Y = lib.Y;
            if (!string.IsNullOrEmpty(lib.TexturePath))
                s.LoadFromFile(lib.TexturePath);

            s.Animated = lib.Animated;

            if (lib.Animated)
            {
                s.FrameWidth = lib.FrameWidth;
                s.FrameHeight = lib.FrameHeight;

                foreach (Animation anim in lib.Animations)
                {
                    s.AddAnimation(anim.Copy());
                }
            }

            return s;
        }
Пример #2
0
        private static Sprite CreateSpriteFromElement(XElement el)
        {
            Sprite s = new Sprite();

            s.InstanceName = el.Element("instanceName").Value;
            s.X = int.Parse(el.Element("x").Value);
            s.Y = int.Parse(el.Element("y").Value);
            s.FrameWidth = uint.Parse(el.Element("frameWidth").Value);
            s.FrameHeight = uint.Parse(el.Element("frameHeight").Value);
            s.Animated = bool.Parse(el.Element("animated").Value);

            string path = el.Element("texturePath").Value;
            if (string.IsNullOrEmpty(path) == false)
            {
                s.LoadFromFile(path);
            }

            XElement animsEl = el.Element("animations");

            foreach (XElement animEl in animsEl.Elements())
            {
                Animation anim = new Animation();
                anim.Name = animEl.Element("name").Value;
                string playStyleStr = animEl.Element("playStyle").Value;

                anim.PlayStyle = playStyleStr == "LOOP" ? AnimationPlayStyle.LOOP : AnimationPlayStyle.ONCE;
                anim.StartFrame = uint.Parse(animEl.Element("startFrame").Value);
                anim.EndFrame = uint.Parse(animEl.Element("endFrame").Value);

                s.AddAnimation(anim);
            }

            return s;
        }