Jump to content

Fonts and setFont()


Recommended Posts

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 ?

Link to comment
Share on other sites

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');


Link to comment
Share on other sites

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.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...