diff --git a/cocos2d/core/assets/CCBitmapFont.js b/cocos2d/core/assets/CCBitmapFont.js index 7ef7ca02fb..6007c5ef48 100644 --- a/cocos2d/core/assets/CCBitmapFont.js +++ b/cocos2d/core/assets/CCBitmapFont.js @@ -49,7 +49,9 @@ var BitmapFont = cc.Class({ fontSize: { default: -1 - } + }, + //用来缓存 BitmapFont 解析之后的数据 + _fntConfig: null } }); diff --git a/cocos2d/core/components/CCLabel.js b/cocos2d/core/components/CCLabel.js index 94ac5d2601..5100aa9b1f 100644 --- a/cocos2d/core/components/CCLabel.js +++ b/cocos2d/core/components/CCLabel.js @@ -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); diff --git a/cocos2d/core/label/CCSGLabel.js b/cocos2d/core/label/CCSGLabel.js index 92c422beb9..fdf73d3fa1 100644 --- a/cocos2d/core/label/CCSGLabel.js +++ b/cocos2d/core/label/CCSGLabel.js @@ -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;