Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Sprite Sheet Animation problem  (Read 2531 times)

0 Members and 1 Guest are viewing this topic.

rojan_neo

  • Newbie
  • *
  • Posts: 28
    • View Profile
    • http://makeagame.tumblr.com
Sprite Sheet Animation problem
« on: August 16, 2011, 03:56:02 am »
I am trying to get a spritesheet animation for walking a player..
Basically what I did is get an IntRect withing a sprite image and move the IntRect to the next frame of sprite along with the actual movement of sprite on the screen.. but now the animation plays really fast.. how can i slow down the animation.
Here is what i did:

Quote
if(RIGHT key is pressed)
{
  move the IntRect to the next frame;
  move the sprite;
}

Disch

  • Full Member
  • ***
  • Posts: 220
    • View Profile
Sprite Sheet Animation problem
« Reply #1 on: August 16, 2011, 04:59:21 am »
You need to watch how much time has passed and only advance frames accordingly.  Something like this:

Code: [Select]

void Animation::Update(int ms)
{
  // this function would be called every update (every "frame")
  //  ms is the number of milliseconds passed since the last
  //  frame
  time_remaining -= ms;  // subtract the time passed from the
         // time remaining in the frame

  // then keep advancing frames until time remaining is above zero
  while(time_remaining < 0)
  {
    AdvanceToNextFrame();
    time_remaining += ms_per_frame;
  }
}

rojan_neo

  • Newbie
  • *
  • Posts: 28
    • View Profile
    • http://makeagame.tumblr.com
Sprite Sheet Animation problem
« Reply #2 on: August 16, 2011, 01:37:05 pm »
Thanks your method helped me a lot and now I can animate my sprites.. :D