- 本帖最后由 关中coder 于 2012-11-5 19:18 编辑 *
我看到帖子里没有字体描黑边的方法,群里有很多同学在问。我这有个简单的方法,可以给大家参考下,直接看代码
static CCRenderTexture* createStroke(CCLabelTTF* label, float size ,ccColor3B cor)
{
float RealSize = size;
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
//if( CDevice::GetDeviceType() == “iPad” )
//{
// RealSize = size * 2;
//}
#endif
CCRenderTexture* rt = CCRenderTexture::create(label->getTexture()->getContentSize().width + RealSize2, label->getTexture()->getContentSize().height + RealSize2);
CCPoint originalPos = label->getPosition();
ccColor3B originalColor = label->getColor();
bool originalVisibility = label->isVisible();
label->setColor(cor);
label->setVisible(true);
ccBlendFunc originalBlend = label->getBlendFunc();
ccBlendFunc tBlendFunc = {GL_SRC_ALPHA, GL_ONE };
label->setBlendFunc(tBlendFunc);
CCPoint bottomLeft = ccp(label->getTexture()->getContentSize().width * label->getAnchorPoint().x + RealSize, label->getTexture()->getContentSize().height * label->getAnchorPoint().y + RealSize);
CCPoint positionOffset = ccp(label->getTexture()->getContentSize().width * label->getAnchorPoint().x - label->getTexture()->getContentSize().width/2, label->getTexture()->getContentSize().height * label->getAnchorPoint().y - label->getTexture()->getContentSize().height/2);
CCPoint position = ccpSub(originalPos, positionOffset);
rt->begin();
for (int i=0; i<360; i+=30)
{
label->setPosition(ccp(bottomLeft.x + sin(CC_DEGREES_TO_RADIANS(i))*RealSize, bottomLeft.y + cos(CC_DEGREES_TO_RADIANS(i))*RealSize));
label->visit();
}
rt->end();
label->setPosition(originalPos);
label->setColor(originalColor);
label->setBlendFunc(originalBlend);
label->setVisible(originalVisibility);
rt->setPosition(position);
return rt;
}
pLabelTTF = CCLabelTTF::labelWithString( “test”, "Verdana-BoldItalic", 12 );
pLabelTTF->setPosition( pSprite->getPosition() );
static const ccColor3B ccBlack = {0,0,0};
pstroke = createStroke(pLabelTTF, 1,ccBlack);
addChild( pstroke,100 );
addChild( pLabelTTF,100 );//注意add顺序不能变
虽然用的方式比较怪,但是效果还行,先凑合用被!
