• Advertisement
Sign in to follow this  

XNA Code Help - Animation Error

This topic is 1731 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a animation error.

 

I have a spritesheet(400*215px) and it contains two frames. One frame (198*215) with a characters eyes open and one frame with the charaters eyes closed. My problem is whenever I attempt to animate this sheet, my code makes the whole sheet appear. Could I please get some help?

---------------------------------------------------------------

Global Variables

Point frameSize = new Point(198, 215); // The Size of an Indivsual Frame
Point currentFrame = new Point (0,0); // Start in the first in the squence
Point sheetSize = new Point(2,1); // Number of Rows and Columns of the Sprite Sheet

----------------------------------------------------------------

Update()

timeSinceLastFrame += gameTime.ElapsedGameTime.Milliseconds;
            if (timeSinceLastFrame > millisecondsPerFrame)
            {
                //Animate the Knight
                timeSinceLastFrame -= millisecondsPerFrame;
                ++currentFrame.X;
                if (currentFrame.X >= sheetSize.X)
                {
                    currentFrame.X = 0;
                    ++currentFrame.Y;
                    if (currentFrame.Y >= sheetSize.Y)
                    {
                        currentFrame.Y = 0;
                    }
                }

--------------------------------------------------------

Draw()

  spriteBatch.Draw(texture,
                 new Rectangle ((currentFrame.X * frameSize.X), (currentFrame.Y*frameSize.Y),
                    frameSize.X, frameSize.Y),Color.White);

----------------------------------------------------------

 

I am not sure what my problem is. I think it lies in the use of the point structs because it is drawing the whole texture file. But then again it could be in the draw but it seems pretty straight forward. Could I get some help?

Edited by mistervirtue

Share this post


Link to post
Share on other sites
Advertisement

I think it has to do with the override of spriteBatch.Draw that you are using.  yours only seems to take into account where you are drawing the texture

 

you need to use the override that includes the source rectangle(the frame on your spritesheet) as well as the destination rectangle(where the texture is being drawn).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement