Issue with text resizing on window size change

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By wolfpeach

Hoping for a bit of assistance in diagnosing this issue.

I’ve created a minimal project here GitHub - tyrelh/godot-text-test that showcases the issue. The graphics used are created by me and the font used is TinyPixie2 by Tiny Pixie via public domain from here

The main issue as you can see from this gif is that the font size/spacing jumps around when resizing the window (the font size/spacing isn’t actually changing when observing the node, just the way it appears). Also it seems when using any window size that isn’t a perfect scaling of the render size it will cause this issue (not jumping around but not fitting the bubble.)

In the project code I am using a NinePatchRect and RichTextLabel on the same level in the tree (with the label in front). In GDScript I get the size of the text with label.get_font("normal_font").get_string_size(label.get_text()) and use this to dynamically set the size of the ninepatch rect. I do this because in my actual project I am animating this with a tween.

So the size of the bubble is set to the size of the text and font with the above code. Even when I start the project at a different resolution (not changing the window size) the text will display condensed from the start but the above code will say it’s longer. Like it isn’t an issue that its happening dynamically, it’s that the above code is returning a different value than what the text appears as.

I’m not sure if this is just an issue with this particular font or if this is a setting I can change somewhere.

I would really appreciate the help! Let me know if you have any other questions!

Follow up:

I’m slowly deciding to move my project from 2d stretch mode to the viewport stretch mode to keep that chunky pixel-perfect look. I like the pixel-perfect look but I needed to convince myself it’s a good idea.

Using viewport actually seems to fix this issue. The text no longer jumps around when scaled to different resolutions.

This isn’t really a solution to the issue as not all projects can be set to viewport scaling, but I think it works for my project.

I would still be very interested if anyone knows of other workarounds to fix this text rendering.

wolfpeach | 2021-04-05 17:37

This is a great question! I’m running into the same problem while trying to get multiple text labels to seamlessly sit side by side. Using an HBoxContainer or the label.get_font("normal_font").get_string_size(label.get_text()) method described above both work at the default resolution, but resizing the window causes a noticeable gap to form between the labels.

Unfortunately I can’t use viewport scaling because it causes the font/art to be indecipherable at smaller resolutions. One workaround might be to pre-render all the text I need as images. Another one might be to limit the resolutions that the player can choose from. But neither sound ideal, so I’d be interested in knowing if anyone has any other solutions :slight_smile:

nivrad00 | 2021-04-13 17:01