gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 07:06:10 25 4
gpt4 key购买 nike

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

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com