cocos2dx 描上边框

前端之家收集整理的这篇文章主要介绍了cocos2dx 描上边框前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

分类Cocos2d-x 1270人阅读 评论(0) 收藏 举报

Sprite描上边框

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;
    }
原文链接:https://www.f2er.com/cocos2dx/345279.html

猜你在找的Cocos2d-x相关文章