Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Armageddon on Sat 20/04/2013 06:51:17

Title: How do I move where speech is displayed and typewriter scrawl.
Post by: Armageddon on Sat 20/04/2013 06:51:17
Hi, I'm wanting to make all speech be displayed in the top left corner like old Lucas Arts games and also not be centered but aligned to the left. Can you even move how the speech text is displayed?

Also I'm wondering how you would make the speech type out like a typewriter?

Thanks.
Title: Re: How do I move where speech is displayed and typewriter scrawl.
Post by: Slasher on Sat 20/04/2013 07:28:21
Hi,

To have the text align left you could use:

Code (AGS) Select
game.speech_text_align=eAlignLeft;

To Display text in a certain area you could use:

Code (AGS) Select
cEgo.SayAt(220, 20, 100, "My name is ego"); // Left, Top, Length, Text


You could also look at using a GUI with label to display the speech, as for typewriting text do a search for typewriter as there are a few answers to that very question.

Hope you find the right solution

Title: Re: How do I move where speech is displayed and typewriter scrawl.
Post by: geork on Sat 20/04/2013 15:55:30
For the typewritten speech, you could do this, although it's a bit more hassle: you'll have to use a custom function (I prefer extender function) for speech instead of using commands like 'Say()' and have that typewrite. you'll probably want a while loop within the function that truncates the string to a lesser and lesser degree every so-many game loops. Maybe something like:
Code (AGS) Select
void Comment(this Character*, String m){ //extender function
  this.StopMoving();
  Overlay* bgs;
  this.LockView(this.SpeechView);
  this.Animate(this.Loop, 3, eRepeat, eNoBlock, eForwards);
  int timer = ((m.Length/Game.TextReadingSpeed + 1) * GetGameSpeed())/m.Length; //get how long every wait should be
                                                                                //the reason this has to be calculated
                                                                                //is because AGS calculates speech time
                                                                                //in 15 character - 40 game loop steps
  int i = 1;
  while (i<=m.Length){
    bgs = this.SayBackground(m.Truncat(i));
    Wait(timer);
    i ++;
  }
  if (bgs != null && bgs.Valid) bgs.Remove();
  this.UnlockView();
}
//then to call it
cChar.Comment("Blah");

!This is thoroughly untested!
The only problem is that this is not skippable. Also, you can't control where the command is put. For that, you may want to change the code like this:
Code (AGS) Select
void CommentAt(this Character*, String m, int X, int Y, int Width, int ColorIndex){ //extender function
  this.StopMoving();
  Overlay* bgs = Overlay.CreateTextual(X,Y,Width, Game.SpeechFont, ColorIndex, ""); //initialize the overlay to display a text
;
  this.LockView(this.SpeechView);
  this.Animate(this.Loop, 3, eRepeat, eNoBlock, eForwards);
  int timer = ((m.Length/Game.TextReadingSpeed + 1) * GetGameSpeed())/m.Length; //get how long every wait should be
                                                                                //the reason this has to be calculated
                                                                                //is because AGS calculates speech time
                                                                                //in 15 character - 40 game loop steps
  int i = 1;
  while (i<=m.Length){
    String s = m.Truncate(i);
    bgs.SetText(Width, Game.SpeechFont, ColorIndex, s); //change the text to the truncated string
    Wait(timer);
    i ++;
  }
  if (bgs != null && bgs.Valid) bgs.Remove();
  this.UnlockView();
}
//then to call it
cChar.CommentAt("Blah", 200, 200, 200, 15);

!Again: thoroughly untested!
  This isn't the most optimized solution I'm sure, but it's something to start on.

Hope that helps! :)

EDIT: Oops, just realized the maths was wrong for the loop. now fixed