Beispiel #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;
        }
Beispiel #2
0
 public void AddLibrarySprite(LibrarySprite lSprite)
 {
     lSprites.Add(lSprite);
     props.AddLibrarySprite(lSprite.Name);
 }
Beispiel #3
0
        public void RemoveLibrarySprite(LibrarySprite lSprite)
        {
            int index = lSprites.IndexOf(lSprite);
            lSprites.Remove(lSprite);

            props.RemoveLibrarySprite(index);
        }
Beispiel #4
0
        private static void WriteLSprite(StringBuilder sb, LibrarySprite lSprite, uint index)
        {
            string inst = "autoGenLs" + index.ToString();

            sb.AppendLine("local " + inst + " = AddLibrarySprite('" + lSprite.Name + "')");
            sb.AppendLine(inst + ":SetPosition(" + lSprite.X.ToString() + "," + lSprite.Y.ToString() + ")");

            string fileName = GetFileNameFromPath(lSprite.TexturePath);
            string newFilePath = GetFullDir() + "\\Assets\\Textures\\" + fileName;
            if (File.Exists(newFilePath) == false)
                File.Copy(lSprite.TexturePath, newFilePath);

            sb.AppendLine(inst + ":SetTexturePath('../Assets/Textures/" + fileName + "')");
            sb.AppendLine(inst + ":Animated(" + lSprite.Animated.ToString().ToLower() + ")");

            if (lSprite.Animated)
            {
                sb.AppendLine(inst + ":SetFrameSize(" + lSprite.FrameWidth + "," + lSprite.FrameHeight + ")");

                foreach (Animation anim in lSprite.Animations)
                {
                    string playStyle = anim.PlayStyle == AnimationPlayStyle.LOOP ? "PLAYSTYLE_LOOP" : "PLAYSTYLE_ONCE";
                    sb.AppendLine(inst + ":AddAnimation('" + anim.Name + "'," + playStyle + "," + anim.StartFrame.ToString() + "," + anim.EndFrame.ToString() + ")");
                }
            }
        }
Beispiel #5
0
        private static LibrarySprite CreateLSpriteFromElement(XElement el)
        {
            LibrarySprite s = new LibrarySprite();
            s.Name = el.Element("name").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);

            s.TexturePath = el.Element("texturePath").Value;

            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.Animations.Add(anim);
            }

            return s;
        }
Beispiel #6
0
        private static XElement CreateLSpriteElement(LibrarySprite ls)
        {
            XElement el = new XElement("lSprite");
            el.Add(new XElement("name", ls.Name));
            el.Add(new XElement("texturePath", ls.TexturePath));
            el.Add(new XElement("frameWidth", ls.FrameWidth));
            el.Add(new XElement("frameHeight", ls.FrameHeight));
            el.Add(new XElement("animated", ls.Animated));

            XElement animsEl = new XElement("animations");
            el.Add(animsEl);

            foreach (Animation anim in ls.Animations)
            {
                XElement animEl = new XElement("animation");

                animEl.Add(new XElement("name", anim.Name));
                animEl.Add(new XElement("playStyle", anim.PlayStyle.ToString()));
                animEl.Add(new XElement("startFrame", anim.StartFrame));
                animEl.Add(new XElement("endFrame", anim.EndFrame));

                animsEl.Add(animEl);

            }
            return el;
        }
Beispiel #7
0
        public LibrarySprite GenerateLibSprite()
        {
            LibrarySprite lib = new LibrarySprite();
            lib.X = X;
            lib.Y = Y;
            lib.TexturePath = srcImagePath;
            lib.Animated = animated;

            if (animated)
            {
                lib.FrameHeight = FrameHeight;
                lib.FrameWidth = FrameHeight;

                foreach(Animation anim in animations)
                {
                    lib.Animations.Add(anim.Copy());
                }
            }
            return lib;
        }