c++ - 在 c++ 中的 cocos2d-x ios 中,在 CCLabelTTF 上抚摸不起作用

标签 c++ xcode cocos2d-x

我正在尝试在我的标签中绘制绿色轮廓,但它不起作用.. 我的代码是

CCLabelTTF* pLabel = CCLabelTTF::create("Hello World", "HoboStd", 50);
pLabel->setPosition(ccp(200,200));
pLabel->enableStroke(ccGREEN, 5.0,true);
this->addChild(pLabel);

它没有提供围绕标签文本 Hello World 的轮廓。任何人都可以帮助我

最佳答案

我在 ios7.0 中修复了如何在标签上启用描边 标签的正常描边代码在 IOS 7.0 中不起作用,但在 IOS 7.0 以下可以正常工作 下面提供了启用描边的基本代码。我们需要添加一个CCLabelTTF,然后调用enableStroke函数

CCLabelTTF *label=CCLabelTTF::create("Hello", "Arial.fnt", 50);
label->setPosition(ccp(300,300));
label->enableStroke(ccGREEN, 1.0,true);
this->addChild(label);

这适用于低于 7.0 的 IOS。但在 IOS 7.0 中,标签上没有描边效果。为了解决这个问题,只需按照一些步骤

第一步

在你的项目中找到CCImage.mm文件,找到里面写的如下代码

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

保存 CCImage.mm 文件,然后再次重新运行您的项目。它将以正确的颜色重绘笔划。在 7.0 模拟器上测试

关于c++ - 在 c++ 中的 cocos2d-x ios 中,在 CCLabelTTF 上抚摸不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21720431/

相关文章:

c++ - 包含 header 会导致解析问题

c++ - vector 内存的有效清除

c++ - 填充二维数组随机整数相同的数字

ios - swift 索引路径=可选(0)

c++ - 在 cocos2dx v3.如何以不同的中心缩放和旋转

c++ - 从灰色到彩色对 Sprite 进行着色

C++ 是否 std::string::erase 重新分配和...?

c++ - 如何使我的字符缓冲区性能更高?

ios - Apple Mach-O 链接器警告 : how to get rid of it but not affect my friend

swift - Xcode 错误 : Argument passed to call that takes no arguments