- Home /
Changing Button/Label text size?
The game I'm working on is designed for 1920x1080 and automatically scales to whatever resolution you're running it at. Naturally for 1920x1080, I need a fairly big font (32 point seems to work nicely) but if someone is running at 640x480, a 32 point font is far, far too big. Now I can't possibly load a different font for every possible resolution out there, but I can't find a way to adjust text size either. This seems pretty elementary. Presumably fonts are loaded into a texture, and drawn from the texture. So there should not be any speed hit from scaling them, and I can scale everything else which is drawn from a texture, but I can't find the trick for fonts.
Surely there's a solution for this. People can't be having enormous fonts on very low resolutions, or vice versa.
Answer by lollevel · Feb 21, 2010 at 02:37 AM
I remember something about resizing the fonts of GUI on the 3rd person plataform tutorial's pdf here at page 55, that's achieved by using a transform matrix.
example from GameHUD.js from tutorial:
// Our GUI is laid out for a 1920 x 1200 pixel display (16:10 aspect).
//The next line makes sure it rescales nicely to other resolutions.
GUI.matrix = Matrix4x4.TRS (Vector3(0, 0, 0),
Quaternion.identity, Vector3 (Screen.height / nativeVerticalResolution,
Screen.height / nativeVerticalResolution, 1));
Hope it helps :)
A very creative solution, and with a lot of other possibilities too. Thanks very much for that.
Answer by Eric5h5 · Feb 21, 2010 at 03:39 AM
If you're using a GUIText object rather than OnGUI, it's trivial to use text that scales automatically, by unchecking "pixel correct" and adjusting the X and Y scale as desired.
I hadn't really looked at GUIText objects until now. Ideally, I did want a button in this instance, for the added benefits of keeping everything within the GUI system. Nevertheless, GUIText objects could definitely have their uses as well, so thanks for introducing me to them.
I noticed that by unchecking "pixel correct", the font can look blurry. I guess that's the drawback from what I noticed.
@Hakimo: import the font at a sufficiently large size, so it will have enough resolution to be not blurry.
Your answer
Follow this Question
Related Questions
Changing the size of a GUI label 1 Answer
How to set the font size in GUI.Label 2 Answers
Changing a GUILabel text SIZE 3 Answers
multi line label with different font? 1 Answer
Why does my non-dynamic label text not resize in Android? 2 Answers