• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Legacy GM Non-Monospaced Font Dialogue Box

D

DarkzFlame

Guest
I'm following this tutorial by diestware on how to create a Dialogue Box.
And I noticed that it only supports Monospaced fonts, but preferably I want it to be Non-Monospaced like a font like Arial where one character is longer than the other.

Currently it uses the amount of characters multiplied by a width variable that remains the same for each character, to place each character correctly. as you can see here below.
Code:
draw_text(tX+(space*char_width), tY+(13*line), string_char_at(message[message_current],i))
But I wonder if there is a way to make the variable change depending on the width of the previous character.
Or another way that makes it Non-Monospaced.
 
D

DarkzFlame

Guest
Thanks, but that doesn't work for so far as I know, because it draws each character as an individual string.
This is also explained in the tutorial here is a snippet of it.
Now the “draw_text” function no longer draws the entire string, it is now drawing each character individually, so we have to manually space them out.
“tX+(space*charWidth)” is doing exactly this.
Remember “space” is like the character count, so we multiply this by the charWidth. So if “space” is equal to 3 and charWidth is equal to 7,
7 X 3 = 21, so the third character will be 21 pixels to the right of the tX position.
 

Ragster

Member
I'm not too sure everything he told you to do in the tutorial, but one thing you could do is add the individual amount of each letter's width as you're displaying them, instead of just 7.

Something along the lines of this:

Code:
current_width = 0;
Code:
var char;
char = string_char_at(message[message_current],i);
draw_text(tX+current_width, tY+(13*line), char);
current_width += string_width(char);
I'm not too sure what the variable "space" is supposed to do, so you may have to add it back in there somewhere, maybe at the "current width += " part? I'm not too sure.
 

Phil Strahl

Member
For a quick implementation, I'd store the width of the widest glyph in the font, usually that's the capital W. Granted, if you write "Illi lilli lil Ill" that line will be too short.

A little more advanced (but not 100% bulletproof) solution would be to use statistics and find out the average glyph length and add this up.

Depending on how much text you're going to plot, I'd personally prefer the "brute force" method: Have a table that has the exact width for every character in your font and use it to calculate the lline width. This might be a little intense, so don't do it on every frame. ;)
 
J

jackhigh24

Guest
create you own font from sprites you can then get the sprite width and set char_width to equal it
 
Top