コード例 #1
0
        /// <summary>
        ///  Add a single size surface.
        /// </summary>
        /// <param name="key">The key 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 Add(string key, int xFrames, int yFrames)
        {
            if (string.IsNullOrEmpty(key))
            {
                return;
            }

            Sprites[key] = null;

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

            var basepath = GameConfig.MediaDirectory + "\\" + key;
            var bmppath  = basepath + ".bmp";

            if (File.Exists(bmppath))
            {
                var tss = new TerrariumSpriteSurface();
                tss.AttachSurface(new DirectDrawSpriteSurface(key, bmppath, xFrames, yFrames));
                Sprites[key] = tss;
            }
        }
コード例 #2
0
        /// <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 (string.IsNullOrEmpty(key))
            {
                return;
            }

            Sprites[key] = null;

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

            var tss  = new TerrariumSpriteSurface();
            var bmps = Directory.GetFiles(GameConfig.MediaDirectory, key + "*.bmp");

            for (var 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;
                    }
                }
            }
        }
コード例 #3
0
        /// <summary>
        ///  Add a single size surface.
        /// </summary>
        /// <param name="key">The key 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 Add(string key, int xFrames, int yFrames)
        {
            if (key == null || key.Length == 0)
            {
                return;
            }

            sprites[key] = null;

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

            string basepath = GameConfig.MediaDirectory + "\\" + key;
            string bmppath = basepath + ".bmp";
            if (File.Exists(bmppath))
            {
                TerrariumSpriteSurface tss = new TerrariumSpriteSurface();
                tss.AttachSurface(new DirectDrawSpriteSurface(key, bmppath, xFrames, yFrames));
                sprites[key] = tss;
            }
        }
コード例 #4
0
        /// <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;
                    }
                }
            }
        }
コード例 #5
0
        /// <summary>
        ///  Add a single size surface.
        /// </summary>
        /// <param name="key">The key 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 Add(string key, int xFrames, int yFrames)
        {
            if (string.IsNullOrEmpty(key))
            {
                return;
            }

            Sprites[key] = null;

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

            var basepath = GameConfig.MediaDirectory + "\\" + key;
            var bmppath = basepath + ".bmp";
            if (File.Exists(bmppath))
            {
                var tss = new TerrariumSpriteSurface();
                tss.AttachSurface(new DirectDrawSpriteSurface(key, bmppath, xFrames, yFrames));
                Sprites[key] = tss;
            }
        }