Skip to content

Commit dd79c81

Browse files
committed
Merge pull request #2691 from dingpinglv/Iss2684_LabelBMFont
Fixed a bug of cc.Layer that its bake function doesn't work when the layer has a parent node
2 parents 397a5d3 + 471855f commit dd79c81

File tree

2 files changed

+10
-31
lines changed

2 files changed

+10
-31
lines changed

cocos2d/core/base-nodes/CCNodeCanvasRenderCmd.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ cc.Node.RenderCmd.prototype = {
252252
// transform for canvas
253253
var t = this.getNodeToParentTransform(),
254254
worldT = this._worldTransform; //get the world transform
255-
255+
this._cacheDirty = true;
256256
if (parentCmd) {
257257
var pt = parentCmd._worldTransform;
258258
// cc.AffineTransformConcat is incorrect at get world transform
@@ -447,7 +447,7 @@ cc.Node.RenderCmd.prototype = {
447447

448448
proto.setDirtyFlag = function (dirtyFlag) {
449449
cc.Node.RenderCmd.prototype.setDirtyFlag.call(this, dirtyFlag);
450-
this._setCacheDirty();
450+
this._setCacheDirty(); //TODO it should remove from here.
451451
if(this._cachedParent)
452452
this._cachedParent.setDirtyFlag(dirtyFlag);
453453
};

cocos2d/core/layers/CCLayerCanvasRenderCmd.js

+8-29
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555

5656
if (!this._bakeSprite){
5757
this._bakeSprite = new cc.BakeSprite();
58-
this._bakeSprite._parent = this._node;
58+
this._bakeSprite.setAnchorPoint(0,0);
5959
}
6060
}
6161
};
@@ -93,19 +93,8 @@
9393
var ctx = bakeContext.getContext();
9494
locBakeSprite.resetCanvasSize(boundingBox.width, boundingBox.height);
9595

96-
var anchor = locBakeSprite.getAnchorPointInPoints(), locPos = node._position;
97-
if(node._ignoreAnchorPointForPosition){
98-
//bakeContext.translate(0 - boundingBox.x + locPos.x, boundingBox.height + boundingBox.y - locPos.y);
99-
bakeContext.setOffset(0 - boundingBox.x, ctx.canvas.height - boundingBox.height + boundingBox.y );
100-
//reset the bake sprite's position
101-
locBakeSprite.setPosition(anchor.x + boundingBox.x - locPos.x, anchor.y + boundingBox.y - locPos.y);
102-
} else {
103-
var selfAnchor = this.getAnchorPointInPoints();
104-
var selfPos = {x: locPos.x - selfAnchor.x, y: locPos.y - selfAnchor.y};
105-
//bakeContext.translate(0 - boundingBox.x + selfPos.x, boundingBox.height + boundingBox.y - selfPos.y);
106-
bakeContext.setOffset(0 - boundingBox.x, ctx.canvas.height - boundingBox.height + boundingBox.y);
107-
locBakeSprite.setPosition(anchor.x + boundingBox.x - selfPos.x, anchor.y + boundingBox.y - selfPos.y);
108-
}
96+
bakeContext.setOffset(0 - boundingBox.x, ctx.canvas.height - boundingBox.height + boundingBox.y );
97+
locBakeSprite.setPosition(boundingBox.x, boundingBox.y);
10998

11099
//visit for canvas
111100
node.sortAllChildren();
@@ -114,7 +103,7 @@
114103
children[i].visit(this);
115104
}
116105
cc.renderer._renderingToCacheCanvas(bakeContext, this.__instanceId);
117-
locBakeSprite.transform(this); //because bake sprite's position was changed at rendering.
106+
locBakeSprite.transform(); //because bake sprite's position was changed at rendering.
118107
this._cacheDirty = false;
119108
}
120109
};
@@ -234,19 +223,9 @@
234223
var bakeContext = locBakeSprite.getCacheContext();
235224
var ctx = bakeContext.getContext();
236225
locBakeSprite.resetCanvasSize(boundingBox.width, boundingBox.height);
237-
var anchor = locBakeSprite.getAnchorPointInPoints(), locPos = node._position;
238-
if(node._ignoreAnchorPointForPosition){
239-
//bakeContext.translate(0 - boundingBox.x + locPos.x, boundingBox.height + boundingBox.y - locPos.y);
240-
bakeContext.setOffset(0 - boundingBox.x, ctx.canvas.height - boundingBox.height + boundingBox.y );
241-
//reset the bake sprite's position
242-
locBakeSprite.setPosition(anchor.x + boundingBox.x - locPos.x, anchor.y + boundingBox.y - locPos.y);
243-
} else {
244-
var selfAnchor = this.getAnchorPointInPoints();
245-
var selfPos = {x: locPos.x - selfAnchor.x, y: locPos.y - selfAnchor.y};
246-
//bakeContext.translate(0 - boundingBox.x + selfPos.x, boundingBox.height + boundingBox.y - selfPos.y);
247-
bakeContext.setOffset(0 - boundingBox.x, ctx.canvas.height - boundingBox.height + boundingBox.y);
248-
locBakeSprite.setPosition(anchor.x + boundingBox.x - selfPos.x, anchor.y + boundingBox.y - selfPos.y);
249-
}
226+
227+
bakeContext.setOffset(0 - boundingBox.x, ctx.canvas.height - boundingBox.height + boundingBox.y );
228+
locBakeSprite.setPosition(boundingBox.x, boundingBox.y);
250229

251230
var child;
252231
cc.renderer._turnToCacheMode(this.__instanceId);
@@ -268,7 +247,7 @@
268247
} else
269248
cc.renderer.pushRenderCommand(this);
270249
cc.renderer._renderingToCacheCanvas(bakeContext, this.__instanceId);
271-
locBakeSprite.transform(this);
250+
locBakeSprite.transform();
272251
this._cacheDirty = false;
273252
}
274253
};

0 commit comments

Comments
 (0)