Merge pull request #1553 from zilongshanren/add-bmfont-parser-cache

fix bmfont parser cache
This commit is contained in:
Wang Nan
2017-03-16 11:29:30 +08:00
committed by GitHub
3 changed files with 18 additions and 5 deletions
+3 -1
View File
@@ -49,7 +49,9 @@ var BitmapFont = cc.Class({
fontSize: {
default: -1
}
},
//用来缓存 BitmapFont 解析之后的数据
_fntConfig: null
}
});
+5 -1
View File
@@ -490,7 +490,11 @@ var Label = cc.Class({
var sgNode;
if (this.font instanceof cc.BitmapFont) {
if (this.font.spriteFrame) {
sgNode = this._sgNode = new _ccsg.Label(this.string, this.font.fntDataStr, this.font.spriteFrame);
if (CC_JSB) {
sgNode = this._sgNode = new _ccsg.Label(this.string, this.font.fntDataStr, this.font.spriteFrame);
} else {
sgNode = this._sgNode = new _ccsg.Label(this.string, this.font.fntDataStr, this.font.spriteFrame, this.font);
}
} else {
cc.warnID(4011, this.font.name);
sgNode = this._sgNode = new _ccsg.Label(this.string);
+10 -3
View File
@@ -229,9 +229,10 @@ _ccsg.Label = _ccsg.Node.extend({
_isBold: false,
_isItalic: false,
_isUnderline: false,
_fontAsset: null,
//fontHandle it is a system font name, ttf file path or bmfont file path.
ctor: function(string, fontHandle, spriteFrame) {
ctor: function(string, fontHandle, spriteFrame, fontAsset) {
EventTarget.call(this);
fontHandle = fontHandle || "";
@@ -241,7 +242,7 @@ _ccsg.Label = _ccsg.Node.extend({
}
this._string = string;
this._fontAsset = fontAsset;
_ccsg.Node.prototype.ctor.call(this);
this.setAnchorPoint(cc.p(0.5, 0.5));
_ccsg.Node.prototype.setContentSize.call(this, cc.size(128, 128));
@@ -1301,7 +1302,13 @@ cc.BMFontHelper = {
var self = this;
this._resetBMFont();
self._config = FntLoader.parseFnt(fntDataStr);
var fntConfig = this._fontAsset._fntConfig;
if (fntConfig) {
self._config = fntConfig;
} else {
self._config = FntLoader.parseFnt(fntDataStr);
this._fontAsset._fntConfig = self._config;
}
self._createFontChars();
self._spriteFrame = spriteFrame;