GMS 2 text border issues

x = 500;
y = 500;

string_val = "string";
draw_text(x, y, string_val);

width = string_width(string_val);
height = string_height(string_val);

draw_rectangle(x, y, x + width, y + height, 1);

I am trying to implement a dialogue with form controls, text, etc.

I have been having problems centering text. The ended up stripping everything down to basics which is the code you see above.

I have printed some text and drawn a box around it to figure out the boundary lines. Horizontally it's pixel perfect. Vertically there are gaps between the top and bottom of where the text meets the border.

The code above should work perfectly, but it doesn't.
 

rIKmAN

Member
x = 500;
y = 500;

string_val = "string";
draw_text(x, y, string_val);

width = string_width(string_val);
height = string_height(string_val);

draw_rectangle(x, y, x + width, y + height, 1);

I am trying to implement a dialogue with form controls, text, etc.

I have been having problems centering text. The ended up stripping everything down to basics which is the code you see above.

I have printed some text and drawn a box around it to figure out the boundary lines. Horizontally it's pixel perfect. Vertically there are gaps between the top and bottom of where the text meets the border.

The code above should work perfectly, but it doesn't.
The font you are using probably has the spacing / padding in it, I just tried with Arial 12 and it's much tighter - just 1-2 pixels space at the top and bottom between the font and border rectangle.

The default font has a larger gap, so it seems dependent on the font you are using - test a few out and see what results you get.
 

rIKmAN

Member
OK, I tested it with the same font but larger and the gap is no bigger. However is there a uvs get font size type functions.
There is - font_get_uvs()
"This function returns an array with the UV coordinates for the font texture on the texture page, filling in the array with the following values: [0] = left, [1] = top, [2] = right and [3] = bottom. This value can then be used in other draw functions, particularly in general drawing when using primitives as well as the Shader functions."

You could have found this by typing "font" into the IDE and looking through the list of autocomplete suggestions, or by typing "font" into the search bar in the manual. ;)
 

Yal

šŸ§ *penguin noises*
GMC Elder
The docs are also available online, which is handy if you don't have GM running and just wanna look something up real quickly (e.g. when answering a forum question, or slacking off planning your dream game at work / school).
 
Top