Jump to content

Fonts and setFont()


pstrejczek
 Share

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":

10463136_ScreenShot2018-07-20at7_37_46.png.50a9028b571b3022a018bd5c0771896e.png

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.

Guest
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.

Loading...
 Share

  • Recently Browsing   0 members

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