Example #1
0
        public static AnimationCollection Load(string path)
        {
            List<Frame> frames = new List<Frame>();
            List<Animation> animations = new List<Animation>();

            using(StreamReader r = new StreamReader(path))
            {
                // frames
                int frameCount = int.Parse(r.ReadLine());
                for (int i = 0; i < frameCount; i++)
                {
                    string fName = r.ReadLine();
                    List<FramePart> fps = new List<FramePart>();
                    int fpCount = int.Parse(r.ReadLine());
                    for (int j = 0; j < fpCount; j++)
                    {
                        string[] pos = r.ReadLine().Split(',');
                        Vector2 position = new Vector2(float.Parse(pos[0], CultureInfo.InvariantCulture), float.Parse(pos[1], CultureInfo.InvariantCulture));
                        string[] src = r.ReadLine().Split(',');
                        Rectangle source = new Rectangle(int.Parse(src[0]), int.Parse(src[1]), int.Parse(src[2]),int.Parse(src[3]));
                        float rotation = float.Parse(r.ReadLine(), CultureInfo.InvariantCulture);
                        float scale = float.Parse(r.ReadLine(), CultureInfo.InvariantCulture);
                        fps.Add(new FramePart(position, rotation, scale) { Source = source });
                    }

                    Frame f = new Frame(null, fps) { Name = fName };
                    frames.Add(f);
                }

                int animCount = int.Parse(r.ReadLine());
                for (int i = 0; i < animCount; i++)
                {
                    string animName = r.ReadLine();
                    List<KeyFrame> keyFrames = new List<KeyFrame>();
                    int kfCount = int.Parse(r.ReadLine());
                    for (int j = 0; j < kfCount; j++)
                    {
                        float duration = float.Parse(r.ReadLine(), CultureInfo.InvariantCulture);
                        int fIndex = int.Parse(r.ReadLine());
                        string[] scripts = new string[int.Parse(r.ReadLine())];
                        for (int x = 0; x < scripts.Length; x++)
                        {
                            scripts[x] = r.ReadLine();
                        }
                        List<KeyFrameScript> s = new List<KeyFrameScript>();
                        KeyFrame kf = new KeyFrame(frames[fIndex], duration, scripts);
                        keyFrames.Add(kf);
                    }

                    Animation a = new Animation(keyFrames) { Name = animName };
                    animations.Add(a);
                }

                AnimationCollection collection = new AnimationCollection(frames, animations);
                return collection;
            }
        }
Example #2
0
 public void DrawLerped(SpriteBatch sb, Vector2 position, KeyFrame nextFrame, bool flipped)
 {
     frameRef.DrawLerped(sb, position, nextFrame.frameRef, current / duration, flipped);
 }
Example #3
0
 void kfList_OnClickedEvent(KeyFrame item)
 {
     // select keyframe
     kfContainer.SetKeyFrame(item);
 }