91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

cocos2d-x字體描邊Label

發布時間:2020-06-10 01:20:24 來源:網絡 閱讀:2039 作者:bailu_1901 欄目:游戲開發

參考http://blog.sina.com.cn/s/blog_a502f1a30101hvh7.html

頭文件

#include "cocos2d.h"
class CCLabelTTFStroke : public cocos2d::CCNode
{
public:
    CCLabelTTFStroke();
    ~CCLabelTTFStroke();
            
public:
    static CCLabelTTFStroke* create(const char *string, const char *fontName, float fontSize, float strokeSize,const cocos2d::ccColor3B&      colStroke = cocos2d::ccc3(0, 0, 0), cocos2d::CCTextAlignment hAlignment=cocos2d::kCCTextAlignmentCenter, cocos2d::CCVerticalTextAlignment vAlignment=cocos2d::kCCVerticalTextAlignmentTop);
    bool initWithString(const char *label, const char *fontName, float fontSize, float fStrokeSize, const cocos2d::ccColor3B&      colStroke, cocos2d::CCTextAlignment hAlignment, cocos2d::CCVerticalTextAlignment vAlignment);
            
public:
    void setColor(const cocos2d::ccColor3B& color3);
    void setString(const char *label);
    void setStrokeColor(cocos2d::ccColor3B col){ m_colStroke = col; updateStroke(); }
    void setStrokeSize(float StrokeSize){ m_fStrokeSize = StrokeSize; updateStroke();}
            
protected:
    void updateStroke();
            
private:
    float                   m_fStrokeSize;
    cocos2d::ccColor3B      m_colStroke;
    cocos2d::CCSprite*      m_sprite;
    cocos2d::CCLabelTTF*    m_label;
};

源文件

#include "CCStrokeLabel.h"
USING_NS_CC;
CCLabelTTFStroke::CCLabelTTFStroke()
:m_colStroke(ccc3(0,0,0))
,m_fStrokeSize(1.0f)
,m_sprite(NULL)
,m_label(NULL)
{}
CCLabelTTFStroke::~CCLabelTTFStroke()
{
    CC_SAFE_RELEASE_NULL(m_label);
}
bool CCLabelTTFStroke::initWithString(const char *string, const char *fontName, float fontSize, float strokeSize,const cocos2d::ccColor3B& colStroke, CCTextAlignment hAlignment,CCVerticalTextAlignment vAlignment)
{
    m_fStrokeSize = strokeSize;
    m_colStroke = colStroke;
    m_label = CCLabelTTF::create(string, fontName, fontSize, CCSizeZero,hAlignment,vAlignment);
    m_label->retain();
      
    updateStroke();
      
    return true;
}
CCLabelTTFStroke* CCLabelTTFStroke::create(const char *string, const char *fontName, float fontSize, float fStrokeSize,const cocos2d::ccColor3B& colStroke ,CCTextAlignment hAlignment,CCVerticalTextAlignment vAlignment)
{
    CCLabelTTFStroke *pRet = new CCLabelTTFStroke();
    if(pRet && pRet->initWithString(string, fontName, fontSize, fStrokeSize, colStroke, hAlignment, vAlignment))
    {
        pRet->autorelease();
        return pRet;
    }
    CC_SAFE_DELETE(pRet);
    return NULL;
}
void CCLabelTTFStroke::updateStroke()
{
    if (m_sprite)
    {
        removeChild(m_sprite, true);
    }
      
    CCSize textureSize = m_label->getContentSize();
    textureSize.width += 2 * m_fStrokeSize;
    textureSize.height += 2 * m_fStrokeSize;
    //call to clear error
    glGetError();
    CCRenderTexture *rt = CCRenderTexture::create(textureSize.width, textureSize.height);
    if(!rt)
    {
        CCLOG("create render texture failed !!!!");
        addChild(m_label);
        return;
    }
      
    ccColor3B col = m_label->getColor();
    m_label->setColor(m_colStroke);
      
    ccBlendFunc originalBlend = m_label->getBlendFunc();
    ccBlendFunc func = { GL_SRC_ALPHA, GL_ONE};
    m_label->setBlendFunc(func);
      
    m_label->setAnchorPoint(ccp(0.5, 0.5));
      
    rt->begin();
    for(int i = 0; i < 360; i += 15)
    {
        float r = CC_DEGREES_TO_RADIANS(i);
        m_label->setPosition(ccp(
                               textureSize.width * 0.5f + sin(r) * m_fStrokeSize,
                               textureSize.height * 0.5f + cos(r) * m_fStrokeSize));
        m_label->visit();
    }
      
    m_label->setColor(col);
    m_label->setBlendFunc(originalBlend);
    m_label->setPosition(ccp(textureSize.width * 0.5f, textureSize.height * 0.5f));
    m_label->visit();
    rt->end();
      
    CCTexture2D *texture = rt->getSprite()->getTexture();
    texture->setAliasTexParameters();
    m_sprite = CCSprite::createWithTexture(rt->getSprite()->getTexture());
    setContentSize(m_sprite->getContentSize());
    m_sprite->setAnchorPoint(ccp(0, 0));
    m_sprite->setPosition(ccp(0, 0));
    ((CCSprite *)m_sprite)->setFlipY(true);
    addChild(m_sprite);
}
void CCLabelTTFStroke::setString(const char *label)
{
    if (m_label)
    {
        if(0!=strcmp(label, m_label->getString()))
        {
            m_label->setString(label);
            updateStroke();
        }
    }
    else
    {
        CCLOG("ERROR:CCLabelTTFStroke::setString m_label=NULL");
    }
}
void CCLabelTTFStroke::setColor(const ccColor3B& color3)
{
    if (m_label)
    {
        ccColor3B col = m_label->getColor();
        if(color3.r!=col.r && color3.g!=col.g && color3.b!=col.b)
        {
            m_label->setColor(color3);
            updateStroke();
        }
    }
    else
    {
        CCLOG("ERROR:CCLabelTTFStroke::setColor m_label=NULL");
    }
}


向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

安平县| 凌海市| 永宁县| 江陵县| 文成县| 保定市| 旅游| 禹州市| 和林格尔县| 云梦县| 清水河县| 平乐县| 扎兰屯市| 竹山县| 平凉市| 英吉沙县| 三门峡市| 平塘县| 安西县| 凤山市| 建平县| 连南| 井研县| 南木林县| 聂拉木县| 新竹县| 武胜县| 中方县| 开化县| 涿鹿县| 什邡市| 南丰县| 广灵县| 丹江口市| 七台河市| 台南市| 宜都市| 伊宁县| 孟州市| 东光县| 邵武市|