2.0.1正式版字体bug(导致字体报错)及原因

// ttf.js 210行开始 _updateFontFamly 方法中
                    cc.loader.load(item, function (err) {
                        var localDownloadPath = "url('" + loadRuntime().env.USER_DATA_PATH + "/" + url + "')";
                        _fontFamily = jsb.loadFont(loaderFontFamily, localDownloadPath);
                        if (!_fontFamily) {
                            _fontFamily = 'Arial';
                        }
                        CustomFontLoader._fontCache[url] = _fontFamily;
                        comp._updateRenderData();
                    });

CustomFontLoader._fontCache[url] 保存的是字符串 ‘Arial’

// text-util.js 84行 _checkFontLoaded方法中
            var fontDescriptor = this._fontCache[k];
            if(fontDescriptor.isLoaded() || !fontDescriptor._isLoadWithCSS) {
                continue;
            }

取出来的 fontDescriptor 实际上是 ‘Arial’,没有 isLoaded 方法,这里就会报错

TypeError: fontDescriptor.isLoaded is not a function

1赞

@panda

没人理会,提了个issue

版本 2.0.1,
在微信开发者工具上也遇到了这个问题:

先是警告:当前版本暂不支持此加载自定义字体(汉仪中圆简.ttf)。
然后是下面的报错:

gameThirdScriptError
fontDescriptor.isLoaded is not a function;at setInterval callback function
TypeError: fontDescriptor.isLoaded is not a function
at Object._checkFontLoaded (http://127.0.0.1:39850/game/cocos2d-js.96d09.js:43223:30)
at http://127.0.0.1:39850/game/dev/WAGame.js:4:14604
at http://127.0.0.1:39850/game/dev/WAGame.js:3:22261

感谢回复,该 bug 已经在 2.0.2 版本进行修复了,可等待新版本


还是有这个问题

creator2.0.10里,字体也有BUG,在creator里字体设置为Arial就没问题,但是如果设置成黑体或者雅黑什么的,模拟器运行会有显示错误。

不能设置黑体中文,需要去查他的英语版例如 黑体 => SimHei

https://xuui.net/ui-design/english-name-of-chinese-characters-table.html