|
How keep text on the screen? |
Gustavo Boni
Member #7,653
August 2006
|
Hi all, sorry for the double post, but i'm new with Allegro and the doubts just come pop upping. I'm using an First State Machine in my game, and i have some states for the character like eating, sleeping, etc. When the character enter in the state sleeping for example, i need to write an text on the screen: textout(buffer,font,"I'm very tired, i need to sleep",0,0,makecol(255,255,255)); The problem is the text is not showing on the screen like i want, it's blinking on the screen. How can i fix this? Thanks. |
GameCreator
Member #2,541
July 2002
|
Care to share that portion of your code? I suspect that you're not using double-buffering and are clearing the screen at an inappropriate time.
|
Gustavo Boni
Member #7,653
August 2006
|
That's it. Thanks |
ReyBrujo
Moderator
January 2001
|
You are cleaning the buffer every loop. Are you also writting the text every loop? -- |
Michael Faerber
Member #4,800
July 2004
|
Should be something like this:
[EDIT] -- |
Gustavo Boni
Member #7,653
August 2006
|
ReyBrujo said: You are cleaning the buffer every loop. Are you also writting the text every loop? No, when i enter in a state, a text must be written on the screen and keep there. So, i just write this in that moment, not every loop. Michael Faerber said: Should be something like this: int main() while(!key[KEY_ESC]) countSpeed--; double_buffering(); The main change is moving the drawing code outside the logic loop. Now it's better, the text still flicking but i can see this for more time. Maybe the problem is i'm not wrtting the text every loop like ReyBrujo asked. |
GameCreator
Member #2,541
July 2002
|
Do you do a clear anywhere in your warrior->start()?
|
KnightWhoSaysNi
Member #7,339
June 2006
|
/*Coloca o buufer na tela*/ /*Linmpa o buffer*/ Switch these two things so it clears the buffer first and then blits. |
Michael Faerber
Member #4,800
July 2004
|
Quote: Switch these two things so it clears the buffer first and then blits. Erm ... you are sure you know what you just suggested? That way it would always blit an empty (black) buffer to the screen! Quote: Do you do a clear anywhere in your warrior->start()?
Generally, do you do anything graphics related (blitting, clearing, drawing) in that function? -- |
Gustavo Boni
Member #7,653
August 2006
|
GameCreator said: Do you do a clear anywhere in your warrior->start()? No, the only thing is the call textoutput inside. Michael Faerber said:
Generally, do you do anything graphics related (blitting, clearing, drawing) in that function? Ok, here it goes:
When i call the warrior->start(); the start() function calls the Sleeping::entry(). [EDIT] Sorry guys, the name of some functions are in my language (Portuguese). |
GameCreator
Member #2,541
July 2002
|
Since it should do the exact same thing, can you replace
|
BAF
Member #2,981
December 2002
|
He should do ALL the drawing at once, and not do any in the logic loop. |
KnightWhoSaysNi
Member #7,339
June 2006
|
I meant: clear(buffer); drawstuffonbuffer() blit(buffer,screen,0,0,0,0,640,480); |
-Doft-
Member #7,309
June 2006
|
Gustavo Boni
Member #7,653
August 2006
|
GameCreator said:
Since it should do the exact same thing, can you replace Yes, it still flickers! [quote-Doft-]Have you tried writing the text every time? I can't because i will need to change all my code. |
BAF
Member #2,981
December 2002
|
That's how you have to do it. You (in most cases) cannot draw in your logic loop like that without flickering. [edit] |
Gustavo Boni
Member #7,653
August 2006
|
BAF said: That's how you have to do it. You (in most cases) cannot draw in your logic loop like that without flickering. [edit] Hm... Maybe i should change my project structure. It would be better if there was in Allegro a function like cout << "Hello" << endl; i just need to show the message. |
BAF
Member #2,981
December 2002
|
Make a message system like that then... you set the message up and then have a manager which draws them when its time to draw. |
Steve Terry
Member #1,989
March 2002
|
If it's not too complex to make the change make a text object part of your main character. If a string value is present then print that to the buffer, or alternatively set a flag but checking for NIL is just as easy. That way when the character needs to speak you set your text, and on drawing of the screen the text is printed, no need for a state for each text. ___________________________________ |
Tobias Dammers
Member #2,604
August 2002
|
Quote: checking for NIL is just as easy C tends to call it NULL. Anyway: Separate logic from drawing! The logic function must never touch any graphics routines, and must not call any function that does. Ideally, the logic function has no idea where to draw to (which is why the back buffer should not be a global var, but rather be maintained by the main loop or a dedicated module, and only passed to the drawing code). The drawing function must not change any state of the game logic. In C++, an object's draw() function should be const. Regard the game logic as read-only in the drawing function. --- |
Steve Terry
Member #1,989
March 2002
|
NULL is 0, same as NIL but NIL is represented by a character, namely '\0'... which is also 0 ___________________________________ |
|