Пример #1
0
 public Animation2D(Texture2D[] textures, Animation2D parent) :
     this(textures, parent.IsLooped, parent.Name, parent.Duration)
 {
     parent.FrameChanged += (i) =>
     {
         index = i;
     };
 }
Пример #2
0
 public void Play(string name)
 {
     current = GetByName(name);
     if (current == null)
     {
         GameConsole.Error("No animation named " + name);
     }
     current.Reset();
     AnimationChanged?.Invoke(name);
 }
Пример #3
0
        public static Animation2D Load(XmlReader xr, Texture2D texture, int tilesize, int spacing)
        {
            xr.Read();
            int         length = int.Parse(xr["length"]);
            Animation2D result = new Animation2D(texture, length);

            result.Name     = xr["name"];
            result.Duration = float.Parse(xr["duration"]);
            result.IsLooped = bool.Parse(xr["looped"]);
            int j = int.Parse(xr["index"]);

            for (int i = 0; i < length; i++)
            {
                result.sources[i] = new Rectangle(i * (tilesize + spacing), j * (tilesize + spacing), tilesize, tilesize);
            }

            return(result);
        }
Пример #4
0
        public static Animation2D[] Load(string file, GraphicsDevice graphicsDevice)
        {
            List <Animation2D> result = new List <Animation2D>();
            int       tilesize        = -1;
            int       spacing         = 0;
            Texture2D source          = null;

            using (XmlReader xr = XmlReader.Create(file))
            {
                while (xr.Read())
                {
                    if (xr.NodeType != XmlNodeType.Element)
                    {
                        continue;
                    }
                    switch (xr.Name)
                    {
                    case "animations":
                        tilesize = int.Parse(xr["tilewidth"]);                                 //Should be same as tileheight
                        if (!string.IsNullOrWhiteSpace(xr["spacing"]))
                        {
                            spacing = int.Parse(xr["spacing"]);
                        }
                        string imagePath = Path.Combine(Path.GetDirectoryName(file), xr["source"]);
                        using (FileStream fs = new FileStream(imagePath, FileMode.Open))
                            source = Texture2D.FromStream(graphicsDevice, fs);
                        break;

                    case "animation":
                        using (StringReader sr = new StringReader(xr.ReadOuterXml()))
                            using (XmlReader r = XmlReader.Create(sr))
                                result.Add(Animation2D.Load(r, source, tilesize, spacing));
                        break;

                    default:
                        throw new NotSupportedException("Unknown Type " + xr.Name);
                    }
                }
            }
            return(result.ToArray());
        }
Пример #5
0
 public void AddAnimation(Animation2D animation)
 {
     animations.Add(animation);
     Play(StartAnimation);
 }