Skip to content

Commit ea56b86

Browse files
committed
Merge pull request cocos2d#20 from VisualSJ/Iss2416_RefactorRenderer
Issue cocos2d#2416: Fixed LabelBMFont
2 parents 0556740 + 6dea9ac commit ea56b86

File tree

4 files changed

+67
-73
lines changed

4 files changed

+67
-73
lines changed

cocos2d/labels/CCLabelAtlas.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ cc.LabelAtlas = cc.AtlasNode.extend(/** @lends cc.LabelAtlas# */{
163163
*/
164164
setColor: function (color3) {
165165
cc.AtlasNode.prototype.setColor.call(this, color3);
166-
this.updateAtlasValues();
166+
this._renderCmd.updateAtlasValues();
167167
},
168168

169169
/**
@@ -199,7 +199,7 @@ cc.LabelAtlas = cc.AtlasNode.extend(/** @lends cc.LabelAtlas# */{
199199
this.setContentSize(len * this._itemWidth, this._itemHeight);
200200
this._renderCmd.setString(label);
201201

202-
this.updateAtlasValues();
202+
this._renderCmd.updateAtlasValues();
203203
this.quadsToDraw = len;
204204
},
205205

cocos2d/labels/CCLabelBMFont.js

Lines changed: 40 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -294,12 +294,12 @@ cc.LabelBMFont = cc.SpriteBatchNode.extend(/** @lends cc.LabelBMFont# */{
294294
*/
295295
updateDisplayedOpacity: function (parentOpacity) {
296296
var cmd = this._renderCmd;
297-
this._displayedOpacity = this._realOpacity * parentOpacity / 255.0;
298-
var locChildren = this._children;
299-
for (var i = 0; i < locChildren.length; i++) {
300-
cmd._updateChildrenDisplayedOpacity(locChildren[i]);
301-
}
302-
this._changeTextureColor();
297+
cmd._displayedOpacity = this._realOpacity * parentOpacity / 255.0;
298+
// var locChildren = this._children;
299+
// for (var i = 0; i < locChildren.length; i++) {
300+
// cmd._updateChildrenDisplayedOpacity(locChildren[i]);
301+
// }
302+
// this._changeTextureColor();
303303
},
304304

305305
/**
@@ -345,17 +345,17 @@ cc.LabelBMFont = cc.SpriteBatchNode.extend(/** @lends cc.LabelBMFont# */{
345345
*/
346346
updateDisplayedColor: function (parentColor) {
347347
var cmd = this._renderCmd;
348-
var locDispColor = this._displayedColor;
348+
var locDispColor = cmd._displayedColor;
349349
var locRealColor = this._realColor;
350350
locDispColor.r = locRealColor.r * parentColor.r / 255.0;
351351
locDispColor.g = locRealColor.g * parentColor.g / 255.0;
352352
locDispColor.b = locRealColor.b * parentColor.b / 255.0;
353353

354-
var locChildren = this._children;
355-
for (var i = 0; i < locChildren.length; i++) {
356-
cmd._updateChildrenDisplayedColor(locChildren[i]);
357-
}
358-
this._changeTextureColor();
354+
// var locChildren = this._children;
355+
// for (var i = 0; i < locChildren.length; i++) {
356+
// cmd._updateChildrenDisplayedColor(locChildren[i]);
357+
// }
358+
// this._changeTextureColor();
359359
},
360360

361361
_changeTextureColor: function () {
@@ -440,8 +440,8 @@ cc.LabelBMFont = cc.SpriteBatchNode.extend(/** @lends cc.LabelBMFont# */{
440440
cmd._displayedOpacity = self._realOpacity = 255;
441441
cmd._displayedColor = cc.color(255, 255, 255, 255);
442442
self._realColor = cc.color(255, 255, 255, 255);
443-
self._cascadeOpacityEnabled = true;
444-
self._cascadeColorEnabled = true;
443+
this._cascadeColorEnabled = true;
444+
this._cascadeOpacityEnabled = true;
445445

446446
self._contentSize.width = 0;
447447
self._contentSize.height = 0;
@@ -513,7 +513,18 @@ cc.LabelBMFont = cc.SpriteBatchNode.extend(/** @lends cc.LabelBMFont# */{
513513

514514
var fontChar = self.getChildByTag(i);
515515

516-
fontChar = this._renderCmd._updateTexture(fontChar, locTexture, rect, i, key);
516+
if(!fontChar){
517+
fontChar = new cc.Sprite();
518+
fontChar.initWithTexture(locTexture, rect, false);
519+
fontChar._newTextureWhenChangeColor = true;
520+
this.addChild(fontChar, 0, i);
521+
}else{
522+
this._renderCmd._updateCharTexture(fontChar, rect, key);
523+
}
524+
525+
// Apply label properties
526+
fontChar.opacityModifyRGB = this._opacityModifyRGB;
527+
this._renderCmd._updateCharColorAndOpacity(fontChar);
517528

518529
var yOffset = locCfg.commonHeight - fontDef.yOffset;
519530
var fontPos = cc.p(nextFontPositionX + fontDef.xOffset + fontDef.rect.width * 0.5 + kerningAmount,
@@ -1000,18 +1011,20 @@ cc.LabelBMFont = cc.SpriteBatchNode.extend(/** @lends cc.LabelBMFont# */{
10001011
}
10011012
});
10021013

1003-
var _p = cc.LabelBMFont.prototype;
1004-
cc.EventHelper.prototype.apply(_p);
1005-
1006-
/** @expose */
1007-
_p.string;
1008-
cc.defineGetterSetter(_p, "string", _p.getString, _p._setStringForSetter);
1009-
/** @expose */
1010-
_p.boundingWidth;
1011-
cc.defineGetterSetter(_p, "boundingWidth", _p._getBoundingWidth, _p.setBoundingWidth);
1012-
/** @expose */
1013-
_p.textAlign;
1014-
cc.defineGetterSetter(_p, "textAlign", _p._getAlignment, _p.setAlignment);
1014+
(function(){
1015+
var p = cc.LabelBMFont.prototype;
1016+
cc.EventHelper.prototype.apply(p);
1017+
1018+
/** @expose */
1019+
p.string;
1020+
cc.defineGetterSetter(p, "string", p.getString, p._setStringForSetter);
1021+
/** @expose */
1022+
p.boundingWidth;
1023+
cc.defineGetterSetter(p, "boundingWidth", p._getBoundingWidth, p.setBoundingWidth);
1024+
/** @expose */
1025+
p.textAlign;
1026+
cc.defineGetterSetter(p, "textAlign", p._getAlignment, p.setAlignment);
1027+
})();
10151028

10161029
/**
10171030
* creates a bitmap font atlas with an initial string and the FNT file

cocos2d/labels/CCLabelBMFontCanvasRenderCmd.js

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -33,39 +33,33 @@
3333
(function(){
3434
cc.LabelBMFont.CanvasRenderCmd = function(renderableObject){
3535
cc.SpriteBatchNode.CanvasRenderCmd.call(this, renderableObject);
36-
this._needDraw = false;
36+
this._needDraw = true;
3737
};
3838

3939
var proto = cc.LabelBMFont.CanvasRenderCmd.prototype = Object.create(cc.SpriteBatchNode.CanvasRenderCmd.prototype);
4040
proto.constructor = cc.LabelBMFont.CanvasRenderCmd;
4141

42-
proto._updateTexture = function(fontChar, locTexture, rect, i, key){
43-
var node = this._node;
44-
//var hasSprite = true;
45-
if (!fontChar) {
46-
fontChar = new cc.Sprite();
42+
proto.rendering = function(){
43+
void 0;
44+
};
4745

48-
fontChar.initWithTexture(locTexture, rect, false);
49-
fontChar._newTextureWhenChangeColor = true;
50-
node.addChild(fontChar, 0, i);
46+
proto._updateCharTexture = function(fontChar, rect, key){
47+
if (key === 32) {
48+
fontChar.setTextureRect(rect, false, cc.size(0, 0));
5149
} else {
52-
if (key === 32) {
53-
fontChar.setTextureRect(rect, false, cc.size(0, 0));
54-
} else {
55-
// updating previous sprite
56-
fontChar.setTextureRect(rect, false);
57-
// restore to default in case they were modified
58-
fontChar.visible = true;
59-
}
50+
// updating previous sprite
51+
fontChar.setTextureRect(rect, false);
52+
// restore to default in case they were modified
53+
fontChar.visible = true;
6054
}
55+
};
6156

62-
// Apply label properties
63-
fontChar.opacityModifyRGB = node._opacityModifyRGB;
57+
proto._updateCharColorAndOpacity = function(fontChar){
6458
// Color MUST be set before opacity, since opacity might change color if OpacityModifyRGB is on
65-
cc.Node.prototype.updateDisplayedColor.call(fontChar, this._displayedColor);
66-
cc.Node.prototype.updateDisplayedOpacity.call(fontChar, this._displayedOpacity);
67-
68-
return fontChar;
59+
// cc.Node.prototype.updateDisplayedColor.call(fontChar, this._displayedColor);
60+
// cc.Node.prototype.updateDisplayedOpacity.call(fontChar, this._displayedOpacity);
61+
fontChar.updateDisplayedColor(this._displayedColor);
62+
fontChar.updateDisplayedOpacity(this._displayedOpacity);
6963
};
7064

7165
proto._updateFntFileTexture = function(){
@@ -137,7 +131,6 @@
137131

138132
proto._updateChildrenDisplayedOpacity = function(locChild){
139133
cc.Node.prototype.updateDisplayedOpacity.call(locChild, this._displayedOpacity);
140-
141134
};
142135

143136
proto._updateChildrenDisplayedColor = function(locChild){

cocos2d/labels/CCLabelBMFontWebGLRenderCmd.js

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -39,29 +39,17 @@
3939
var proto = cc.LabelBMFont.WebGLRenderCmd.prototype = Object.create(cc.SpriteBatchNode.WebGLRenderCmd.prototype);
4040
proto.constructor = cc.LabelBMFont.WebGLRenderCmd;
4141

42-
proto._updateTexture = function(fontChar, locTexture, rect, i){
43-
var node = this._node;
44-
//var hasSprite = true;
45-
if (!fontChar) {
46-
fontChar = new cc.Sprite();
47-
fontChar.initWithTexture(locTexture, rect, false);
48-
fontChar._newTextureWhenChangeColor = true;
49-
node.addChild(fontChar, 0, i);
50-
} else {
51-
// updating previous sprite
52-
fontChar.setTextureRect(rect, false);
53-
// restore to default in case they were modified
54-
fontChar.visible = true;
55-
}
56-
57-
58-
// Apply label properties
59-
fontChar.opacityModifyRGB = node._opacityModifyRGB;
42+
proto._updateCharTexture = function(fontChar, rect, key){
43+
// updating previous sprite
44+
fontChar.setTextureRect(rect, false);
45+
// restore to default in case they were modified
46+
fontChar.visible = true;
47+
};
48+
49+
proto._updateCharColorAndOpacity = function(fontChar){
6050
// Color MUST be set before opacity, since opacity might change color if OpacityModifyRGB is on
6151
fontChar.updateDisplayedColor(this._displayedColor);
6252
fontChar.updateDisplayedOpacity(this._displayedOpacity);
63-
64-
return fontChar;
6553
};
6654

6755
proto._updateFntFileTexture = function(){};

0 commit comments

Comments
 (0)