Reputation: 57
GameMaker allows you to select a font size on a font asset, and this scales perfectly without looking pixelated (with anti-aliasing enabled). However, it doesn't seem to be possible to change the font size at runtime or draw text with a specified font size. You are apparently expected to make a seperate font asset for each font size you are going to use. But what if you have to determine font size dynamically at runtime? For example the font size you need could depend on user input or on some runtime calculation, and could change to any value at runtime, not just a limited set.
The draw_text_transformed
function scales the text by xscale
and yscale
values, but it seems to essentially scale the image that is the result of the font being rendered, so if your font has a small font size and you upscale it, it will look very pixelated. This is different to when you change the font size in the font asset, which seems to correctly scale based on vector graphics and supports anti-aliasing. Even if you set the font to a very big font size and then downscale it rather than upscale, it will look worse than a font asset with that font size, since the scaling doesn't seem to use anti-aliasing. Compare:
Top is the downscaled version, bottom is a different font asset with its font size manually set to the desired value.
Is there a good solution for this?
Upvotes: 1
Views: 2067
Reputation: 3202
If you require text to be drawn at a variety of sizes and scales, distance field fonts (explanation) are the way this is usually handled. There is an example implementation for GameMaker.
An alternative is to use font_add
, which will dynamically generate a texture page for the font from a (vector-based) file.
Upvotes: 0