Encapsulate the logic for implementing a sprite surface capable of rendering animated sprites.
 /// <summary>
 ///  Attaches a single, unsized surface to this instance.
 ///  If sizedSurface was previously set, it is now unset.
 /// </summary>
 /// <param name="ddss">The surface to attach.</param>
 internal void AttachSurface(DirectDrawSpriteSurface ddss)
 {
     sizedSurfaces = false;
     surfaces[0] = ddss;
 }
 /// <summary>
 ///  Attaches a sized surface to this instance.  No bounds
 ///  checking is performed.  The size should be between 0 and 48.
 ///  The sizedSurfaces field is set to true.
 /// </summary>
 /// <param name="ddss">The sprite surface to attach to this instance.</param>
 /// <param name="size">The size of this sprite surface.</param>
 internal void AttachSurface(DirectDrawSpriteSurface ddss, int size)
 {
     sizedSurfaces = true;
     surfaces[size] = ddss;
 }
        /// <summary>
        ///  Adds a new sized surface to the sprite manager.  A sized surface
        ///  attempts to load multiple surfaces for the various sizes of a keyed
        ///  sprite.
        /// </summary>
        /// <param name="key">The name of the sprite surface.</param>
        /// <param name="xFrames">The number of frames of animation.</param>
        /// <param name="yFrames">The number of frame types.</param>
        internal void AddSizedSurface(string key, int xFrames, int yFrames)
        {
            if (key == null || key.Length == 0)
            {
                return;
            }

            sprites[key] = null;

            try
            {
                Int32.Parse(key);
                return;
            }
            catch
            {
            }

            TerrariumSpriteSurface tss = new TerrariumSpriteSurface();
            string[] bmps = Directory.GetFiles(GameConfig.MediaDirectory, key + "*.bmp");
            for (int i = 0; i < bmps.Length; i++)
            {
                if (!IsSourceValid(bmps[i], key))
                {
                    continue;
                }

                DirectDrawSpriteSurface dds;

                try
                {
                    dds = new DirectDrawSpriteSurface(
                        Path.GetFileNameWithoutExtension(bmps[i]),
                        bmps[i],
                        xFrames,
                        yFrames
                        );
                }
                catch
                {
                    dds = null;
                }

                if (dds != null)
                {
                    // Only if frames are between 8 and 48 pixels.
                    if (dds.FrameWidth > 7 && dds.FrameWidth < 49)
                    {
                        tss.AttachSurface(dds, dds.FrameWidth);
                        sprites[key] = tss;
                    }
                }
            }
        }