Jump to content

  • Log In with Google      Sign In   
  • Create Account


#Actualmistervirtue

Posted 24 April 2013 - 11:28 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?


#1mistervirtue

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 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?


PARTNERS