|
« Reply #22 on: May 28, 2011, 04:31:17 pm »
|
|
Running it through the debugger with breakpoints, it's definitely the font that's failing to load. Here's the directory and file structure you should have: SDL_TUTORIAL\ (Solution Directory) SDL_TUTORIAL.sdf Intellisense database SDL_TUTORIAL.opensdf A lock file for the Intellisense database SDL_TUTORIAL.sln Visual Studio Solution File SDL_TUTORIAL.suo Visual Studio Solution User Options ipch\ (The contents here don't really matter to this) Debug\ This is where Visual Studio is placing your files when you build a Debug configuration Release\ This is where Visual Studio is placing your files when you build a Release configuration SDL_TUTORIAL\ (Project Directory) Debug\ This is where Visual Studio is placing temporary files during the compilation and linking phases for a Debug build Release\ This is where Visual Studio is placing temporary files during the compilation and linking phases for a Release build Source Files THIS IS NOT A SEPARATE FOLDER - THEY SHOULD BE IN SDL_TUTORIAL/SDL_TUTORIAL/ All of your source files (.h and .cpp) are going to be in here. Media THIS IS NOT A SEPARATE FOLDER - THEY SHOULD BE IN SDL_TUTORIAL/SDL_TUTORIAL/ This is also where all of your media files are going to need to be. This is because this directory is where the executable is considered to be running when you Debug/Run through Visual Studio (F5).As far as the code goes, your game loop is all sorts of messed up. Basically, here's what you want to do with your main loop: while (quit == false) while there are events if event is key down if key is up, set message to up message if key is down, set message to down message if key is left, set message to left message if key is right, set message to right message if event is quit, set quit to true apply background surface if message is not null apply message surface flip rendering buffers
So your main function should become: int main( int argc, char* args[] ) { //Quit flag bool quit = false; //Initialize if( init() == false ) { return 1; } //Load the files if( load_files() == false ) { return 2; } //Render the text upMessage = TTF_RenderText_Solid( font, "up was pressed", textColor ); downMessage = TTF_RenderText_Solid( font,"down was pressed",textColor); leftMessage = TTF_RenderText_Solid(font, "left was pressed",textColor); rightMessage = TTF_RenderText_Solid(font, "right was pressed",textColor); apply_surface(0,0,background,screen); //Apply the images to the screen //While the user hasn't quit while( quit == false ) { //While there's events to handle while( SDL_PollEvent( &event ) ) { if (event.type == SDL_KEYDOWN) { switch(event.key.keysym.sym) { case SDLK_UP : message = upMessage; break; case SDLK_DOWN : message = downMessage; break; case SDLK_LEFT : message = leftMessage; break; case SDLK_RIGHT : message = rightMessage; break; } } //If the user has Xed out the window else if( event.type == SDL_QUIT ) { //Quit the program quit = true; } } apply_surface( 0, 0, background, screen ); if (message != NULL) { apply_surface((SCREEN_WIDTH - message->w) / 2, (SCREEN_HEIGHT - message->h) / 2, message,screen); } //Update the screen if( SDL_Flip( screen ) == -1 ) { return 4; } } //Free surfaces and font then quit SDL_ttf and SDL clean_up(); return 0; }
It's still not the cleanest code around, but it's functional. You don't want to set message to NULL after rendering it because you only receive an event when you press the key. If you want the message to only appear when the button is pressed, I can show you some modified event code to check for the button being held (basically, setting/clearing a boolean value on key up/down, then checking for the bool to set message).
Logged
|
There's such a double standard about religion in the modern world. Catholics can gather, wear white robes, and say "In nomine Patris, et Filii, et Spiritus Sancti" and be considered normal.
But if my friends and I gather, wear black robes, and say "Ph'nglui mglw'nafh Cthulhu R'lyeh wgah'nagl fhtagn", we're considered cultists.
|