I've referred to this link: Using custom fonts in Cocos2d
and this link : http://captainjor.wordpress.com/2013/04/03/cocos2d-x-custom-ttf-font/
The first link works but I can only specify the family name of the font (Name based on the top of the font window). If I wanted Bold, or some crazy ass styling, I cannot specify explicitly as I opened other styles fonts like BoldItalic or Italic, it still returns me the Family Name.
The second link does not work at all.
The code I've used in Cocos2dx that works:
CCLabelTTF *energyLabel = CCLabelTTF::create("ABCDEFGHIJKL", "Roboto", 60.0f);
This one doesn't:
CCLabelTTF *energyLabel = CCLabelTTF::create("ABCDEFGHIJKL", "Roboto Black Italic", 60.0f);
Note that I've already double checked in my Info.plist file to import all the required fonts. Anyone has any more solutions? =/ I'm pretty stumped. Importing fonts are such PITA.
EDIT: I've stumbled again on this issue, but in a different approach. just thought I would post here a few important pointers on how I exactly do font importing for Android and iOS. Note that this is best for supporting the Import of fonts with ONE line of code.
-> Yes we can see that I have somehow included the "fonts/" subfolder directory EVEN THOUGH the fonts are at the ROOT folder in Resources. This is the weirdest part here and this should be only thing that's tricky. I tried removing the "fonts/" subfolder directory reference and it DOESN'T WORK when I tried to use the font to display texts/ labels in my application
And this is the line that works for both iOS and Android:
CCLabelTTF* levelLabel = CCLabelTTF::create("TextDisplayed", Roboto-BlackItalic.ttf, 12);
This line of code heavily relies on this fact: PostScript Name of a Font needs to be exactly the same as file name.
Would you try using
"Roboto-BlackItalic"
as a font name? I have just checked in some code base of mine and I am using the font filename (without extension) rather that the proper font name and it works just fine.
EDIT: as per Joel Tay's comment, it is the Postscript font name the right one to use. You can find it in Font Book, as the attached picture shows, by selecting Show Font Info from the Preview Menu.