示例#1
0
        public Animation Copy()
        {
            Animation a = new Animation();
            a.Name = Name;
            a.PlayStyle = PlayStyle;
            a.StartFrame = StartFrame;
            a.EndFrame = EndFrame;

            return a;
        }
示例#2
0
        public Sprite()
        {
            animated = false;
            srcImagePath = string.Empty;
            frameWidth = frameHeight = 30;
            srcRect.left = srcRect.top = 0;
            srcRect.right = (int)frameWidth;
            srcRect.bottom = (int)frameHeight;
            animations = new List<Animation>();
            currentAnimation = null;
            currentFrame = 0;

            Rotation = 0;

            texture = null;

            currentColor = Color.Green;

            props = new SpritePropPanel();

            props.FrameWidth = frameWidth;
            props.FrameHeight = frameHeight;

            props.OnPropChange += PropPanel_OnChange;

            OnXChange += OnInternalPropChange;
            OnYChange += OnInternalPropChange;

            props.OnAnimAdd += OnPropPanel_AnimAdd;
            props.OnAnimPlay += OnPropPanel_AnimPlay;
            props.OnAnimStop += OnPropPanel_AnimStop;
            props.OnAnimEdit += OnPropPanel_AnimEdit;
            props.OnAnimDelete += OnPropPanel_AnimDelete;

            AddMenuItem("Delete");
            AddMenuItem("Add to library");
            OnMenuItemSelect += OnMenuItemSel;

            OnInstanceNameChange += OnInstanceNameCh;
        }
示例#3
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;
        }
示例#4
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;
        }
示例#5
0
 private void OnPropPanel_AnimStop(object sender, EventArgs e)
 {
     currentAnimation = null;
 }
示例#6
0
 private void OnPropPanel_AnimPlay(object sender, SpritePropPanel_AnimPlayArgs e)
 {
     currentAnimation = animations[(int)e.Index];
     currentFrame = 0;
     counter = 0;
 }
示例#7
0
        private void OnPropPanel_AnimEdit(object sender, SpritePropPanel_AnimEditArgs e)
        {
            if (animations[(int)e.Index] == currentAnimation)
            {
                currentAnimation = null;
            }

            Animation anim = animations[(int)e.Index];
            anim.Name = e.New.Name;
            anim.PlayStyle = e.New.PlayStyle;
            anim.StartFrame = e.New.StartFrame;
            anim.EndFrame = e.New.EndFrame;
        }
示例#8
0
        private void OnPropPanel_AnimDelete(object sender, SpritePropPanel_AnimDeleteArgs e)
        {
            if (animations[(int)e.Index] == currentAnimation)
            {
                currentAnimation = null;
            }

            animations.RemoveAt((int)e.Index);
        }
示例#9
0
        private void OnPropPanel_AnimAdd(object sender, SpritePropPanel_AnimAddArgs e)
        {
            Animation a = new Animation();
            a.Name = e.Anim.Name;
            a.PlayStyle = e.Anim.PlayStyle;
            a.StartFrame = e.Anim.StartFrame;
            a.EndFrame = e.Anim.EndFrame;

            animations.Add(a);
        }
示例#10
0
 public SpritePropPanel_AnimEditArgs(Animation a, uint index)
 {
     New = a;
     Index = index;
 }
示例#11
0
 public void AddAnimation(Animation anim)
 {
     animations.Add(anim);
     props.AddAnimation(anim);
 }
示例#12
0
 public SpritePropPanel_AnimAddArgs(Animation a)
 {
     Anim = a;
 }
示例#13
0
 private void SetUpAnimFromDialog(AnimationEditor dialog, Animation anim)
 {
     anim.Name = dialog.AnimationName;
     anim.StartFrame = dialog.StartFrame;
     anim.EndFrame = dialog.EndFrame;
     anim.PlayStyle = dialog.PlayStyle;
 }
示例#14
0
 private string GenerateLBNameFromAnim(Animation anim)
 {
     return anim.Name + ": " + anim.StartFrame.ToString() + "-" + anim.EndFrame.ToString();
 }
示例#15
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            AnimationEditor dialog = new AnimationEditor();
            DialogResult res = dialog.ShowDialog();

            if (res == DialogResult.OK)
            {
                Animation anim = new Animation();

                SetUpAnimFromDialog(dialog, anim);

                AddAnimation(anim);

                if (OnAnimAdd != null)
                {
                    OnAnimAdd(this, new SpritePropPanel_AnimAddArgs(anim));
                }

            }
        }
示例#16
0
 public void AddAnimation(Animation anim)
 {
     animations.Add(anim);
     lbAnimations.Items.Add(GenerateLBNameFromAnim(anim));
 }