cocos2dx-3.2 ttf字体显示异常

这个函数里加段代码,大家试试吧!
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();
}

}

就是这一段
//added to fix bug
if (_batchNodes.size() > 1)
{
_batchNodes.clear();
_batchNodes.push_back(this);
}
// end

楼上的,貌似不行哦

我的就是这样修好的

我按这样也修好了,请问下楼上,怎么找到解决方案的呢?这块代码也太难看懂了,还得在看懂的基础上修bug,这难度相当大了

3.8的怎么改

3.8版本的怎么改,求解

官方为什么一直不解决呀

刚解决掉文字丢失的问题,我的情况是由于在非cocos Thread中操作ui导致的

在@子龙山人的帮助下,解决了这个问题,原因是由于ttf是gb2312编码的原因,cocos引擎在将gb2312转unicode时异常导致,解决办法是:
CCFontAltas.cpp找到 conversionU16TOGB2312 这个函数
将:
_iconv = iconv_open(“gb2312”, “UTF-16LE”);
修改为:
_iconv = iconv_open(“GBK//TRANSLIT”, “UTF-16LE”);
即可。

整个项目都没有找到这个方法。请问你确定有这么个东西么

cocos2dx 3.16也遇到了这个坑,卧槽

我也遇到类似的问题,不过我是在尝试将cocos2x接入到QT中出现的,我出现这个问题是因为线程导致的,具体解决办法可以参考: Cocos2dx接入Qt后,Text使用TTF显示异常 - 掘金

现在还在使用cocos2dx啊~

是啊,挺难受的,但是项目挣钱啊

赚钱就够了~ :nerd_face:
原来大佬写了那么多的插件~ 高手高手~