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 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; }