public Action(List Data, string BaseDir, SpriteData spriteData) { Properties Props = new Properties(Data); if(!Props.Get("name", ref Name)) throw new Exception("Action without name specified"); Props.Get("fps", ref Speed); Props.Get("x-offset", ref Offset.X); Props.Get("y-offset", ref Offset.Y); List<string> ImageFileNames = new List<string>(); Props.GetStringList("images", ImageFileNames); Props.PrintUnusedWarnings(); foreach(string ImageFile in ImageFileNames) { Surface surface = new Surface(BaseDir + "/" + ImageFile); Width = Math.Max(Width, surface.Width); Height = Math.Max(Height, surface.Height); Frames.Add(surface); } string MirrorActionName = null; Props.Get("mirror-action", ref MirrorActionName); if(MirrorActionName != null) { Action MirrorAction = spriteData.Actions[MirrorActionName]; foreach(Surface surface in MirrorAction.Frames) { Surface flippedSurface = new Surface(surface); flippedSurface.Left = surface.Right; flippedSurface.Right = surface.Left; Width = Math.Max(Width, surface.Width); Height = Math.Max(Height, surface.Height); Frames.Add(flippedSurface); } } }
internal Sprite(SpriteData Data) { this.Data = Data; CurrentAction = null; if(Data.Actions.Count > 0) { IEnumerator<KeyValuePair<string, SpriteData.Action>> enumerator = Data.Actions.GetEnumerator(); enumerator.MoveNext(); CurrentAction = enumerator.Current.Value; } }
/// <summary> /// Creates a sprite from an image file. /// </summary> /// <remarks> /// If a sprite from the same image was already loaded /// before it will return a new sprite from the SpriteData /// in the cache. /// </remarks> /// <param name="ImageFile">The image file to create the sprite from</param> /// <param name="offset">Offset, same as <see cref="Sprite.Offset"/>.</param> /// <returns>A <see cref="Sprite"/>.</returns> public static Sprite CreateFromImage(string ImageFile, Vector offset) { if(!SpriteDatas.ContainsKey(ImageFile)) { Surface Surface = new Surface(ImageFile); SpriteData Data = new SpriteData(Surface, offset); SpriteDatas[ImageFile] = Data; return new Sprite(Data); } return new Sprite(SpriteDatas[ImageFile]); }
public Action(List Data, string BaseDir, SpriteData spriteData) { Properties Props = new Properties(Data); if(!Props.Get("name", ref Name)) throw new Exception("Action without name specified"); Props.Get("fps", ref Speed); if(Props.Exists("hitbox")) { List<float> hitbox = new List<float>(); Props.GetFloatList("hitbox", hitbox); if (hitbox.Count != 4) throw new Exception("hitbox must specify exactly 4 coordinates"); Hitbox = new RectangleF(hitbox[0], hitbox[1], hitbox[2], hitbox[3]); Offset.X = Hitbox.Left; Offset.Y = Hitbox.Top; } List<string> ImageFileNames = new List<string>(); Props.GetStringList("images", ImageFileNames); Props.PrintUnusedWarnings(); foreach(string ImageFile in ImageFileNames) { Surface surface = new Surface(BaseDir + "/" + ImageFile); Width = Math.Max(Width, surface.Width); Height = Math.Max(Height, surface.Height); Frames.Add(surface); } string MirrorActionName = null; Props.Get("mirror-action", ref MirrorActionName); if(MirrorActionName != null) { Action MirrorAction = spriteData.Actions[MirrorActionName]; foreach(Surface surface in MirrorAction.Frames) { Surface flippedSurface = new Surface(surface); flippedSurface.Left = surface.Right; flippedSurface.Right = surface.Left; Width = Math.Max(Width, surface.Width); Height = Math.Max(Height, surface.Height); Frames.Add(flippedSurface); } } }