GUI advice and dynamic font sizing

Me again

I intended for my game to be run at one resolution only, but l always had it in the back of my mind that there are bound to be people who simply don’t want to or even can’t run at that resolution. Same thing for the web player. My game will need to run at different resolutions. So, statically placing the interface elements using fixed values have to go…

I finally got my interface looking nice at various resolutions and everything fits where it is supposed to go… everything except the fonts. The only way I can see to make the fonts fit the interface is by making one GUIStyle for every resolution the game can run at and do a

switch(Screen.height)
{
case 200:
GUI.Label(Rect(20, screen.height - 50, 200, 200), "Some text here", 200Style);
break;
case 480:
GUI.Label(Rect(20, screen.height - 60, 240, 240), "Some text here", 480Style);
break;
case 768:
GUI.Label(Rect(20, screen.height - 70, 290, 310), "Some text here", 768Style);
break;
}

No way is that practical for every single piece of text in the game?! Even if stored in an array with each resolution being hardcoded an array index, surely there must be an easier way? For the main menu I simply changed from fonts to PNG files but I can’t do that for the timer and for ammo counters…

So here are my questions:

  1. How does one do Fonts for games running at different resolutions?
  2. Is it possible for GUI buttons to change their images OnMouseOver?

Thanks again

You can use GUI.matrix to scale OnGUI elements. There’s a few topics about that; have a look around.

–Eric

I’ve stopped using GUI.matrix (or ScaleAroundPivot) for adapting to different screen-sizes because it gave me rather ugly artefacts in fonts both on Windows and Mac. Does anybody have a solution to that or was I the only one experiencing that?

so how do you do it at the moment?

I use the same font-size for each resolution (not ideal, of course), and simply have a few different screen layouts (3 to be exact) for ranges of differnet screen-sizes. Probably, one could do some kind of “font-lookup”, i.e. you have the default fonts in your skin, then you set up a hashtable each time the screen resolution is changed (and of course, on initialization when the game starts up), which maps the fonts you use in the skin to the ones specific to your current screen size.

Then, you replace the fonts each time you use them. That’s the part that’s not fun…

Sunny regards,
Jashan

I don’t remember seeing artifacts with GUI.Matrix, but I haven’t used it in a while. Actually, for something simple like timers and ammo counters I’d just use GUIText or GUITexture anyway, which is trivial to make resolution independent…no coding, just make sure not to use pixel correct for fonts and don’t use a scale of 0 for textures, and make the font/textures large enough that they will normally scale down rather than up. Also you can use multicolored fonts this way.

–Eric