Font on different screen size

Hey,

I’ve faced with problem of rendering fonts on various screen size. What’s the best approach to do that ? I can think about two solutions:

  1. Use scale factor in drawString method (quality of scaled font could be poor …)
  2. Generate (in content pipeline) few fonts of the same type with different size and choose the best matching

I don’t have much time to experiment with solutions, so it will be great if you could share some thoughts about this common problem. Also, I don’t want to use any third-party libraries.

I generate 2 different sizes and then downscale from the one that is closer (never upscale).

But I haven’t played on a 4k display, maybe I would need another even bigger fontsize.

Any other opinions?

Currently I’m trying to implement this approach.

  1. Is it possible to read dynamically font size from SpriteFont object? Couldn’t find a way how to do that.
  2. How to choose scale factor ? For example, my game is for HD resolution and I scale every object properly with scaleX and scaleY factors. For font we could apply only one parameter. Which one should I use ? Horizontally or vertically factor ?

You can read the LineSpacing property of the SpriteFont.

The original Half-Life game had several fonts for different screen resolutions. It had them named with the vertical screen resolution they were made for, then loaded the font that most closely matched the user’s selected screen resolution. They didn’t bother scaling the font for in-between resolutions though, and that worked fine for what they wanted.

You could have several fonts at different sizes, named according to a set of screen resolutions, and then scale the font based on the screen vertical resolution and the SpriteFont’s LineSpacing property.