public Animation Copy() { Animation a = new Animation(); a.Name = Name; a.PlayStyle = PlayStyle; a.StartFrame = StartFrame; a.EndFrame = EndFrame; return a; }
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; }
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; }
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; }
private void OnPropPanel_AnimStop(object sender, EventArgs e) { currentAnimation = null; }
private void OnPropPanel_AnimPlay(object sender, SpritePropPanel_AnimPlayArgs e) { currentAnimation = animations[(int)e.Index]; currentFrame = 0; counter = 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; }
private void OnPropPanel_AnimDelete(object sender, SpritePropPanel_AnimDeleteArgs e) { if (animations[(int)e.Index] == currentAnimation) { currentAnimation = null; } animations.RemoveAt((int)e.Index); }
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); }
public SpritePropPanel_AnimEditArgs(Animation a, uint index) { New = a; Index = index; }
public void AddAnimation(Animation anim) { animations.Add(anim); props.AddAnimation(anim); }
public SpritePropPanel_AnimAddArgs(Animation a) { Anim = a; }
private void SetUpAnimFromDialog(AnimationEditor dialog, Animation anim) { anim.Name = dialog.AnimationName; anim.StartFrame = dialog.StartFrame; anim.EndFrame = dialog.EndFrame; anim.PlayStyle = dialog.PlayStyle; }
private string GenerateLBNameFromAnim(Animation anim) { return anim.Name + ": " + anim.StartFrame.ToString() + "-" + anim.EndFrame.ToString(); }
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)); } } }
public void AddAnimation(Animation anim) { animations.Add(anim); lbAnimations.Items.Add(GenerateLBNameFromAnim(anim)); }