having trouble with dialogue text placement

Started by Ardentsideburns, Sun 03/11/2019 14:17:08

Previous topic - Next topic

Ardentsideburns

hey peeps! i 'm having a problem and i don't exactly know if there's an actual solution to it, i've looked everywhere but i can't really find a way to solve the problem.

so basically our game has plenty of animations, so to keep everything on the same axis and to allow enough space to do wildly different animations we had like every frame take about 200x200 pixels of space.

now the actual character size is about a third of that of course, the rest of it is composed of transparent pixels. This wouldn't be a big deal if it wasn't that when the character speaks the text is shown at the top of the 200x200 frame instead of on top of the character's head, making the text appear miles above the character.

is there a way for ags to ignore the transparent pixels when it comes to showing text?

thanks for your help in advance!

Laura Hunt

#1
You could try using a custom speech function. At the top of your global script:

Code: ags
function myCustomSay(this Character*, String message) {

  int mytextwidth = GetTextWidth(message, eFontFont0);  // use your actual speech font here
  int mytextheight = 80 + GetTextHeight(message, eFontFont0, 300);
  this.SayAt(this.x - (mytextwidth / 2), this.y - mytextheight, 300, message); 

}


(Replace 80 with the actual height of the character + a few pixels of air, and 300 with the maximum width you want the text lines to be.)

And then import it from your global script header (.ash):

Code: ags
import function myCustomSay(this Character*, String message);


Now you just have to call your function instead of the regular Say:

Code: ags
cExampleCharacter.myCustomSay("Does this work now?");



Even better would be to replace the (this.y - 80) part with something a bit more flexible using font height and text width to know how tall the text will be and adjust the y coordinate accordingly, but for now I'm hoping this does the trick!

Edit: ok, I think I got it? I'm sure there's something wrong because I'm bad at math in general, but at least it's a start.


SMF spam blocked by CleanTalk