Sign in to follow this  
quark

Can't create custom BitmapFont

Recommended Posts

Good morning, I created a font using bmGlyph and exported as 'Sparrow/Starling' to use with pixi.

 

Using the font directly on the bitmapText style works correctly:

// Load font
app.loader.add('dafont', 'dafont.fnt').load(startup);

function startup() {
   const text = new PIXI.BitmapText('ABCDEFGHIJLMNOPQRSTUVWXYZ\nabcdefghijlmnopqrstuvwxyz\n0123456789', { fontName: 'dafont' });
   app.stage.addChild(text);
}   

result_correct.png

Trying to create a bitmapFont with a custom style it just doesnt' apply the intended font: 

// Load font
app.loader.add('dafont', 'dafont.fnt').load(startup);

function startup()
{
   PIXI.BitmapFont.from('bestfont', {fontName: 'dafont', size: 48});
   const text = new PIXI.BitmapText('ABCDEFGHIJLMNOPQRSTUVWXYZ\nabcdefghijlmnopqrstuvwxyz\n0123456789', { fontName: 'bestfont' });
   app.stage.addChild(text);
}   

result_wrong.png

Can't actually understand if I'm doing something wrong or if it's a misbehaviour.

Thanks in advance :)

Share this post


Link to post
Share on other sites

The 'from' function here is meant to be to generate your own bitmap font dynamically from a text style... which uses the Text class on the background. And the Text class uses the Canvas API to generate textures. You can use custom fonts via loaded woff / woff2 files, just like in html and CSS.  But you cannot use a Bitmap font as a source to draw regular Text

Share this post


Link to post
Share on other sites
19 hours ago, themoonrat said:

The 'from' function here is meant to be to generate your own bitmap font dynamically from a text style... which uses the Text class on the background. And the Text class uses the Canvas API to generate textures. You can use custom fonts via loaded woff / woff2 files, just like in html and CSS.  But you cannot use a Bitmap font as a source to draw regular Text

Thanks for your reply and the explanation. I misunderstood it's behaviour! I already had it working with regular web fonts and somehow I expected the same behaviour to the already created BitmapFonts 😕 

Just a simple note, I made a simple trick so that i don't need to create a bitmapFont for each text color (that share same font), every bitmapFont from an web font is generated with fill white, and then it's applied tint instead of fill to the bitmapText directly to change text color.

Share this post


Link to post
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...
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.