# SDL Problem

This topic is 2977 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello guys! I have problem with sdl. So I made a little game and I loaded pictures for player and background then I defined Uint8 keys = SDL_GetKeyState(NULL); and did when player press a, x-- and so on but I have problem with drawing,when the picture moves it left the trace =( then I tried something with SDL_FillRect(...) and then picture didn't left the trace but now there isn't background anymore.So can some1 tell my some solutions for that, thx! Sry for my bad english Ponco123

##### Share on other sites
Let's say you make an SDL window that is 800x600 pixels^2. You have a background image; call it "background.bmp". And let's also know that you have a game loop.

So why is it leaving the 'trace' or 'trails' as people sometimes refer to them?

It is because you are not clearing the screen. You should change yr game loop to something like:

The following is pseudo code....
while(game){     background.blit();  // clear the screen. blit the background to the screen.     player.update();    // carry out player updating stuff here, like movement.     player.blit();      // draw the player.     SDL_Flip();         // flip the back buffer.}

So basically you have a background image that is the same dimensions as the screen. In my example above, the image "background.bmp" should be 800x600 pixels^2, the same as the SDL window size.

By first blitting the background to the screen, you 'clear' the screen. Then you can draw the updated images in their updated orientations. If you omit this step, then yr sprite will leave a trail of images that correspond to where it was when that particular frame was rendered.

So the moral of the story is blit the background, that is the same size as the SDL window, first, at the beginning of yr rendering code in order to draw over these sprite trails or traces. Then blit the updated sprites.

Hopefully I am clear enough.

##### Share on other sites
yes,thanks a lot =)