Sign in to follow this  

SDL Fade Out Question

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am trying to create a function in SDL that will fade the screen out to any color desired. So far I have:
void fade_out(int r, int g, int b) {
  for(int y = 0; y <= SCREEN_HEIGHT; y++) {
    for(int x = 0; x <= SCREEN_WIDTH; x++) {
      SDL_Rect fill_area;
      fill_area.x = x;
      fill_area.y = y;
      fill_area.w = 1;
      fill_area.h = 1;
SDL_FillRect(SDL_GetVideoSurface(), &fill_area, SDL_MapRGB(SDL_GetVideoSurface()->format, r, g, b));
      SDL_Delay(10);
    }
  }
}
This works just fine without the SDL_Delay(10);, but the problem is that it does it too fast for me to even notice that is is fading, it just fills in the screen with a color instantly. When I add in the SDL_Delay(10);, it doesn't do anything, just sits there with a black screen. Any ideas? EDIT: Nevermind, I solved the problem myself. For those who are having similar problems, it was that I did not flip the screen. The solution was much more complicated and had to use a boolean to check and see if the game was currently fading. If it was, it continued to fade in the next iteration. fade_out() would create a SDL_Rect that started at (0,0) and had a height of SCREEN_HEIGHT and a width of a passed in x value plus a passed in fade speed. If it went outside the boundaries of the screen, it returned false to signal that fading is done. [Edited by - kevin_06s on February 28, 2010 5:00:14 PM]

Share this post


Link to post
Share on other sites

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

If you intended to correct an error in the post then please contact us.

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