public JSONSpriteSheet Serialize() { var ss = new JSONSpriteSheet(); ss.Name = Name; ss.Sprites = Sprites.Select( a => new JSONSpriteSheet.JSONSprite() { Name = a.Name, X = (int)a.Rectangle.X, Y = (int)a.Rectangle.Y, Width = (int)a.Rectangle.Width, Height = (int)a.Rectangle.Height }).ToArray(); ss.Animations = Animations.Select( a => new JSONSpriteSheet.JSONAnimation() { FrameRate = a.FrameRate, Name = a.Name, Frames = a.Sprites.Select(b => b.Name).ToArray() }).ToArray(); return(ss); }
public static RuntimeSpriteSheet Load(JSONSpriteSheet sheet) { var ss = new RuntimeSpriteSheet(); foreach (var sprite in sheet.Sprites) { ss.Sprites.Add(new RuntimeSprite(ss) { Name = sprite.Name, Rectangle = new Rect(sprite.X, sprite.Y, sprite.Width, sprite.Height) }); } foreach (var anim in sheet.Animations) { ss.Animations.Add(new RuntimeAnimation(ss) { FrameRate = anim.FrameRate, Name = anim.Name, Sprites = anim.Frames.Select(a => ss.Sprites.First(b => b.Name == a)).ToList() }); } return(ss); }
public static RuntimeSpriteSheet Load(string JSON) => Load(JSONSpriteSheet.Load(JSON));