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);
                }
                }
            }
 public Action(string Name, Surface Surface)
 {
     this.Name = Name;
     Frames.Add(Surface);
     Width = Surface.Width;
     Height = Surface.Height;
 }
        /// <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]);
        }
Exemple #4
0
        public Surface(Surface other)
        {
            texture = other.texture;
            texture.Ref();

            width = other.width;
            height = other.height;

            Left = other.Left;
            Top = other.Top;
            Right = other.Right;
            Bottom = other.Bottom;
        }
 public SpriteData(Surface Surface, Vector offset)
 {
     Action Action = new Action("default", Surface);
     Action.Offset = offset;
     Actions.Add(Action.Name, Action);
 }
            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);
                }
                }
            }
 public SpriteData(Surface Surface)
 {
     Action Action = new Action("default", Surface);
     Actions.Add(Action.Name, Action);
 }