Пример #1
0
        /// <summary>
        /// Add an animation to a sprite.
        /// </summary>
        /// <param name="name">Animation name.</param>
        /// <param name="indexes">Array of index</param>
        /// <param name="frameRate">Desired framerate</param>
        /// <param name="reversed">Sets to true for a reversed animation.</param>
        public void Add(string name, int[] indexes, int frameRate, bool reversed)
        {
            int animationLength = indexes.Length;

            SpriteAnimation animation = new SpriteAnimation(animationLength, frameRate, reversed);

            for (int i = 0; i < animationLength; i++)
            {
                int x = indexes[i] % _nbSpriteX;
                int y = (int)Math.Floor((double)(indexes[i] / _nbSpriteX));

                // Adapt the X value 
                // Ex: For Y = 2, we must have X in range [0... sizeX]
                if (y > 0)
                    x = x % (_nbSpriteX * y);
                else
                    x = x % _nbSpriteX;

                // The source rectangle for the sprite
                animation.Rectangle[i] = new Rectangle(x * _spriteWidth, y * _spriteHeight, _spriteWidth, _spriteHeight);
            }

            _animations.Add(name, animation);
        }
Пример #2
0
 /// <summary>
 /// Add a new animation.
 /// </summary>
 /// <param name="name">Animation name</param>
 /// <param name="rectangles">Rectangles that compose the animation</param>
 /// <param name="frameRate">The framerate</param>
 /// <param name="reversed">Sets to true to reverse image</param>
 public void Add(string name, Rectangle[] rectangles, int frameRate, bool reversed)
 {
     int animationLength = rectangles.Length;
     SpriteAnimation animation = new SpriteAnimation(animationLength, frameRate, reversed);
     animation.Rectangle = rectangles;
     _animations.Add(name, animation);
 }