Why my text isn't showing?(SDL/SDL_TTF)

Started by
18 comments, last by dudedbz1 18 years, 6 months ago
Just draw the scores every frame.
Ex:
void DrawGame(){    // Draw paddles, balls, whatever    Draw_Text(score,...);    /*     *Most likely, if you have score as an int, change it to a char     *with a stringstream or something.     *     */    SDL_Flip(...);}


I mean, dont do
if (player_scores)    Draw_Text(...);

, but do it all the time.
-----------------------------....::::DRAGON BALL Z::::....C<<"+"<<"+"; // Go C++ !!!-----------------------------
Advertisement
Ok, I have tried all that and still nothing! I have no idea why it won't freaking stay up. Anyone else? PLEASE!



EDIT:HERE IS SOME OF MY NEW CODE. THIS IS FROM MY NEW MAIN MENU. IT WON'T STAY UP FOR SOMEREASON.

Draw_Text("(P)lay Game", 24, WINDOW_WIDTH/2, WINDOW_HEIGHT/2, 255, 255, 255, 0, 0, 0);    Draw_Text("(E)xit Game", 24, WINDOW_WIDTH/2+20, WINDOW_HEIGHT/2+20, 255, 255, 255, 0, 0, 0);    Uint8* KeysHeld= SDL_GetKeyState(0);    if(KeysHeld[SDLK_p])    {                    Init();          KeysHeld[SDLK_p]=0;    }    if(KeysHeld[SDLK_e])    {          SDL_Quit();          KeysHeld[SDLK_e]=0;    }



and the Draw_Text function:

void Draw_Text(char* string, int size, int x, int y, int fr, int fg, int fb, int br, int bg, int bb){      TTF_Font* font = TTF_OpenFont("lazy.ttf", size);      SDL_Color fgc={fr, fg, fb};      SDL_Color bgc={br, bg, bb};      SDL_Surface* textsurface= TTF_RenderText_Shaded(font, string, fgc, bgc);      SDL_Rect textlocation={x, y, 0, 0};      SDL_BlitSurface(textsurface, NULL, SDL_GetVideoSurface(), &textlocation);       SDL_FreeSurface(textsurface);      TTF_CloseFont(font);}



the Main menu text comes up. I read it, then it goes. Why won't it stay again? I think it should be so simple, but it not! lol.


Chad!

[Edited by - Chad Smith on October 11, 2005 9:03:43 PM]
Now, I'm really sleepy, and I may not be thinking right... But what about putting it in a do {} while () loop?

-DBZ-
-----------------------------....::::DRAGON BALL Z::::....C<<"+"<<"+"; // Go C++ !!!-----------------------------
After your code:
Draw_Text("(P)lay Game", 24, WINDOW_WIDTH/2, WINDOW_HEIGHT/2, 255, 255, 255, 0, 0, 0);Draw_Text("(E)xit Game", 24, WINDOW_WIDTH/2+20, WINDOW_HEIGHT/2+20, 255, 255, 255, 0, 0, 0);Uint8* KeysHeld= SDL_GetKeyState(0);

I'm betting that you draw something else that ends up covering the text. Instead, make sure it's structured like this:
- Clear Screen- Draw Everything- Draw that code above- Flip Screen

Also let's see the entire rendering loop to make sure.
Oh yeah... drawing something over it might also be the case... Make sure that you draw everything in the order you want it to appear. In my pong game:

-Clear the screen
-If the game is paused
-Draw the pause menu
-Else
-Draw everything
-Flip the screen

Ex:

-Clear the screen
-Draw all sprites or pictures or whatever
-Draw your text last, so something isnt drawn over it
-Flip the screen
-----------------------------....::::DRAGON BALL Z::::....C<<"+"<<"+"; // Go C++ !!!-----------------------------
That is the Main Menu, and I am calling that first in main(). So, nothing else is being drawn over it. Atleast I wouldn't think anything would. I will try the do...while attempt.



Chad.
Sorry to double post, but I didn't want to edit that post, because I wanted people to see this post actually.



I tried the do...while, and guess what? It STILL didn't work!



NA, I'm justplaying. It worked! Yeah! I only have last minute bugs left, and the game is done! I'm so excited! Thanks everyone for your help!




Chad.
Good, good. Good luck with finishing it up everywhere. Interesting, I just finsihed my pong clone too, lol. Are you going to post a screenshot or a demo of it?

-DBZ-
-----------------------------....::::DRAGON BALL Z::::....C<<"+"<<"+"; // Go C++ !!!-----------------------------
Cool. I am going to post the demo/final version of it(not sure if it will be a demo or the final version)somewhere. I am thinking about implenting one more feature in their before I release it. Well....2 more features. I want to make this Pong Clone the best as I can.



Chad.
Cool, good luck.
-----------------------------....::::DRAGON BALL Z::::....C<<"+"<<"+"; // Go C++ !!!-----------------------------

This topic is closed to new replies.

Advertisement