Jump to content
  • Advertisement
Sign in to follow this  

SDL - Refreshing the screen

This topic is 4183 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'm having problems with SDL and trying to refresh the screen. When I run the code below, the ship just moves across the screen, and leaves a trail.
#include "SDL.h"

const int WINDOW_WIDTH = 640;
const int WINDOW_HEIGHT = 480;
const char* WINDOW_TITLE = "SDL Sprites";

int main(int argc, char **argv)
   SDL_Surface* screen = SDL_SetVideoMode( WINDOW_WIDTH, WINDOW_HEIGHT, 0, 
                     SDL_HWSURFACE | SDL_DOUBLEBUF );
   SDL_WM_SetCaption( WINDOW_TITLE, 0 ); 
   SDL_Surface* ship = SDL_LoadBMP("ship.bmp");
   SDL_Rect shipPos;
   shipPos.x = 100;
   shipPos.y = 100;
   shipPos.w = 30;
   shipPos.h = 55;
   SDL_SetColorKey(screen, SDL_SRCCOLORKEY, SDL_MapRGB(screen->format, 0, 0, 0));
   SDL_Event event;
   bool gameRunning = true;
   while (gameRunning)
         if (SDL_PollEvent(&event))
            if (event.type == SDL_QUIT)
               gameRunning = false;
         SDL_BlitSurface(ship, NULL, screen, &shipPos);
         if (shipPos.x < 610)
            shipPos.x += 1;
         SDL_UpdateRect(screen, 0, 0, 0, 0);


   return 0;

I've tried putting the line: SDL_UpdateRect(screen, 0, 0, 0, 0); in lines in the while loop, but it still has no effect.

Share this post

Link to post
Share on other sites
Clear the screen by filling it white using SDL_FillRect().

Also SDL_Flip() and SDL_UpdateRect() do the same thing in your code so there's no need to call them both.

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!