SDL Problem

Started by
1 comment, last by ponco123 14 years, 3 months ago
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
Advertisement
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.
yes,thanks a lot =)

This topic is closed to new replies.

Advertisement