[SDL] Rect(s) flash when they are moving

Started by
3 comments, last by Simian Man 16 years, 1 month ago
Hi. I am using SDL_Rect in my game. If I draw one, it moves fine and smooth. If I draw more, they keep flashing. The way I'm doing this: Every time is the time to draw: draw the background and everything else on it. Is there a better way to do this?
Advertisement
It sounds like every time you draw a rectangle, you're also drawing the background, which would then cover up the previous rectangle.

If so, you should draw the background once, before any of the rectangles, then draw the rectangles on top of it.

If not, post some code so we can try and see what you did wrong.
Quote:Original post by redattack34
It sounds like every time you draw a rectangle, you're also drawing the background, which would then cover up the previous rectangle.

That's what I'm doing, but I draw the background first so the rect is drawn on it.

If I don't do that, the rectangles will leave a trail behind.
Do you have double buffering enabled? More info here.

Basically, at setup time, set the video mode to include double buffering. Then, before each frame, call SDL_Flip(whatever_surface); to swap the buffers. This will only draw a frame once everything is finished drawing, so things show up all at once, and not staggered, which may be happening now.
Even if you are not using double buffering, you should call SDL_Flip. It will call SDL_UpdateRecs for you which could remove the flicker.

This topic is closed to new replies.

Advertisement