Impossible to create font. Please check file

I tried to use LabelBMFont.

var label2 = new cc.LabelBMFont("Test", "res/fonts/bitmapFontTest2.fnt");
    // testing anchors
    label2.anchorX = 0.5;
    label2.anchorY = 0.5;
    label2.color = cc.color.RED ;
    this.addChild(label2, 0);

I am getting those errors.

cc.LabelBMFont.initWithString(): Impossible to create font. Please check file

I got that output from web console.
If i am targeting multi resolution,
Which is best option? Label, LabelBMFont, LabelAtlas

Take a look here

BMFont requires 2 files. The .fnt and a .png.

Also, Label is unified now, so Label should be able to create any type of label.

auto myLabel = Label::createWithBMFont("bitmapRed.fnt", "Your Text");
Uncaught TypeError: Cannot read property 'totalQuads' of null

The same coding copied from test files.
Now i have added the png file the fnt location. I have the two files in the same location. Now, the error is different.

var label2 = new cc.LabelBMFont("Test", "res/fonts/bitmapFontTest2.fnt");
    // testing anchors
    label2.anchorX = 0.5;
    label2.anchorY = 0.5;
    label2.color = cc.color.RED;
    this.addChild(label2, 3);

Javascript does not contain Label.createWithBMFont

Make sure that your .png file and .fnt file are preloaded. Usually this is done by adding it to a dictionary in resource.js. Then use the code from your first post.

1 Like

Sir, It is working after loading them.
One more doubt.
Can i use different size .fnt and .png for multi resolution support?

Yes you can, you need different paths for each resolution. This tutorial shows how. One side note this tutorial is still valid, though the creator has made a newer version with a different approach.

I was using the second method supporting multiple devices with LabelTTF.
However, It did not work with few devices which are greater resolution. My friend has note 5 and font is not displayed as expected.

That is why i am trying BMFont.
Will BMFont work good if i create multiple of them with different sizes?

Yes, though you should create them bigger then the size you want. For example if you need to have a max font size of 32, create a .fnt with size 64 and downscale the bmfont in your code. That way if the target resolution is bigger than the design resolution and the view gets scaled the font will still look good.

1 Like

Nice Idea. Should i follow this methods on sprites too?

Sprites can be scaled a bit before it looks bad. It’ll depend on your artwork though. I’m using the second approach as well, with one asset set for all resolutions. The max scale would be 2x, which is still acceptable for the artwork I’m using.

1 Like