Quote from: geork on Wed 24/04/2013 11:41:23
You can reference a font through it's enumerated index. Something like:Code: AGS int f = eFontFont0; Overlay *v = Overlay.CreateTextual(40, 40, 40, f, 6, "hi!");//where f stands in for the FontType parameter
I don't know if the wording I've used is correct, but the code works
Thanks, that seems to work perfectly.
Anyway, I'm just going to post the code here, as it's easier for me to keep it updated.
V1.2
Script Header:
//Expressed as MAXIMUM_DISPLAY_TIME * (delay * 4)
//Therefore, a delay setting of 3 and a maximum time of 5
//will wait 60 game loops before removing the text
#define TYPEWRITER_MAXIMUM_DISPLAY_TIME 5
enum TypewriterStyle {
eTypewriter_LongSpace,
eTypewriter_Constant,
eTypewriter_ShortSpace,
eTypeWriter_Mixed,
};
enum TypewriterFlash {
eTypewriter_Flash = true,
eTypewriter_DontFlash = false,
};
struct Typewriter {
import static void Type (int x, int y, int delay, int color, int font,
String text, TypewriterStyle style,
AudioClip *sound = 0, TypewriterFlash flash = true);
};
Main Script:
Overlay *olTypedText;
static void Typewriter::Type (int x, int y, int delay, int color, int font,
String text, TypewriterStyle style,
AudioClip *sound, TypewriterFlash flash) {
String displayedLine = "";
olTypedText = Overlay.CreateTextual (x, y, System.ViewportWidth - x,
font, color, displayedLine);
Wait (delay);
int i = 0;
while (i < text.Length) {
displayedLine = String.Format ("%s%c", displayedLine, text.Chars[i]);
olTypedText.SetText (System.ViewportWidth - x, font, color, displayedLine);
if (style == eTypewriter_LongSpace) {
if (text.Chars[i] == ' ')
Wait(delay*2);
else if (text.Chars[i] == '[')
Wait(delay*4);
else {
if (sound)
sound.Play ();
Wait(delay);
}
}
else if (style == eTypewriter_Constant) {
if (text.Chars[i] == ' ')
Wait(delay);
else if (text.Chars[i] == '[')
Wait(delay*2);
else {
if (sound)
sound.Play ();
Wait(delay);
}
}
else if (style == eTypewriter_ShortSpace) {
if (text.Chars[i] == ' ')
Wait(delay/2);
else if (text.Chars[i] == '[')
Wait(delay*2);
else {
if (sound)
sound.Play ();
Wait(delay);
}
}
else if (style == eTypeWriter_Mixed) {
int r = Random(2);
if (text.Chars[i] == ' ') {
if (r == 0)
Wait (delay*2);
else if (r == 1)
Wait (delay/2);
else
Wait (delay);
}
else if (text.Chars[i] == '[') {
if (r == 0)
Wait (delay*2);
else
Wait (delay*4);
}
else {
if (sound)
sound.Play ();
Wait (delay);
}
}
i++;
}
if (flash == eTypewriter_Flash) {
i = 0;
while (i < TYPEWRITER_MAXIMUM_DISPLAY_TIME) {
olTypedText.SetText (System.ViewportWidth - x, font, color,
displayedLine.Truncate (displayedLine.Length - 1));
Wait (delay*2);
displayedLine = String.Format ("%s%c", displayedLine, text.Chars[displayedLine.Length]);
olTypedText.SetText (System.ViewportWidth - x, font, color, displayedLine);
Wait (delay*2);
i++;
}
}
else if (flash == eTypewriter_DontFlash) {
Wait (TYPEWRITER_MAXIMUM_DISPLAY_TIME * (delay * 4));
}
if (olTypedText.Valid)
olTypedText.Remove ();
}