3
\$\begingroup\$

When animating sprites I am taking the delta difference between frames and locking the rendering frame rate of the sprite animation to the delta time.

float delay = 1000.0f / FPS;
float now = SDL_GetTicks();
if(now - sprite->last_update > delay) {
    render sprite frame
}

This is causing flickering because the background is being drawn faster than the sprite. (my guess) If I draw as fast as the frame rate the flickering goes away. If I slow down the background rendering then the background flickers. By slow down I mean set the FPS to 30. I want to be able to slow down the animation for a single sprite. I need a better way to lock the frame rate for individual sprites. I can slow the entire frame rate down by delaying in the game loop but I want to be able to slow down a single sprite. Is this possible?

\$\endgroup\$
2
  • 1
    \$\begingroup\$ You should draw the sprite every frame. The If check you have will be to advance the frame index. \$\endgroup\$
    – Tetrad
    May 30, 2013 at 21:41
  • \$\begingroup\$ @Tetrad brilliant.....that makes sense and it also works...thank you \$\endgroup\$ May 30, 2013 at 22:12

1 Answer 1

1
\$\begingroup\$

Seeing as how you are already using SDL, I would advice taking the tutorials over at SDLtutorials.

In particular there is a tutorial on Animation which gives you an Animation CLASS, which includes framerate, frame increments, and even other more complex things like oscillation.

http://www.sdltutorials.com/sdl-animation

\$\endgroup\$
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .