mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-02 08:42:43 +08:00
Merge pull request #1553 from zilongshanren/add-bmfont-parser-cache
fix bmfont parser cache
This commit is contained in:
@@ -49,7 +49,9 @@ var BitmapFont = cc.Class({
|
||||
|
||||
fontSize: {
|
||||
default: -1
|
||||
}
|
||||
},
|
||||
//用来缓存 BitmapFont 解析之后的数据
|
||||
_fntConfig: null
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user