Original Post
Hello everyone, I am having a problem. The code below compiles, but when I run it, the window flashes quickly and then disappears. To be quite honest, I am very new to the whole game loop thing as I have never attempted game programming before. There is probably a simple solution, and I am sorry if this is a stupid question. Maybe I am tired and just can't see the problem. I am new here too, so Hello! (BTW, I know the way the paddle is moving is pointless, but i believe it should still work, I was just messing around.) /********************************************************************** * Name: A Program Version 1.0 * * Author: Shane O'Neal * * SDK: SDL * **********************************************************************/ #include #include "SDL.h" #include "SDL_image.h" using namespace std; // Defines for screen height, width and depth #define SCREEN_WIDTH 500 #define SCREEN_HEIGHT 400 #define SCREEN_DEPTH 16 int main(int args, char **argv) { // Set up the variables SDL_Event event; SDL_Surface *screen; SDL_Surface *ball; SDL_Surface *paddle; SDL_Surface *background; int paddle_movey, paddle_movex; // Initialize SDL SDL_Init(SDL_INIT_EVERYTHING); // Set up "screen" as the screen screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_DEPTH, SDL_DOUBLEBUF); background = IMG_Load("sunset.jpg"); // Blit the background surface SDL_Rect bg_dest; bg_dest.w = SCREEN_WIDTH; bg_dest.h = SCREEN_HEIGHT; bg_dest.x = 0; bg_dest.y = 0; SDL_BlitSurface(background, NULL, screen, &bg_dest); // Set up the paddle surface and rect paddle = IMG_Load("paddle.bmp"); SDL_Rect paddle_dest, paddle_src; paddle_dest.w = paddle->w; paddle_dest.h = paddle->h; paddle_dest.x = 200; paddle_dest.y = 350; paddle_src = paddle_dest; // The Main Message Loop bool running = true; while (running) { SDL_PollEvent(&event); switch (event.type) { case SDL_QUIT: running = false; } SDL_FillRect(screen, NULL, 0); SDL_BlitSurface(paddle, &paddle_src, screen, &paddle_dest); paddle_dest.x += 1; if (paddle_dest.x == 0 || paddle_dest.x == SCREEN_WIDTH - paddle_dest.w) paddle_dest.x -= 1; SDL_UpdateRect(screen, 0, 0 ,0 ,0); SDL_Flip(screen); } return 0; }