Display Text | First Person Game

Started by Phonoitypal, Fri 28/07/2023 20:06:33

Previous topic - Next topic

Phonoitypal

Hello again!
I've encountered the following difficulty:
While working on a first person game(using a blank template for the sake of learning the engine as a whole), I want to be able to trigger text that will be somewhere at the bottom of the screen. The problem is, while I can do that using the Display Text function, the game pauses, freezing all the animations that happen(and are necessary) in the background.
My question is : how can I actually print text on to the screen, so that it may be at the bottom of the screen, thus not 'pausing'the game? I thought about making an invisible character that would be positioned somewhere in the mid-bottom, but I am sure there is another way that is more efficent. Thanks in advance and I hope that someone can help me. :(

CaptainD

You could use a character, but you could also use Surface.DisplayString. If you did that you'd have to (for instance) draw a background colour rectangle over it once you wanted the text to disappear though.

Another possibility is using a GUI text label, which can be redefined within the room code.
 

Phonoitypal

Quote from: CaptainD on Fri 28/07/2023 20:18:52You could use a character, but you could also use Surface.DisplayString. If you did that you'd have to (for instance) draw a background colour rectangle over it once you wanted the text to disappear though.

Another possibility is using a GUI text label, which can be redefined within the room code.


Could you be more specific about the GUI version  please ? I'm still learning the hang of it (ags). While I tried to use a normal character text, I cannot seem to find where can I modify how long it can appear on screen(it flashes just for 1 second) or how to actually change its size(to be bigger)

Khris

#3
Create a GUI (gSpeech) and put a label (lblSpeech) on it.
Set the GUI's y position to a suitable one near the bottom and make it as wide as the screen. Then set its border and background color to a suitable color or to 0 to just display the text.
Make the label as wide as the GUI and adjust the alignment, font and text size to your liking.

Next, add a function to the global script:

Code: ags
function CustomSay(this Character*, String text) {
  int gameloops = ((text.Length / game.text_speed) + 1) * GetGameSpeed();
  lblSpeech.Text = text;
  lbl.TextColor = this.SpeechColor;
  gSpeech.Visible = true;
  SetTimer(1, gameloops);
}

We're using a timer to hide the GUI again, so add this to the repeatedly_execute function:
Code: ags
  if (IsTimerExired(1)) gSpeech.Visible = false;

Next we need to import the function in the global header so we can call it in room scripts, too:
Code: ags
import function CustomSay(this Character*, String text);

You can now do
Code: ags
  player.CustomSay("Hello!");

Note that calling this a second time right after will currently simply overwrite the text and reset the timer, so if you want say commands to queue but still be non-blocking, you will have to program a literal queue mechanism.

SMF spam blocked by CleanTalk