LoginSignup
1
1

More than 5 years have passed since last update.

CCLabelTTFのenableStrokeがiOS7で効かない

Last updated at Posted at 2014-05-17

Cocos2d-x で開発をしていて、CCLabelTTFに縁取りをしたいと思って、
以下のように記述

CCLabelTTF* pLabel = CCLabelTTF::create(labelType.c_str(), GAME_FONT, 28);
// 影をつける
pLabel->enableShadow(CCSizeMake(4,-4),0.5,0.8,true);
// 縁取りをする
pLabel->enableStroke(ccGRAY,1.0,true);

cocos2d-x のバージョンは、cocos2d-x-2.2.3

iOS7だと、縁取りが反映されない。

ここに対処方法が乗ってた。
Stroking not working on CCLabelTTF in cocos2d-x ios in c++

これを参考に、以下のように修正しました。

修正前:

// actually draw the text in the context
// XXX: ios7 casting
[str drawInRect:CGRectMake(textOriginX, textOrigingY, textWidth, textHeight) withFont:font lineBreakMode:NSLineBreakByWordWrapping alignment:(NSTextAlignment)align];

修正後:

// actually draw the text in the context
// XXX: ios7 casting
[str drawInRect:CGRectMake(textOriginX, textOrigingY, textWidth, textHeight) withFont:font lineBreakMode:NSLineBreakByWordWrapping alignment:(NSTextAlignment)align];

// 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

試してませんが、以下のサイトの方法でも大丈夫かもです。

CCLabelTTFのenableStrokeをiOS7に対応させる

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1