在c ++中,cocos2d-x ios中的CCLabelTTF不工作 [英] Stroking not working on CCLabelTTF in cocos2d-x ios in c++

查看:131
本文介绍了在c ++中,cocos2d-x ios中的CCLabelTTF不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我tryng在我的标签中,我的标签绿色的轮廓大纲,但它不工作..
我的代码是

I am tryng to make an outline of green color in my label but its not working.. my code is

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

它不提供标签文本周围的轮廓Hello World.Any one here谁可以帮助我


Its not providing the outline around the label text Hello World.Any one here who can help me

推荐答案

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

I got the fix in ios7.0 on how to enable stroking on labels 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);

这适用于IOS 7.0以下。但在IOS 7.0中没有对标签的抚摸效果。

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



Step1



在项目中找到CCImage.mm文件并找到以下代码写入

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];



Step2



现在添加以下代码

Step2

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

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

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

这篇关于在c ++中,cocos2d-x ios中的CCLabelTTF不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆