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
}