这个函数里加段代码,大家试试吧!
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);
}
//added to fix bug
if (_batchNodes.size() > 1)
{
_batchNodes.clear();
_batchNodes.push_back(this);
}
// end
if (_reusedLetter == nullptr)
{
_reusedLetter = Sprite::create();
_reusedLetter->setOpacityModifyRGB(_isOpacityModifyRGB);
_reusedLetter->retain();
_reusedLetter->setAnchorPoint(Vec2::ANCHOR_TOP_LEFT);
}
_reusedLetter->setBatchNode(this);
if (_fontAtlas)
{
_commonLineHeight = _fontAtlas->getCommonLineHeight();
_contentDirty = true;
}
#if CC_TARGET_PLATFORM != CC_PLATFORM_WP8
_useDistanceField = distanceFieldEnabled;
#else
// some older Windows Phones cannot run the ccShader_Label_df.frag program
// so we must disable distance field
_useDistanceField = false;
#endif
_useA8Shader = useA8Shader;
if (_currentLabelType != LabelType::TTF)
{
_currLabelEffect = LabelEffect::NORMAL;
updateShaderProgram();
}
}