1
votes

In my game I use cclabelttf to display the score the player made. It was working fine back in the end of July, I've changed nothing in my code, but there was a: - IOS upgraded (6.1 to 7.0) - OSX updated - cocos2d-x
- Xcode update

I'm not using helvetica fonts.

I have a floating text to show the score, if I kill a terrorist a "+10" string floats up and than disappears, if I write " +10 " then it's visible, otherwise it's not.

I've tried to change the text alignment in ccimage.mm, from UITextAlignmentLeft to the same with NS,

uncomment these lines:

if( [font isKindOfClass:[UIFont class] ] )
{
    [str drawInRect:CGRectMake(0, startH, dim.width, dim.height) withFont:font lineBreakMode:(UILineBreakMode)UILineBreakModeWordWrap alignment:align];
}

I've read these modifications on the cococs2d-x forum, there was a bug back than, and these was the solution. No luck for me.

Weird part is on my gameScene one of the labels is visible, but only on iPhone simulator, but starting from this, I think it must be an alignment/wrapping problem.

2
thanks but I don't think so, I've tried these thingFerenc Dajka

2 Answers

4
votes

Met the same issue, found a solution works for me, try this. Modify _initWithString in CCImage.mm, at line:

CGContextRef context = CGBitmapContextCreate(data, dim.width, dim.height, 8, dim.width * 4, colorSpace, kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big);

change it to:

CGContextRef context = CGBitmapContextCreate(data, (int)dim.width, (int)dim.height, 8, (int)dim.width * 4, colorSpace, kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big);

Just three (int) casts.

0
votes

maybe you can try it like this:

CCLabelTTF*  YouClassName::stringNewLine(string orgStr,CCSize sizeTable,const char* fontName,float fontSize){
CCLabelTTF *m_label_content = CCLabelTTF::create( "hello", fontName, fontSize ,sizeTable, kCCTextAlignmentCenter, kCCVerticalTextAlignmentCenter);

m_label_content->setString(orgStr.c_str());
return m_label_content;
}

and use it like this

CCLabelTTF * ttf = stringNewLine("test",CCSizeMake(200,200), "Arial", 28);