How to enable stroking on label in IOS 7.0 in cocos2d-x | Techbirds

The normal stroking code of a label doesn’t work in IOS 7.0 but it works successfuly below IOS 7.0
The basic code for enabling stroking is provided below. We need to add a CCLabelTTF and then call the enableStroke function

CCLabelTTF *label=CCLabelTTF::create("Hello", "Arial.fnt", 50); label->setPosition(ccp(300,300)); label->enableStroke(ccGREEN, 1.0,true); this->addChild(label);
This works fine with IOS below 7.0. But in IOS 7.0 there is no stroking effect on the label. In order to fix the issue just follow some steps

1. Find the CCImage.mm file in your project and find the following code written there

// actually draw the text in the context // XXX: ios7 casting

[str drawInRect:CGRectMake(textOriginX, textOrigingY, textWidth, textHeight) withFont:font lineBreakMode:NSLineBreakByWordWrapping alignment:(NSTextAlignment)align];

2. Now add the following code just below this line

//New Code Start if(pInfo->hasStroke) { CGContextSetTextDrawingMode(context, kCGTextStroke); CGContextSetRGBFillColor(context, pInfo->strokeColorR, pInfo->strokeColorG, pInfo->strokeColorB, 1); CGContextSetLineWidth(context, pInfo->strokeSize); [str drawInRect:CGRectMake(textOriginX, textOrigingY, textWidth, textHeight) withFont:font lineBreakMode:NSLineBreakByWordWrapping alignment:(NSTextAlignment)align]; }

//New Code End

3. Save the CCImage.mm file and then again re-run your project. It will redraw stroke with correct color.
Tested on 7.0 simulator

HAPPY CODING

1,552 total views, 1 views today

Share this Onfacebook-2754436twitter-6807360linkedin-2341123google-3441258 Tags: C++, cocos2dx, Game-development