Custom TTF font

Custom TTF font
0.0 0


How can I change the font used by coco studio ?


Which widget do you want to change the font?


Do you mean you wanna to change the default font to your custom font in a widget like textFiled?


Yes, that’s what I want to do.
I want to use my own TTF font in my game (for labels, text fields).

I’m currently using a BMP font, but coco studio is more powerfull with TTF fonts (more settings; alignment, custom max size,…). Using BMP font, you have to take care that your text does fit, for example. Also, text field always uses TTF font, so BMP is not an option.


Unfortunately UI Editor doesn’t support your own fonts in their widgets now…:;sick


Where does Cocos2d-x take the TTF font from when running the game ?
A MacOS build show a different font than Windows builds.
So, there must be a way to replace the default font with a new font after building the source.
I suppose there must be a TTF font file loaded at runtime, or something.
Is it?



I do

Label *lbl = dynamic_cast( UIHelper::seekWidgetByName( root, "Title" ) );
lbl->setFontName( "fonts/Marker Felt.ttf" );

But nothing happends… I’m working on Win32 platform.
Marker Felt.ttf is placed inside Resources/fonts folder.
Any idea?


Finally I managed to use my own fonts, but not properly.
On Win32 and MacOS builds, the font must be installed on the operative system for it to be rendered on Cocos2d-x applications. In this case, the font does not have to be included in the project resources (neither added to info.plist on MacOS). But I might be doing something wrong, because this solution would force all users to have that font installed on their systems, which obviouly is not possible.

Adding the font to project resources and using the above code, DOES work, however, on Android.
Any idea why it isn’t on Win or MacOS ?
I’ve not tried on iOS yet.