2

I made a CCLabelTTF object in one of my custom layers.

myLabel = CCLabelTTF::create( "Something", CCSizeMake( 300, 96 ), kCCTextAlignmentCenter, "Arial Rounded MT Bold", 48.0f );

Works perfectly fine in the simulator and an iPhone device. But on the iPad, it doesn't work. I've added the font in the resources folder and in the Info.plist file but it still doesn't work.

So I tried to run the HelloWorld layer ( same project ). It has a CCLabelTTF with a Thonburi font. Worked fine on the iPad. But when I used Thonburi in my own layer, it didn't work! Why would it not be able to show a text with a Thonburi font in my own layer when it can in the HelloWorld layer?

The difference between the two CCLabelTTF objects are:

  1. The HelloWorld version is a local variable while in my layer it is a member variable.
  2. The HelloWorld version used CCLabelTTF::create( text, font, size ) while in my layer I used CCLabelTTF::create( text, dimension, alignment, font, size )
alxcyl
  • 2,722
  • 7
  • 31
  • 47
  • Lance, I just posted a Question+Answer post on this question. I had this same problem and was getting quite frustrated. Because, though numerous users have had this problem, often times it was for various reasons. My response is a combination of all solutions. Follow my answer, and it should solve your problem. If not, post a comment and I'll find the solution and update my answer. Anyway, here is the post (http://stackoverflow.com/questions/14508675/how-can-i-add-a-font-to-my-cocos2d-ios-project-and-use-it-with-a-cclabelttf) – RLH Jan 25 '13 at 12:03

1 Answers1

0

in 2.0, they change the API of the create function to create(const char *string, const char *fontName, float fontSize, const CCSize& dimensions, CCTextAlignment hAlignment)

m.ding
  • 3,172
  • 19
  • 27
  • The label does not show. 1. Yes, I have. It works fine on an iPhone. 2. False. I set it to be three times the font size. When I try to get the label's size, I get zero. – alxcyl Oct 01 '12 at 10:24
  • @LanceGray I copy your code into my project and I think I know why. in 2.0, they change the api to `create(const char *string, const char *fontName, float fontSize, const CCSize& dimensions, CCTextAlignment hAlignment)` – m.ding Oct 01 '12 at 23:10
  • I tried it but it's not in the API. The only similar one is `CCLabelTTF::create(const char *string, const cocos2d::CCSize &dimensions, CCTextAlignment hAlignment, const char *fontName, float fontSize)` and that's what I am using. – alxcyl Oct 02 '12 at 01:00
  • @LanceGray That is wild, how about the label position? is it out of the screen? – m.ding Oct 02 '12 at 01:10
  • It's still there. I don't know what the reason is but `CCLabelTTF` won't work. I've replaced my `CCLabelTTF` with `CCLabelBMFont` and I think the results were better than expected. Thanks a lot for your help. – alxcyl Oct 02 '12 at 02:57
  • @LanceGray it is really strange, as long as it works fine on iphone, it is expected to work in ipad as well. sorry cannot help much. – m.ding Oct 02 '12 at 03:41