Jump to content
  • Advertisement
Sign in to follow this  

SDL Fade Out Question

This topic is 3186 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));
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
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!