在CCLabel.cpp文件中加几行代码
void Label::setFontAtlas(FontAtlas* atlas,bool distanceFieldEnabled /* = false /, bool useA8Shader / = false */)
{
if (atlas == _fontAtlas)
{
FontAtlasCache::releaseFontAtlas(atlas);
return;
}
if (_fontAtlas)
{
FontAtlasCache::releaseFontAtlas(_fontAtlas);
_fontAtlas = nullptr;
}
_fontAtlas = atlas;
if (_textureAtlas)
{
_textureAtlas->setTexture(_fontAtlas->getTexture(0));
}
else
{
SpriteBatchNode::initWithTexture(_fontAtlas->getTexture(0), 30);
}
//--------------------------------这里是新添加的-----------------------
if (_batchNodes.size() > 1)
{
_batchNodes.clear();
batchNodes.pushback(this);
}
//----------------------------------------------------------------
if (_reusedLetter == nullptr)
{
_reusedLetter = Sprite::create();
reusedLetter->setOpacityModifyRGB(isOpacityModifyRGB);
_reusedLetter->retain();
reusedLetter->setAnchorPoint(Vec2::ANCHORTOP_LEFT);
}
_reusedLetter->setBatchNode(this);
if (_fontAtlas)
{
_commonLineHeight = _fontAtlas->getCommonLineHeight();
_contentDirty = true;
}
_useDistanceField = distanceFieldEnabled;
_useA8Shader = useA8Shader;
if (_currentLabelType != LabelType::TTF)
{
_currLabelEffect = LabelEffect::NORMAL;
updateShaderProgram();
}
}