Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Vincent on Tue 24/11/2015 12:34:47

Title: Char color
Post by: Vincent on Tue 24/11/2015 12:34:47
Good evening to all AGSer !!!

Since there is not a section below the beginning area, I will post it here.
I would like to ask you if there is a way to choose a single char from a label text and being able to change its single color.

Example :
Code (ags) Select

String text = "This is a String text";


I would love to get all the 't' or all the 'i' to be in a different color in that text.
Any of you know the right approach to use to get this to work ?

Grazie mille in advance.
Title: Re: Char color
Post by: Khris on Wed 25/11/2015 22:12:53
The only way to do this is to compose a DynamicSprite using .DrawString(), then show that in place of the label, for instance by drawing the result onto the GUI's background image.
Title: Re: Char color
Post by: Vincent on Thu 26/11/2015 11:30:59
Hi Khris, is a glad to hear from you.
Thanks so much for suggesting the best approach to do something like this.
Your help was very greatly appreciated.
I meant to add a new parameter or two in my function, which can optionally change color for that char(in that specific text).
But I find difficulties to execute your idea in my script.
I wish I could show you and I hope you can help me again.

Code (ags) Select

function _Say (this Character*, String txt, int speed, int color)
{
   String text = GetTranslation(txt);
   if (!color) color = chars_setup[this.ID].SpeechColor;
   lblboard.TextColor = color;
   
   // display char
   String temp = "";
   int text_length = text.Length;
   int i = 0;
   char current_char;
   bool abort = false;
   bool speaking = false;
   while (i < text_length && !abort)
   {
      current_char = text.Chars[i];
      temp = temp.AppendChar(current_char);
      lblboard.Text = temp;
      if (current_char == eKeyPeriod)
      {
         // do stuff
         speaking = false;
      }
     
      else if (!speaking)
      {
         // do stuff
         speaking = true;
      }
     
     abort = WaitMouseKey(6);
     i++;
   }

   lblboard.Text = text;
   // do stuff
   if  (abort)
   WaitMouseKey(2 * (text_length - i) + 50);
   else
   WaitMouseKey(50);
}




I had to start by doing something like so :

Code (ags) Select

// outside
DynamicSprite*text_box;


function game_start()
{
   text_box = DynamicSprite.Create(gSpeechbox.Width, gSpeechbox.Height); // ?
}



Then I should write something like this but I can't figure it out how can I make this to work inside my function..

Code (ags) Select

DrawingSurface*sur = text_box.GetDrawingSurface();
sur.DrawingColor = 14;
sur.DrawString(0, 0, Game.NormalFont, "%s", text); // text regarding the one inside the function...
gSpeechbox.BackgroundGraphic = text_box.Graphic;
sur.Release();
Title: Re: Char color
Post by: Khris on Thu 26/11/2015 18:17:32
Could you describe *how exactly* the code fails?
Title: Re: Char color
Post by: Vincent on Fri 04/12/2015 21:13:40
Hi Khris, I am sorry for the late reply.
I had to change some things inside the function to make sure that your idea worked well.
I would like to thank you for your help because it was useful.
Especially use the DrawingSurface String and land the result in the background of the gui.
Bravo, Grazie mille :)