cocos2d-x 3.0이상에서 라벨사용시 폰트 자간 조절 하는 법



CCLabel.cpp


CCLabel.h


CCLabelTextFormatter.cpp


위3가지의 파일을 덮어 씌어 준 후 사용 하면 됩니다. 혹시 버젼이 변경 되어 다른 곳에서 에러가 날 시 


CCLabe.cpp 에 추가 Code


, _additionalKerning(0.0f)


void Label::setAdditionalKerning(float space)

{

    CCASSERT(_currentLabelType != LabelType::STRING_TEXTURE, "Not supported system font!");

    if (_additionalKerning != space)

    {

        _additionalKerning = space;

        _contentDirty = true;

    }

}


float Label::getAdditionalKerning() const

{

    CCASSERT(_currentLabelType != LabelType::STRING_TEXTURE, "Not supported system font!");

    

    return _additionalKerning;

}


CCLabel.h 에 추가 Code


    float _additionalKerning;


    void setAdditionalKerning(float space);

    /** Returns the additional kerning of this label

    @warning Not support system font

    @since v3.2.0

    */

    float getAdditionalKerning() const;


CCLabelTextFormatter.cpp 에 변경 Code

nextFontPositionX += charAdvance + kernings[i];

위 코드를 아래와 같이 변경

nextFontPositionX += charAdvance + kernings[i] + theLabel->_additionalKerning;


이상입니다.~


참고 : https://github.com/cocos2d/cocos2d-x/search?q=setAdditionalKerning&ref=cmdform



+ Recent posts