Skip to content

Commit a57e049

Browse files
committed
Merge pull request #2380 from dingpinglv/develop
Fixed a bug of TextureRenderCmdCanvas
2 parents c6bfd6e + 1cdd7ad commit a57e049

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

cocos2d/core/renderer/RendererCanvas.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,7 @@ if (cc._renderType === cc._RENDER_TYPE_CANVAS) {
144144
locY = -node._offsetPosition.y - node._rect.height,
145145
locWidth = node._rect.width,
146146
locHeight = node._rect.height,
147-
image,
148-
curColor;
147+
image, curColor, contentSize;
149148

150149
var blendChange = (node._blendFuncStr !== "source"), alpha = (node._displayedOpacity / 255);
151150
/*if(cc.renderer.contextSession.globalAlpha !== alpha){
@@ -194,9 +193,12 @@ if (cc._renderType === cc._RENDER_TYPE_CANVAS) {
194193
);
195194
}
196195
} else {
197-
curColor = node._displayedColor;
198-
context.fillStyle = "rgba(" + curColor.r + "," + curColor.g + "," + curColor.b + "," + node._displayedOpacity + ")";
199-
context.fillRect(locX, locY, locWidth, locHeight);
196+
contentSize = node._contentSize;
197+
if(contentSize.width !== 0 && contentSize.height !== 0) {
198+
curColor = node._displayedColor;
199+
context.fillStyle = "rgba(" + curColor.r + "," + curColor.g + "," + curColor.b + "," + node._displayedOpacity + ")";
200+
context.fillRect(locX * scaleX, locY * scaleY, contentSize.width * scaleX, contentSize.height * scaleY);
201+
}
200202
}
201203
context.restore();
202204
} else {
@@ -231,9 +233,12 @@ if (cc._renderType === cc._RENDER_TYPE_CANVAS) {
231233
locHeight * scaleY);
232234
}
233235
} else {
234-
curColor = node._displayedColor;
235-
context.fillStyle = "rgba(" + curColor.r + "," + curColor.g + "," + curColor.b + "," + node._displayedOpacity + ")";
236-
context.fillRect(t.tx * scaleX + locX, -t.ty * scaleY + locY, locWidth, locHeight);
236+
contentSize = node._contentSize;
237+
if(contentSize.width !== 0 && contentSize.height !== 0) {
238+
curColor = node._displayedColor;
239+
context.fillStyle = "rgba(" + curColor.r + "," + curColor.g + "," + curColor.b + "," + node._displayedOpacity + ")";
240+
context.fillRect(locX * scaleX, locY * scaleY, contentSize.width * scaleX, contentSize.height * scaleY);
241+
}
237242
}
238243
if (blendChange)
239244
context.restore();

cocos2d/labels/CCLabelBMFont.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,8 @@ cc.LabelBMFont = cc.SpriteBatchNode.extend(/** @lends cc.LabelBMFont# */{
543543
//var hasSprite = true;
544544
if (!fontChar) {
545545
fontChar = new cc.Sprite();
546-
if ((key === 32) && (locContextType === cc._RENDER_TYPE_CANVAS)) rect = cc.rect(0, 0, 0, 0);
546+
if ((key === 32) && (locContextType === cc._RENDER_TYPE_CANVAS))
547+
rect = cc.rect(0, 0, 0, 0);
547548
fontChar.initWithTexture(locTexture, rect, false);
548549
fontChar._newTextureWhenChangeColor = true;
549550
self.addChild(fontChar, 0, i);

0 commit comments

Comments
 (0)