Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: The creature on Tue 06/11/2018 10:36:54

Title: Changing text color mid sentence.
Post by: The creature on Tue 06/11/2018 10:36:54
Hi I was wondering  - like the post title says - if you can change the color text mid sentence to highlight keywords.

For example:
if (Parser.Said("navigation"))lDetails.Text=("Command Example:[['navigate b1 to r2'[Moves bot1 to Room1");

The text is set to white, is it possible to change "navigate b1 to r2'[Moves bot1 to Room1" to say green?

Kind regards
C
Title: Re: Changing text color mid sentence.
Post by: Khris on Tue 06/11/2018 10:56:43
Not with built-in texts like those appearing on labels or when you call Display(). You would have to program your own font rendering, basically. Split the text accordingly, measure it, draw colored text on a DrawingSurface, display it using a GUI or GUI Button. Not fun :)
Title: Re: Changing text color mid sentence.
Post by: dayowlron on Tue 06/11/2018 15:04:00
You could create a graphic then create an object in the room then set it visible when you want it displayed, but the text would be static so couldn't use any variables to create it.
Title: Re: Changing text color mid sentence.
Post by: The creature on Tue 06/11/2018 15:27:26
Great.

Thanks for the reply, food for thought.
Title: Re: Changing text color mid sentence.
Post by: Cassiebsg on Tue 06/11/2018 17:58:13
You can try and use a GUI with labels, since you can change the colour of the labels.
So you would have:

lbCommand.TextColor = 15; // white
lbMoves.TextColor = 2; // Green

Then you just pass the text to the label on the GUI...

lbCommand.Text = "navigate b1 to r2";
lbMoves= "Moves bot1 to Room1";

This is a simple way to do it. But does require that "navigate b1 to r2" isn't "move b1 to r2"... Though if that's a possibility, you can also adjust the x,y of the label in script if needed... but seems to me that the green will always be on the next line, and thus will always start right bellow the command.

Like:

navigate b1 to b2
Moves bot1 to Room1

I'm just simplifying Khris's idea, though I'm skipping the "DrawingSurface" (mostly cause I'm a chicken and haven't bothered to learn how to use that yet. (laugh) ).

Anyway, just a practical solution on how to do it.
Title: Re: Changing text color mid sentence.
Post by: Khris on Tue 06/11/2018 18:05:31
If that solution is enough, you can position the 2nd labels behind the 1st using GetTextWidth().