Пример #1
0
        public static Animation GenerateAnimation(string texturePath, int frameWidth, int frameHeight, int animLength, double animSpeed)
        {
            Animation _Animation = new Animation();
            Texture _Texture = GameResources.Load<Texture>(texturePath);

            int Cols = _Texture.Width / frameWidth;
            int Rows = _Texture.Height / frameHeight;

            _Animation.W = frameWidth;
            _Animation.H = frameHeight;
            _Animation.Size.Set(frameWidth, frameHeight);

            _Animation.Frames = new List<Frame>();
            _Animation.CurrentFrame = 0;
            _Animation._TotalFrames = animLength; // Cols* Rows;

            for (int j = 0; j < Rows; j++)
                for (int i = 0; i < Cols && j * Cols + i < animLength; i++)
                {
                    Frame _Frame = new Frame(texturePath, new System.Drawing.Rectangle(i * frameWidth, j * frameHeight, frameWidth, frameHeight));
                    _Frame.Offset.X = 40;
                    _Frame.Offset.Y = 30;

                    _Frame.Shape = new Rectangle(0,0,32,65);
                    _Animation.Frames.Add(_Frame);
                }

            _Animation.AnimationSpeed = animSpeed;
            return _Animation;
        }
Пример #2
0
 public void SetAnimation(int animIndex)
 {
     CurrentAnimation = AnimationSet[animIndex];
 }
Пример #3
0
 public void AddAnimation(Animation anim)
 {
     AnimationSet.Add(anim);
     if (AnimationSet.Count == 1)
     {
         CurrentAnimation = anim;
         Size.Set(CurrentFrame._BaseWidth, CurrentFrame._BaseHeight);
     }
 }