Sign in to follow this  
3Dgonewild

SDL - FLICKERING!

Recommended Posts

Hi , im having a problem with SDL library. Each time i move an image sdl flickers. I've set up the video mode like this: 800,600,32,SW_DOUBLEBUF|SDL_FULLSCREEN Also , i've tryed with the following flags : SW_DOUBLEBUF|SW_HWSURFACE|SDL_FULLSCREEN AND: SW_DOUBLEBUF|SW_SWSURFACE|SDL_FULLSCREEN But nothing. Any ideas?!

Share this post


Link to post
Share on other sites
The following flags won't work at least: SW_DOUBLEBUF|SW_SWSURFACE|SDL_FULLSCREEN because only SW_HWSURFACE is valid with SW_DOUBLEBUF. The other one should work however. If you post the rest of the code then maybe I can help you. I can't tell what's wrong with this information alone.

Share this post


Link to post
Share on other sites
Without seeing any other code, it'd be hard to tell. However, I did have an issue when I redrew the entire screen everytime a sprite moved. I got a flicker type effect then. If this is how you're handling your sprites, you can try just updating what needs to be redrawn.

For example, if you have a sprite that is 32x32, you would only redraw that 32x32 area anytime it moves instead of redrawing the entire 800x600 screen.

Share this post


Link to post
Share on other sites
Thanks for the support.

The image is about 200 x 200 ( its a bouncing ball ).


And here's the loop:
(It looks messy , but im just a newbie)

while( quit == false )
{
SDL_Flip( screen );
SDL_FillRect( screen, &screen->clip_rect, SDL_MapRGB( screen->format, 0, 0, 0 ) );
apply_surface( BallX , BallY, _BALL, screen );
fps.start();
BallX+=(int)SpeedX;
BallY+=BallSpeedY;
Bleft=BallX+_BALL->w;
Btop=BallY+_BALL->h;
if ( (Btop>SCREEN_Y))
{
BallSpeedY*=-1;
}
if (Btop<SCREEN_Y)
{
BallSpeedY+=1;
}
while( SDL_PollEvent( &event ) )
{
if( event.type == SDL_KEYDOWN )
{
switch( event.key.keysym.sym )
{
case SDLK_UP: SpeedX+=0.2f; break;
case SDLK_DOWN: SpeedX-=0.2f;break;
// case SDLK_LEFT: break;
// case SDLK_RIGHT: break;
case SDLK_ESCAPE:quit=true; break;
}
}
if( event.type == SDL_QUIT )
{
//Quit
quit = true;
}
}
//FRAMES_PER_SECOND = 20
while( fps.get_ticks() < 1000 / FRAMES_PER_SECOND )
{
// LOCK @ 20 FPS
}
}
SDL_Quit();
return 0;
}


Share this post


Link to post
Share on other sites
I tested your code and it worked fine for me. There were no flicker at all, but the object is shaking when it moves. This is because you have a frame limit to 20 FPS. Change this to 40 or something higher and the movement should be much smoother than before.

Share this post


Link to post
Share on other sites
Quote:
Original post by password
I tested your code and it worked fine for me. There were no flicker at all, but the object is shaking when it moves. This is because you have a frame limit to 20 FPS. Change this to 40 or something higher and the movement should be much smoother than before.


Thanks , now its much better.

By the way , do you know any function(in sdl) that allows you to rotate 2D images ?
I want to add some scrolling effects , but i stuck..

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