0

I am having some trouble with cocos2dx (windows-ver. cocos2d-1.0.1-x-0.12.0) CCLabelTTF. Whichever label having string-with-spaces, the label is moving upwards by few pixels.

Here is the basic code I used to display two labels (with and without spaces) at the same position. This picture shows how it is displayed.

CCLabelTTF *label0 = CCLabelTTF::labelWithString( "This is a", GAME_FONT, 20 );
addChild( label0 );
label0->setPosition( ccp( SCR_W / 2, SCR_H / 2 ) );

CCLabelTTF *label1 = CCLabelTTF::labelWithString( "string", GAME_FONT, 20 );
addChild( label1 );
label1->setPosition( ccp( SCR_W / 2, SCR_H / 2 ) );

The project is working fine on Mac for iOS. I noticed the bug while trying to port it for windows. It is too late for me to update to a new cocos2dx SDK, as it involves API changes.

halfer
  • 19,824
  • 17
  • 99
  • 186
  • Have you tried this with different fonts? Could be an issue with the font itself. – CodeSmile Sep 27 '13 at 08:23
  • Tried with 3 different fonts, but same displacement with every font. – ios_developer Sep 27 '13 at 10:44
  • Try in a new project with this particular cocos2d-x version just to verify this is a cocos2d-x issue. If it is, try verifying the issue in a newer cocos2d-x version. If it's gone there, you may want to upgrade or at least try to locate and cherrypick the corresponding fix. – CodeSmile Sep 27 '13 at 10:51
  • Thanks for the responses. I downloaded the latest cocos2dx sdk and was surprised to see that the issue is still there. Could this possibly be related to the simulator ? I don't have a device right now. Going to get a device soon and check in it. – ios_developer Sep 27 '13 at 11:59
  • certainly, always verify issues on a device – CodeSmile Sep 27 '13 at 14:46
  • I had the same issue, see here: http://www.cocos2d-x.org/forums/6/topics/35477 . We decided to use instead LabelBMFont in the end. – jonynz Oct 07 '13 at 13:46
  • Even I used CCLabelBMFont instead and it solved the displacement issue and a bunch of associated crashes. Thanks everyone for replies ! – ios_developer Oct 08 '13 at 11:35

1 Answers1

1
you can create label such type. try it
 CCLabelTTF *lbl_Question=CCLabelTTF::create("23", "mvboli.ttf", 36, CCSize(400, 0),       kCCTextAlignmentCenter, kCCVerticalTextAlignmentCenter);
Dinesh Patel
  • 142
  • 1
  • 7