Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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?

share|improve this question
1  
You should draw the sprite every frame. The If check you have will be to advance the frame index. –  Tetrad May 30 '13 at 21:41
    
@Tetrad brilliant.....that makes sense and it also works...thank you –  eat_a_lemon May 30 '13 at 22:12

1 Answer 1

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.