public void OnMouseEvent(MouseEvent e) { if (e.Type == EventType.Click) { GameScreen currentScreen = GameApp.GetGurrentScreen(); ScreenEntity entity = null; if (type == ObjectType.Sprite) { Sprite s; if (obj != null) s = (Sprite)obj; else s = new Sprite(); entity = s; s.InstanceName = "sprite"; currentScreen.AddSprite(s); s.ShowPropsPanel(); } else { Text t; if (obj != null) t = (Text)obj; else t = new Text(); entity = t; t.InstanceName = "text"; currentScreen.AddText(t); t.ShowPropPanel(); } entity.X = e.MouseX - entity.ClipWidth / 2; entity.Y = e.MouseY - entity.ClipHeight / 2; FocusHandler.SetFocusComponent(entity.GetFocusComponent()); ToolManager.SetCurrentTool(new InteractionTool()); } }
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; }
public void AddSprite(Sprite sprite) { sprites.Add(sprite); drawables.Add(sprite); updateables.Add(sprite); iArea.AddEntity(sprite.GetIntractionComponent()); AddChild(sprite); }
public void RemoveSprite(Sprite sprite) { sprites.Remove(sprite); drawables.Remove(sprite); updateables.Remove(sprite); iArea.RemoveEntity(sprite.GetIntractionComponent()); RemoveChild(sprite); ShowPropsPanel(); }
private static void WriteSprite(StringBuilder sb, Sprite sprite) { sb.AppendLine(sprite.InstanceName + " = AddSprite()"); sb.AppendLine(sprite.InstanceName + ":SetPosition(" + sprite.X.ToString() + "," + sprite.Y.ToString() + ")"); if (sprite.TexturePath != string.Empty) { string fileName = GetFileNameFromPath(sprite.TexturePath); string newFilePath = GetFullDir() + "\\Assets\\Textures\\" + fileName; if (File.Exists(newFilePath) == false) File.Copy(sprite.TexturePath, newFilePath); sb.AppendLine(sprite.InstanceName + ":LoadTextureFromFile('../Assets/Textures/" + fileName + "')"); } sb.AppendLine(sprite.InstanceName + ":Animated(" + sprite.Animated.ToString().ToLower() + ")"); if (sprite.Animated) { sb.AppendLine(sprite.InstanceName + ":SetFrameSize(" + sprite.FrameWidth.ToString() + "," + sprite.FrameHeight.ToString() + ")"); for (uint i = 0; i < sprite.GetNumberOfAnimations(); i++) { Animation anim = sprite.GetAnimationAt(i); string playStyle = anim.PlayStyle == AnimationPlayStyle.LOOP ? "PLAYSTYLE_LOOP" : "PLAYSTYLE_ONCE"; sb.AppendLine(sprite.InstanceName + ":AddAnimation('" + anim.Name + "'," + playStyle + "," + anim.StartFrame.ToString() + "," + anim.EndFrame.ToString() + ")"); } } }
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 XElement CreateSpriteElement(Sprite s) { XElement el = new XElement("sprite"); el.Add(new XElement("instanceName", s.InstanceName)); el.Add(new XElement("x", s.X)); el.Add(new XElement("y", s.Y)); el.Add(new XElement("texturePath", s.TexturePath)); el.Add(new XElement("frameWidth", s.FrameWidth)); el.Add(new XElement("frameHeight", s.FrameHeight)); el.Add(new XElement("animated", s.Animated)); XElement animsEl = new XElement("animations"); el.Add(animsEl); for (uint i = 0; i < s.GetNumberOfAnimations(); i++) { XElement animEl = new XElement("animation"); Animation anim = s.GetAnimationAt(i); 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; }