Sign in to follow this  
ponco123

SDL Problem

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 this post


Link to post
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 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