pstrejczek Posted July 19, 2018 Share Posted July 19, 2018 I have two fonts in my game. One of the fonts works. I add it to the scene with game.addAsset('font.fnt'). Then, in another scene, I have another font added the same way, but it looks like it still uses the font from the other scene. I'm aware of the setFont() function, but I don't know how it works. I don't know why there is 'Arial' in the example when the font files are font.fnt and font2.fnt. When I try to call setFont with my font filename as a parameter setFont('bigfont.fnt') the editor throws: Uncaught Font bigfont.fnt not found. The font is correct. When I replace the other font in other scene with this one - it works. What am I doing wrong ? Quote Link to comment Share on other sites More sharing options...
enpu Posted July 20, 2018 Share Posted July 20, 2018 Good question. Font name and font filename are different things. You can have font named Arial in a filename font.fnt. You should be able to set the font name in the software that you use to generate the fonts. If you look inside the fnt file, the name should be defined as "face": When you load more than one font, you can set the font in a text using setFont function or as a parameter like this: // Create text using Arial font var text = new game.Text('Hello', { font: 'Arial' }); You can also set default font in your config. All texts that you create and do not define the font, will use the default font: game.config = { text: { defaultFont: 'Arial' } }; // If multiple fonts loaded, this will use the default font var text = new game.Text('Hello'); pstrejczek 1 Quote Link to comment Share on other sites More sharing options...
pstrejczek Posted July 20, 2018 Author Share Posted July 20, 2018 Thanks @enpu ! Everything is clear now and works like a charm. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.