SDL Animation & collision

Feb 20, 2013 at 7:49pm
closed account (N36fSL3A)
:D I'm so happy! The progress on my game looks promising!!!! Just one question...

I need a quick & easy way to add animation & collision to my DragonBall Z game. (You can't have a DBZ game without collision or animation.)

Moving around is all good, but without animation, it doesn't feel right.
I was thinking that you could add collision with a SDL_Rect object slightly smaller than the sprite, but I'm not sure how to do this.

With animation, I was thinking about a SDL_Delay() with animation, but this would pause the program.

I need help quickly C:

Thanks in advance.
Feb 20, 2013 at 9:41pm
closed account (N36fSL3A)
I think I figured out collision, but I need help with animation!
Feb 20, 2013 at 10:14pm
An animation consists of one or more "frames". In its simplest form, a frame is just a single still image that is just drawn normally, and a duration to indicate how long the frame lasts.

An animating object would have these frames, and would step through them as time progresses.

If you want to base your animations on "frames" (ie: one frame of animation lasts X display frames... so at 60 FPS, a frame that lasts 60 display frames would last 1 second long), you can just have an update() function which counts down the remaining frames until the next frame.

You would call this update() every display frame.

1
2
3
4
5
6
7
8
9
void animation::update()
{
  timeremaining -= 1;
  if(timeremaining <= 0)
  {
     currentframe += 1;
     timeremaining = lengthofcurrentframe();
  }
}


Then you simply draw the current frame.
Topic archived. No new replies allowed.