# sprite animation individual framerate

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?

• 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