Cocos2d-x创建包边字
生活随笔
收集整理的這篇文章主要介紹了
Cocos2d-x创建包边字
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
CCLabelTTF* createTextWithBorder(int size,const char* content, int contentColor, int borderColor)
{
? ? //通過將兩個(gè)不同尺寸的字體疊在一起來實(shí)現(xiàn)描邊的效果
? ??
? ? //邊字體
? ? CCLabelTTF* border=CCLabelTTF::create(content, FONT_NAME, size+4);
? ??
? ? border->setColor(Color::IntTranColor3B(borderColor));
? ??
? ? //內(nèi)容字體
? ? CCLabelTTF* text=CCLabelTTF::create(content,FONT_NAME, size);
? ??
? ? text->setColor(Color::IntTranColor3B(contentColor));
? ??
? ? border->addChild(text);
? ??
? ? //內(nèi)容字體置中放在邊字體上
? ? text->setAnchorPoint(ccp(0.5f,0.5f));
? ? text->setPosition(ccp(border->getContentSize().width/2,border->getContentSize().height/2));
? ??
? ? return border;
}
{
? ? //通過將兩個(gè)不同尺寸的字體疊在一起來實(shí)現(xiàn)描邊的效果
? ??
? ? //邊字體
? ? CCLabelTTF* border=CCLabelTTF::create(content, FONT_NAME, size+4);
? ??
? ? border->setColor(Color::IntTranColor3B(borderColor));
? ??
? ? //內(nèi)容字體
? ? CCLabelTTF* text=CCLabelTTF::create(content,FONT_NAME, size);
? ??
? ? text->setColor(Color::IntTranColor3B(contentColor));
? ??
? ? border->addChild(text);
? ??
? ? //內(nèi)容字體置中放在邊字體上
? ? text->setAnchorPoint(ccp(0.5f,0.5f));
? ? text->setPosition(ccp(border->getContentSize().width/2,border->getContentSize().height/2));
? ??
? ? return border;
}
總結(jié)
以上是生活随笔為你收集整理的Cocos2d-x创建包边字的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。