int main(int argc, char* args[]){ // Initialize the game InitGame(); // Load the game resources LoadGame(); // Game Loop while ( gamedata.game_loop ) // This is a bool set to true until exit { // At the start of a frame we want to start our FPS timer timer_reg_fps.StartTimer(); // Grab the latest event in the event-queue SDL_PollEvent(&gamedata.sdl_event); // Update the game each frame UpdateGame(); // This runs game-logic // Render the game each frame RenderGame(); // Effectively this calls an SDL_Flip() to update the screen // Regulate the FPS - keeps the FPS around 60 if ( gamedata.vsync ) { // Check if we need to sleep if ( timer_reg_fps.GetTicks() < (1000 / gamedata.vsync_fps) ) { // Sleep SDL_Delay( ( 1000 / gamedata.vsync_fps ) - timer_reg_fps.GetTicks() ); } } // At the end of a frame we want to reset our frame timer timer_reg_fps.StopTimer(); // Now reset it timer_reg_fps.ResetTimer(); } // Unload resources UnloadGame(); // Exit program return 0;}
At the start of UpdateGame() function I call an ClearScreen() command that effectively does SDL_FillRect() on the screen that will be SDL_Flipp()'d each frame in RenderGame(), then I redraw the entire scene.
Unfortunately I don't know how to make this a clear and concise question, so I apologize for that - but my game tends to jitter a bit as I move along (it's a side-scroller very much like Mario) and I'm not sure if I'm doing something blatantly wrong here or if it's just to be expected when using SDL. (It's not a very noticeable jitter, I probably only notice it because I'm the one writing the game.)