Search code examples
ioscocos2d-iphonecocos2d-x

Cocos2d-x CCLabelTTF does not work on iPad


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 )

Solution

  • 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)