Sign in to follow this  
sheep19

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

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this