I have a custom font I'd like to use with my game. Is there a way for me to include the .ttf file with the game, and have the font display accordingly as the default one when played?
OK… I've not tried this, but it should be possible.
You'll need to set the game's defaultwebfont
attribute to the name of your font (the name, not the filename).
The in your UI Initialisation script, put something like:
JS.addScript("<style>@font-face { font-family: 'MyFontName'; src: url('" + GetFileURL("myfont.ttf") + "'); }</style>")
(changing the filename and fontname as appropriate)
However, if you want it to work properly on all browsers, you should include the font in multiple file formats. Sites like Transfonter can convert it for you. Then, your line would look more like:
JS.addScript("<style>@font-face { font-family: 'MyFontName'; src: url('" + GetFileURL("myfont.eot") + "'); src: url('" + GetFileURL("myfont.eot") + "?#iefix') format('embedded-opentype'),
url('" + GetFileURL("myfont.woff2") + "') format('woff2'), url('" + GetFileURL("myfont.woff") + "') format('woff'), url('" + GetFileURL("myfont.ttf") + "') format('truetype'), url('" + GetFileURL("myfont.svg") + "#MyFontName') format('svg');}</style>")
(Yes, I know EOT is included twice. This is a workaround for an Internet Explorer bug. If you remove the first one, it won't work in IE versions before 8)