static CCRenderTexture* createStroke(CCSprite* label, int size, ccColor3B color, GLubyte opacity) { CCRenderTexture* rt = CCRenderTexture::create(label->getTexture()->getContentSize().width + size * 2, label->getTexture()->getContentSize().height+size * 2); CCPoint originalPos = label->getPosition(); ccColor3B originalColor = label->getColor(); GLubyte originalOpacity = label->getOpacity(); label->setColor(color); label->setOpacity(opacity); bool originalVisibility = label->isVisible(); ccBlendFunc originalBlend = label->getBlendFunc(); ccBlendFunc bf = {GL_SRC_ALPHA, GL_ONE}; label->setBlendFunc(bf); CCPoint bottomLeft = ccp( label->getTexture()->getContentSize().width * label->getAnchorPoint().x + size, label->getTexture()->getContentSize().height * label->getAnchorPoint().y + size); //原來沒有判斷AnchorPoint的寫法 // CCPoint positionOffset= ccp( - label->getTexture()->getContentSize().width / 2, // - label->getTexture()->getContentSize().height / 2); //SetAnchorPoint會影響到positionOffset,所以要做判斷 CCPoint positionOffset = CCPointZero; if(label->getAnchorPoint().x == 0.5f){ positionOffset.x = 0; }else if(label->getAnchorPoint().x == 0.0f){ positionOffset.x =- label->getTexture()->getContentSize().width / 2; }else{ positionOffset.x = label->getTexture()->getContentSize().width/2; } if(label->getAnchorPoint().y == 0.5f){ positionOffset.y = 0; }else if(label->getAnchorPoint().y == 0.0f){ positionOffset.y =- label->getTexture()->getContentSize().height / 2; }else{ positionOffset.y = label->getTexture()->getContentSize().height/2; } CCPoint position = ccpSub(originalPos, positionOffset); rt->begin(); for (int i=0; i<360 data-blogger-escaped-for="" data-blogger-escaped-i="" data-blogger-escaped-label-="" data-blogger-escaped-needs="" data-blogger-escaped-optimize="" data-blogger-escaped-should="" data-blogger-escaped-that="" data-blogger-escaped-you="" data-blogger-escaped-your="">setPosition( ccp(bottomLeft.x + sin(CC_DEGREES_TO_RADIANS(i))*size, bottomLeft.y + cos(CC_DEGREES_TO_RADIANS(i))*size) ); label->visit(); } rt->end(); label->setPosition(originalPos); label->setColor(originalColor); label->setBlendFunc(originalBlend); label->setVisible(originalVisibility); label->setOpacity(originalOpacity); rt->setPosition(position); //反踞齒 rt->getSprite()->getTexture()->setAntiAliasTexParameters(); return rt; } 360>
2/14/2014
[Cocos2D] 在文字旁加上黑邊 CCLabelTTF and CCSprite
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言