How to set CCLabelTTF with fixed width and dynamic height?

I followed the example at http://www.cocos2d-x.org/projects/cocos2d-x/wiki/How_does_CCLabelTTF_support_line_breaks_and_wrapping

but when i set height to 0, the label is not visiable

label = CCLabelTTF::labelWithString(“show ”, CCSizeMake(300, 0), CCTextAlignmentCenter, “Arial”, 9);

I created 4 lables with the following code, but only 3 lablels are visiable, the attachement is the screenshot

CCLabelTTF *label;
// fixed width & fixed heigth, visible
label = CCLabelTTF::labelWithString(“show ”, CCSizeMake(300, 50), CCTextAlignmentCenter, “Arial”, 9);
label~~>setPosition);
addChild;
// fixed width & fixed height, visible
label = CCLabelTTF::labelWithString, CCTextAlignmentCenter, “Arial”, 9);
label~~>setPosition(ccp(0,0));
addChild(label);
// fixed width & dynamic height, invisible :frowning:
label = CCLabelTTF::labelWithString(“show ”, CCSizeMake(300, 0), CCTextAlignmentCenter, “Arial”, 9);
label~~>setPosition);
addChild;
// dynamic width & dynamic height, visible
label = CCLabelTTF::labelWithString, CCTextAlignmentCenter, “Arial”, 9);
label~~>setPosition(ccp(0,–50));
addChild(label);


Screen Shot 2012-02-17 at 下午5.41.25.png (15.6 KB)

I

Same problem here, did you find a solution ?

I’m using cocos2d-1.0.1-x-0.12.0 now , seems that the bug has been fixed.

Hmm strange, I’m using version 0.12.0 and I have the same problem.

I still have the problem, and I don’t understand why it’s working for you and not for me :slight_smile:

My code is :

CCLabelTTF *label = CCLabelTTF::labelWithString("show \nme \nthe \nmoney", CCSizeMake(300, 0), CCTextAlignmentCenter, "Arial", 32); label->setPosition(ccp(200, 200)); this->addChild(label);

I’m using cocos2d-1.0.1-x-0.12.0 on iOS.

Thanks for your help.

After comparing the files, it seems that i totally messed up my cocos2d-x versions.
Sorry, my fault.
Thanks for your help.

Fixed width can be achieved by the label attribute ‘boundingWidth’