CocosBuilder icon indicating copy to clipboard operation
CocosBuilder copied to clipboard

[2.1x] CCLabelTTF - User Fonts not working

Open Tw0bit opened this issue 12 years ago • 5 comments

When selecting a user font (in the root of Resources or subfolders) the CCLabelTTF content size resizes to 0 by 0 and nothing is shown.

We have tried many fonts, even the standard "CocosBuilder System" fonts as .ttf files - they do not appear. In addition, the text does not appear on the CCControlButtons.

The font does not appear in xCode projects. Here are the logs to our font: 2012-10-17 09:03:17:782 sampleApp[43301:3079] setTitleTTF: bannb forState:1 2012-10-17 09:03:17.783 sampleApp[43301: c07] cocos2d: Unable to load font bannb 2012-10-17 09:03:17.802 sampleApp[43301: c07] cocos2d: Texture2d: Invalid Font: bannb. Verify the .ttf name

The ttf is exported from the system fonts and placed in the ROOT resources folder. It has been added to xCode.

Tw0bit avatar Oct 16 '12 23:10 Tw0bit

I believe the issue was with the font name/file name. When I labelled the file to match the title (as in Font Book) it appeared in CocosBuilder.

For xCode, I had to add the font to the info.plist.

Tw0bit avatar Oct 17 '12 01:10 Tw0bit

I am using cocosbuilder 3 alpha 5. I have tried different combinations of including ttf extension and not in plist files, in actual file names etc... None of them work.

However, I do not get any logs about not finding a file or unable to load the files....

I tried searching about it, but couldn't find anything. How do I go about debugging what the issue is?

sramanujan avatar Jul 31 '13 03:07 sramanujan

I see that CCNodeLoader simply returns the entire path as provided in the CCB to setFontName with the full path. This will not work on iOS as iOS needs fonts to be mentioned in the plist file beforehand and just the font name for setFontName - is there a possible way in which I can get this working without having to edit source files (CCNodeLoader) ?

sramanujan avatar Jul 31 '13 04:07 sramanujan

@sramanujan, as you noticed, CCB3alpha doesn't work correctly. It worked better in 2.1, but you'd have to rename the file so it matches the font's Postscript name (displayed in Font Book).

My recommendation is to store only the font's Postscript name in the CCLabelTTF nodes in ccb and ccbi files. It will reduce platform dependencies and the massaging (of font files) necessary for developers to build their games.

huperniketes avatar Aug 06 '13 22:08 huperniketes

I've met this problem too... My solution is that change the font file name to it's PostScript name (upperlower careless) then you kan have the font show in the CocosBuilder. I think it's caused by the code in CCTexture2D.initWithString() "NSFont* font = [NSFont fontWithName:name size:size];" the name input is the font name you have selected in the cocosbuilder, but it try to load the font as the postscript name, if your font file name is not equal to it's postscript name then it will failed.

zjsxcm avatar May 31 '15 13:05 zjsxcm