cocos2d-x CCLabelTTF 描边
2013-10-17 13:26
369 查看
原文地址:CCLabelTTF 描边">cocos2d-x CCLabelTTF 描边作者:王烁
CCLabelTTF 描边" TITLE="[转载]cocos2d-x CCLabelTTF 描边" />
bool HelloWorld::init()
{
//////////////////////////////
// 1. super init first
if (
!CCLayer::init() )
{
return false;
}
/////////////////////////////
// 2. add a menu item with "X" image, which is clicked to quit the
program
// you may
modify it.
// add a "close" icon to exit the progress. it's an autorelease
object
CCMenuItemImage *pCloseItem
= CCMenuItemImage::itemFromNormalImage(
"CloseNormal.png",
"CloseSelected.png",
this,
menu_selector(HelloWorld::menuCloseCallback)
);
pCloseItem->setPosition( ccp(CCDirector::sharedDirector()->getWinSize().width - 20, 20)
);
// create menu, it's an autorelease object
CCMenu* pMenu = CCMenu::menuWithItems(pCloseItem, NULL);
pMenu->setPosition( CCPointZero );
this->addChild(pMenu, 1);
CCSize size
= CCDirector::sharedDirector()->getWinSize();
CCLabelTTF* pLabel
= CCLabelTTF::labelWithString("http://blog.sina.com.cn/iphonewangshuo",CCSizeMake(360, 100),CCTextAlignmentLeft,"Georgia-BoldItalic", 24);
pLabel->setPosition( ccp(size.width / 2,
size.height/2) );
pLabel->setColor(ccYELLOW);
CCRenderTexture *stroke=this->createStroke(pLabel,2, ccRED);
this->addChild(stroke);
// add the label as a child to this layer
this->addChild(pLabel);
pLabel->setPosition( ccp(size.width / 2+2,
size.height/2) );
// add "HelloWorld" splash screen"
return true;
}
CCRenderTexture* HelloWorld::createStroke(CCLabelTTF*lable,float size,ccColor3B cor)
{
CCRenderTexture*rt=CCRenderTexture::renderTextureWithWidthAndHeight(lable->getTexture()->getContentSize().width,
lable->getTexture()->getContentSize().height+size*2);
CCPoint originalPos
= lable->getPosition();
ccColor3B originalColor
= lable->getColor();
bool originalVisibility
=lable->getIsVisible();
lable->setColor(cor);
lable->setIsVisible(true);
ccBlendFunc originalBlend
= lable->getBlendFunc();
ccBlendFunc blendFunc1
= { GL_SRC_ALPHA, GL_ONE };
lable->setBlendFunc(blendFunc1);
float aa=lable->getTexture()->getContentSize().width*lable->getAnchorPoint().x+size;
float bb=lable->getTexture()->getContentSize().height*lable->getAnchorPoint().y+size;
CCPoint bottomLeft=ccp(aa,
bb);
float aaa=lable->getTexture()->getContentSize().width*lable->getAnchorPoint().x-
lable->getTexture()->getContentSize().width/2;
float bbb=lable->getTexture()->getContentSize().height*lable->getAnchorPoint().y-
lable->getTexture()->getContentSize().height/2;
CCPoint positionOffset=ccp(aaa,bbb);
CCPoint position=ccpSub(originalPos,
positionOffset);
rt->begin();
for (int i=0; i<</span>360; i+=30) // you should
optimize that for your needs
{
lable->setPosition(ccp(bottomLeft.x+sin(CC_DEGREES_TO_RADIANS(i)*size),
bottomLeft.y+cos(CC_DEGREES_TO_RADIANS(i)*size)));
lable->visit();
}
rt->end();
lable->setPosition(originalPos);
lable->setColor(originalColor);
lable->setBlendFunc(originalBlend);
lable->setIsVisible(originalVisibility);
rt->setPosition(position);
return rt;
}
void HelloWorld::menuCloseCallback(CCObject*
pSender)
{
CCDirector::sharedDirector()->end();
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
exit(0);
#endif
}
CCLabelTTF 描边" TITLE="[转载]cocos2d-x CCLabelTTF 描边" />
bool HelloWorld::init()
{
//////////////////////////////
// 1. super init first
if (
!CCLayer::init() )
{
return false;
}
/////////////////////////////
// 2. add a menu item with "X" image, which is clicked to quit the
program
// you may
modify it.
// add a "close" icon to exit the progress. it's an autorelease
object
CCMenuItemImage *pCloseItem
= CCMenuItemImage::itemFromNormalImage(
"CloseNormal.png",
"CloseSelected.png",
this,
menu_selector(HelloWorld::menuCloseCallback)
);
pCloseItem->setPosition( ccp(CCDirector::sharedDirector()->getWinSize().width - 20, 20)
);
// create menu, it's an autorelease object
CCMenu* pMenu = CCMenu::menuWithItems(pCloseItem, NULL);
pMenu->setPosition( CCPointZero );
this->addChild(pMenu, 1);
CCSize size
= CCDirector::sharedDirector()->getWinSize();
CCLabelTTF* pLabel
= CCLabelTTF::labelWithString("http://blog.sina.com.cn/iphonewangshuo",CCSizeMake(360, 100),CCTextAlignmentLeft,"Georgia-BoldItalic", 24);
pLabel->setPosition( ccp(size.width / 2,
size.height/2) );
pLabel->setColor(ccYELLOW);
CCRenderTexture *stroke=this->createStroke(pLabel,2, ccRED);
this->addChild(stroke);
// add the label as a child to this layer
this->addChild(pLabel);
pLabel->setPosition( ccp(size.width / 2+2,
size.height/2) );
// add "HelloWorld" splash screen"
return true;
}
CCRenderTexture* HelloWorld::createStroke(CCLabelTTF*lable,float size,ccColor3B cor)
{
CCRenderTexture*rt=CCRenderTexture::renderTextureWithWidthAndHeight(lable->getTexture()->getContentSize().width,
lable->getTexture()->getContentSize().height+size*2);
CCPoint originalPos
= lable->getPosition();
ccColor3B originalColor
= lable->getColor();
bool originalVisibility
=lable->getIsVisible();
lable->setColor(cor);
lable->setIsVisible(true);
ccBlendFunc originalBlend
= lable->getBlendFunc();
ccBlendFunc blendFunc1
= { GL_SRC_ALPHA, GL_ONE };
lable->setBlendFunc(blendFunc1);
float aa=lable->getTexture()->getContentSize().width*lable->getAnchorPoint().x+size;
float bb=lable->getTexture()->getContentSize().height*lable->getAnchorPoint().y+size;
CCPoint bottomLeft=ccp(aa,
bb);
float aaa=lable->getTexture()->getContentSize().width*lable->getAnchorPoint().x-
lable->getTexture()->getContentSize().width/2;
float bbb=lable->getTexture()->getContentSize().height*lable->getAnchorPoint().y-
lable->getTexture()->getContentSize().height/2;
CCPoint positionOffset=ccp(aaa,bbb);
CCPoint position=ccpSub(originalPos,
positionOffset);
rt->begin();
for (int i=0; i<</span>360; i+=30) // you should
optimize that for your needs
{
lable->setPosition(ccp(bottomLeft.x+sin(CC_DEGREES_TO_RADIANS(i)*size),
bottomLeft.y+cos(CC_DEGREES_TO_RADIANS(i)*size)));
lable->visit();
}
rt->end();
lable->setPosition(originalPos);
lable->setColor(originalColor);
lable->setBlendFunc(originalBlend);
lable->setIsVisible(originalVisibility);
rt->setPosition(position);
return rt;
}
void HelloWorld::menuCloseCallback(CCObject*
pSender)
{
CCDirector::sharedDirector()->end();
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
exit(0);
#endif
}
相关文章推荐
- cocos2d实现CCLabelTTF真正字体描边效果
- [置顶] cocos2d实现CCLabelTTF真正字体描边效果
- cocos2d实现CCLabelTTF真正字体描边效果
- cocos2d-x 利用CCLabelTTF制作文字描边与阴影效果的实现方法
- cocos2d-x CCLabelTTF文字描边与阴影效果
- cocos2d-x 利用CCLabelTTF制作文字描边与阴影效果的实现方法
- cocos2d-x 利用CCLabelTTF制作文字描边与阴影效果的实现方法
- cocos2d-x 利用CCLabelTTF制作文字描边与阴影效果的实现方法
- 大话cocos2d中的文字显示(CCLabelTTF、CCLabelBMFont和CCLabelAtlas)
- Cocos2d-x跨平台 Andro…
- Cocos2d-x CCEditBox & CCTextFieldTTF
- cocos2d学习笔记(四)CCLabelTTF和CCLabelBMFont
- cocos2d 中添加显示文字的三种方式(CCLabelTTF 、CCLabelBMFont 和CCLabelAtlas)
- Cocos2d-x+ vs2010环境配置图…
- Cocos2d-x win下环境搭建及其介绍
- cocos2d 中加入显示文字的三种方式(CCLabelTTF 、CCLabelBMFont 和CCLabelAtlas)
- CCLabelTTF制造文字描边
- Cocos2d-x 3.0beta与windows&…
- cocos2d 中添加显示文字的三种方式(CCLabelTTF 、CCLabelBMFont 和CCLabelAtlas)
- cocos2d-x 2.1下使用CCLabelTTF显示汉字的问题