Skip to content

Commit 3378ce7

Browse files
committed
Merge pull request cocos2d#1 from zilongshanren/addBMFontSupport
fix a few issues of CCLabel.js
2 parents 7027d83 + fdad0a7 commit 3378ce7

File tree

1 file changed

+42
-30
lines changed

1 file changed

+42
-30
lines changed

cocos2d/labels/CCLabel.js

+42-30
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/*global cc */
2+
13
/****************************************************************************
24
Copyright (c) 2015 Chukong Technologies Inc.
35
@@ -22,7 +24,7 @@
2224
THE SOFTWARE.
2325
****************************************************************************/
2426

25-
EventTarget = require("../cocos2d/core/event/event-target");
27+
var EventTarget = require("../cocos2d/core/event/event-target");
2628

2729
cc.Label = cc.Node.extend({
2830
_hAlign: 0, //0 left, 1 center, 2 right
@@ -31,45 +33,45 @@ cc.Label = cc.Node.extend({
3133
_fontSize: 20,
3234
_overFlow: 0, //0 clamp, 1 shrink 2, resize to content
3335
_isWrapText: true,
34-
_spacingX : 0,
35-
_spacingY : 0,
36+
_spacingX: 0,
37+
_spacingY: 0,
3638

3739
_labelSkinDirty: true,
3840
_labelIsTTF: true,
3941
_fontHandle: "",
4042

4143
//fontHandle it is a font name or bmfont file.
42-
ctor : function(fontHandle, isTTF) {
44+
ctor: function(fontHandle, isTTF) {
4345
fontHandle = fontHandle || "";
4446
this._fontHandle = fontHandle;
4547
isTTF = isTTF || true;
4648
this._labelIsTTF = isTTF;
4749
cc.Node.prototype.ctor.call(this);
48-
this.setContentSize(cc.size(128,128));
50+
this.setContentSize(cc.size(128, 128));
4951
},
5052

51-
setHorizontalAlign: function (align) {
52-
if(this._hAlign === align) return;
53+
setHorizontalAlign: function(align) {
54+
if (this._hAlign === align) return;
5355
this._hAlign = align;
5456
this._notifyLabelSkinDirty();
5557
},
5658

57-
getHorizontalAlign: function () {
59+
getHorizontalAlign: function() {
5860
return this._hAlign;
5961
},
6062

61-
setVerticalAlign: function (align) {
62-
if(this._vAlign === align) return;
63+
setVerticalAlign: function(align) {
64+
if (this._vAlign === align) return;
6365
this._vAlign = align;
6466
this._notifyLabelSkinDirty();
6567
},
6668

67-
getVerticalAlign: function () {
69+
getVerticalAlign: function() {
6870
return this._vAlign;
6971
},
7072

7173
setString: function(string) {
72-
if(this._string === string) return;
74+
if (this._string === string) return;
7375
this._string = string;
7476
this._notifyLabelSkinDirty();
7577
},
@@ -79,7 +81,7 @@ cc.Label = cc.Node.extend({
7981
},
8082

8183
enableWrapText: function(enabled) {
82-
if(this._isWrapText === enabled) return;
84+
if (this._isWrapText === enabled) return;
8385
this._isWrapText = enabled;
8486
this._notifyLabelSkinDirty();
8587
},
@@ -89,7 +91,7 @@ cc.Label = cc.Node.extend({
8991
},
9092

9193
setFontSize: function(fntSize) {
92-
if(this._fontSize === fntSize) return;
94+
if (this._fontSize === fntSize) return;
9395
this._fontSize = fntSize;
9496
this._notifyLabelSkinDirty();
9597
},
@@ -99,7 +101,7 @@ cc.Label = cc.Node.extend({
99101
},
100102

101103
setOverflow: function(overflow) {
102-
if(this._overFlow === overflow) return;
104+
if (this._overFlow === overflow) return;
103105
this._overFlow = overflow;
104106
this._notifyLabelSkinDirty();
105107
},
@@ -109,14 +111,14 @@ cc.Label = cc.Node.extend({
109111
},
110112

111113
setSpacingX: function(spacing) {
112-
if(this._spacingX === spacing) return;
113-
this._spacingX == spacing;
114+
if (this._spacingX === spacing) return;
115+
this._spacingX = spacing;
114116
this._notifyLabelSkinDirty();
115117
},
116118

117119
setSpacingY: function(spacing) {
118-
if(this._spacingY === spacing) return;
119-
this._spacingY == spacing;
120+
if (this._spacingY === spacing) return;
121+
this._spacingY = spacing;
120122
this._notifyLabelSkinDirty();
121123
},
122124

@@ -128,33 +130,43 @@ cc.Label = cc.Node.extend({
128130
return this._spacingY;
129131
},
130132

131-
setContentSize : function(size){
132-
if (cc.sizeEqualToSize(this._contentSize,size))
133-
{
133+
setContentSize: function(size) {
134+
if (cc.sizeEqualToSize(this._contentSize, size)) {
134135
return;
135136
}
136137
cc.Node.prototype.setContentSize.call(this, size);
137138
this._notifyLabelSkinDirty();
138139
},
139140

140-
_notifyLabelSkinDirty : function() {
141+
_notifyLabelSkinDirty: function() {
141142
this._labelSkinDirty = true;
142143
this._renderCmd.setDirtyFlag(cc.Node._dirtyFlags.textDirty);
143144
},
144-
_createRenderCmd: function () {
145+
_createRenderCmd: function() {
145146

146-
if(this._labelIsTTF) {
147+
if (this._labelIsTTF) {
147148
if (cc._renderType === cc.game.RENDER_TYPE_WEBGL)
148149
return new cc.Label.TTFWebGLRenderCmd(this);
149150
else
150151
return new cc.Label.TTFCanvasRenderCmd(this);
151-
}
152-
else {
152+
} else {
153153
//todo:add label bmfont here
154154
}
155155
}
156156
});
157157

158-
cc.Label.HorizontalAlign = {LEFT: 0, CENTER: 1, RIGHT: 2};
159-
cc.Label.VerticalAlign = {BOTTOM: 0, CENTER: 1, TOP: 2};
160-
cc.Label.Overflow = {CLAMP: 0, SHRINK: 1, RESIZE: 2};
158+
cc.Label.HorizontalAlign = {
159+
LEFT: 0,
160+
CENTER: 1,
161+
RIGHT: 2
162+
};
163+
cc.Label.VerticalAlign = {
164+
BOTTOM: 0,
165+
CENTER: 1,
166+
TOP: 2
167+
};
168+
cc.Label.Overflow = {
169+
CLAMP: 0,
170+
SHRINK: 1,
171+
RESIZE: 2
172+
};

0 commit comments

Comments
 (0)