Custom Fonts

Custom Fonts
0.0 0


Quick questions!

Is it possible yet to use LabelTTF to load a custom font, and if so, how would I go about setting up the font file properly?

I know in Cocos2d you convert to .fnt format and make sure there’s a reference to it in your info.plist ( if i remember correctly ). Is the process similar for Cocos2d html?



It is the similar process between Cocos2d-x and Cocos2d-html5 in cc.LabelBMFont (.fnt).

It also supports custom font by `font-face selector.

`font-face {
 font-family: yourFontName ;
 src: url( /location/of/font/FontFileName.ttf ) format(“truetype”);

/\* Then use it like you would any other font \*/
.yourFontName { font-family: yourFontName , verdana, helvetica, sans-serif;


Thanks for the response!

I’m trying to get my .fnt file working with cc.LabelBMFont, but BMFontConfiguration.parseConfigFile doesn’t seem be parsing the .fnt file properly.

It gets past the line:
var data = cc.SAXParser.shareParser().getList(controlFile);
and data remains undefined.

I’m a bit new to JS, but its not immediately apparent what getList() is supposed to be doing here. I can’t see where xmllist would be populated through this flow.

My call looks like this:
var desc = cc.LabelBMFont.create("test text", "./fonts/TestFont.fnt");

Any ideas what I could be doing wrong here?


Your call method is right.

What is the cocos2d-html5 version in your test case?

I have tested both alpha2 and github version, and all of them are right.

Please check your engine version and .fnt file path.


I got it working!

I followed “MenuTest” a bit more closely after confirming the LabelBMFonts work just fine there, and noticed that I had neglected to set cc.Loader.shareLoader().preload(g_resources) to preload any resources for my project. After doing this referencing my font works just fine.

Thanks for the help!