i need a little help here plz

Oct 20, 2011 at 1:32 PM

I wish someone please help me I wish someone please help me with something very simple,yeah its veeery simple i know :p but the more I try to find a way i just cant.

I can not find a way to make my animated class scroll lines besides only columns, someone who understands this please tell me a way to put in the class constructor...

thanks anyway!!!

 public class AnimationStrip
    {
      
        public Texture2D texture;
        private int frameWidth;
        private int frameHeight;
        public bool update = true;
        private float frameTimer = 0f;
        public float frameDelay = 0.05f;

        public int currentFrame;

        private bool loopAnimation = true;
        public bool finishedPlaying = false;

        private string name;
        private string nextAnimation;
     
      
        #region Properties
        public int FrameWidth
        {
            get { return frameWidth; }
            set { frameWidth = value; }
        }

        public int FrameHeight
        {
            get { return frameHeight; }
            set { frameHeight = value; }
        }

        public Texture2D Texture
        {
            
            get { return texture; }
            set { texture = value; }
        }

        public string Name
        {
            get { return name; }
            set { name = value; }
        }

        public string NextAnimation
        {
            get { return nextAnimation; }
            set { nextAnimation = value; }
        }

        public bool LoopAnimation
        {
            get { return loopAnimation; }
            set { loopAnimation = value; }
        }

        public bool FinishedPlaying
        {
            get { return finishedPlaying; }
        }

        public int FrameCount
        {
            get { return texture.Width / frameWidth; }
        }

        public float FrameLength
        {
            get { return frameDelay; }
            set { frameDelay = value; }
        }

        public Rectangle FrameRectangle
        {
            get
            {
                return new Rectangle(
                    currentFrame * frameWidth,
                   0,
                    frameWidth,
                    frameHeight);
            }
        }

        public AnimationStrip(Texture2D texture, int frameWidth, string name)
        {
            this.texture = texture;
            this.frameWidth = frameWidth;
            this.frameHeight = texture.Height;
            this.name = name;
        }
        

      
        public void Play()
        {
            currentFrame = 0;
            finishedPlaying = false;
        }

        public void Update(GameTime gameTime)
        {
            if (update)
            {
                float elapsed = (float)gameTime.ElapsedGameTime.TotalSeconds;

                frameTimer += elapsed;

                if (frameTimer >= frameDelay)
                {
                    currentFrame++;
                    if (currentFrame >= FrameCount)
                    {
                        if (loopAnimation)
                        {
                            currentFrame = 0;
                        }
                        else
                        {
                            currentFrame = FrameCount - 1;
                            finishedPlaying = true;
                        }
                    }

                    frameTimer = 0f;
                    textura = texture;
                }
            }
        }
       

    }
}

 


Oct 20, 2011 at 1:51 PM
Edited Oct 20, 2011 at 1:52 PM

In your frame rect...

 

public Rectangle FrameRectangle
        {
            get
            {
                return new Rectangle(
                    currentFrame * frameWidth,
                   0,
                    frameWidth,
                    frameHeight);
            }
        }

The first two parameters determine what region of the texture gets clipped to draw. Your Y parameter is zero, which is fine for a single strip of frames. If you want a two-dimensional grid, say line 0 is facing north, 1 is the sprite facing south, 2 is east, and so on, you need to use the Y parameter to clip the appropriate line of sprites. In your code, Y Zero is the first row, and the second row would be 0 + frameHeight. You need a row index to determine which animation is being used.

 

Assuming your sprite sheet looks like this:

N1 N2 N3 N4
S1 S2 S3 S4

...you'll use some variant of the following

 

//Determine which row has the current animation to draw
public void FaceNorth() 
{ rowIndex = 0; }
public void FaceSouth()
{ rowIndex = 1 }
//and so on...
public
Rectangle FrameRectangle
{
get
{
return
new Rectangle(
currentFrame * frameWidth,
rowIndex * frameHeight, //This determines the row being drawn
frameWidth,
frameHeight);
}
}