Jump to content

  • Log In with Google      Sign In   
  • Create Account

XNA Code Help - Animation Error


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 mistervirtue   Members   -  Reputation: 590

Like
0Likes
Like

Posted 24 April 2013 - 11:27 PM

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, 24 April 2013 - 11:28 PM.


Sponsor:

#2 moneal2001   Members   -  Reputation: 619

Like
3Likes
Like

Posted 24 April 2013 - 11:53 PM

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).



#3 Orangeatang   Members   -  Reputation: 1790

Like
1Likes
Like

Posted 25 April 2013 - 01:22 AM

I think it has to do with the override of spriteBatch.Draw that you are using.

Exactly. 

 

You want to use this version http://msdn.microsoft.com/en-us/library/ff433987.aspx


Edited by Orangeatang, 25 April 2013 - 01:23 AM.


#4 mistervirtue   Members   -  Reputation: 590

Like
0Likes
Like

Posted 25 April 2013 - 09:06 AM

Thanks! I appericate the help and explanation. You were right it was my overload that was the problem.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS