[SOLVED] How to dynamically load font

Hi!

I need to load a font by specifying its name. Normally, you would use something like this:

var font:h2d.Font = hxd.Res.fonts.fontname.toFont();

But I need to use a variable (i.e. load the font after compilation). I tried this:

var font:h2d.Font = hxd.Res.loader.load(“fonts/” + “fontname”).toFont();

but I get this error:

hxd.res.Any has no field toFont

Any ideas on how to achieve this?

I’ve done it in this way:

hxd.Res.load(‘fonts/${fontName}.fnt’).to(hxd.res.BitmapFont).toFont();

2 Likes

Awsome! This works great! Thanks a lot, buddy <3