public AnimationSet makeAnimationSet()
        {
            AnimationSet animSet = new AnimationSet();
            List<Animation> animations = new List<Animation>();

            List<SpriteBox> sbs = new List<SpriteBox>(SpriteBoxes.ToArray());

            while (sbs.Count > 0)
            {
                Animation a = new Animation();
                List<Sprite> sprites = new List<Sprite>();
                animations.Add(a);

                Color c = sbs[0].Color;
                List<SpriteBox> matches = sbs.FindAll(i => i.Color == c);
                sbs.RemoveAll(i => i.Color == c);

                foreach (SpriteBox box in matches)
                {
                    sprites.Add(box.Sprite);
                }
                a.sprites = sprites.ToArray();
            }

            animSet.anims = animations.ToArray();

            return animSet;
        }
 public AnimationSet()
 {
     anims = new Animation[0];
 }
        public void addSpriteBox(SpriteBox spriteBox)
        {
            SpriteBoxes.Add(spriteBox);

            // if AnimationSet exists, make sure to update it

            // known Animation, so update it
            if (colorLookup.ContainsKey(spriteBox.Color))
            {
                int animIdx = colorLookup[spriteBox.Color];
                List<SpriteBox> lst = sbLookup[spriteBox.Color];

                lst.Add(spriteBox);

                List<Sprite> sprites = new List<Sprite>();
                foreach (SpriteBox sb in lst)
                {
                    sprites.Add(sb.Sprite);
                }
                m_animationSet.anims[animIdx].sprites = sprites.ToArray();
            }

            // unknown Animation, create it
            else if (m_animationSet != null)
            {
                Animation a = new Animation();

                colorLookup.Add(spriteBox.Color, m_animationSet.anims.Length);

                List<SpriteBox> lst = new List<SpriteBox>();
                lst.Add(spriteBox);
                sbLookup.Add(spriteBox.Color, lst);

                a.sprites = new Sprite[1];
                a.sprites[0] = spriteBox.Sprite;

                List<Animation> anims = new List<Animation>(m_animationSet.anims);
                anims.Add(a);
                m_animationSet.anims = anims.ToArray();
            }
            Refresh();
        }