Skip to content

Commit f03b6cf

Browse files
committed
Merge pull request cocos2d#2430 from dingpinglv/Iss2429_LayerBake
Closed cocos2d#2429: Fixed a bug of cc.Layer's bake function.
2 parents 3ce8142 + d24b8a9 commit f03b6cf

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

cocos2d/core/layers/CCLayer.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -146,17 +146,16 @@ if (cc._renderType === cc._RENDER_TYPE_CANVAS) {
146146
var _t = this;
147147
var children = _t._children, locBakeSprite = this._bakeSprite;
148148
//compute the bounding box of the bake layer.
149+
this._transformForRenderer();
149150
var boundingBox = this._getBoundingBoxForBake();
150-
boundingBox.width = 0 | boundingBox.width;
151-
boundingBox.height = 0 | boundingBox.height;
151+
boundingBox.width = 0|(boundingBox.width+0.5);
152+
boundingBox.height = 0|(boundingBox.height+0.5);
152153
var bakeContext = locBakeSprite.getCacheContext();
153154
locBakeSprite.resetCanvasSize(boundingBox.width, boundingBox.height);
154155
bakeContext.translate(0 - boundingBox.x, boundingBox.height + boundingBox.y);
155-
156156
// invert
157157
var t = cc.affineTransformInvert(this._transformWorld);
158-
var scaleX = cc.view.getScaleX(), scaleY = cc.view.getScaleY();
159-
bakeContext.transform(t.a, t.c, t.b, t.d, t.tx * scaleX, -t.ty * scaleY);
158+
bakeContext.transform(t.a, t.c, t.b, t.d, t.tx , -t.ty );
160159

161160
//reset the bake sprite's position
162161
var anchor = locBakeSprite.getAnchorPointInPoints();
@@ -169,6 +168,7 @@ if (cc._renderType === cc._RENDER_TYPE_CANVAS) {
169168
children[i].visit(bakeContext);
170169
}
171170
cc.renderer._renderingToCacheCanvas(bakeContext, this.__instanceId);
171+
locBakeSprite.transform(); //because bake sprite's position was changed at rendering.
172172
this._cacheDirty = false;
173173
}
174174
};
@@ -230,7 +230,7 @@ if (cc._renderType === cc._RENDER_TYPE_CANVAS) {
230230
* CCLayerColor is a subclass of CCLayer that implements the CCRGBAProtocol protocol. <br/>
231231
* All features from CCLayer are valid, plus the following new features: <br/>
232232
* - opacity <br/>
233-
* - RGB colors </p>
233+
* - RGB colors </p>
234234
* @class
235235
* @extends cc.Layer
236236
*
@@ -467,8 +467,7 @@ if (cc._renderType === cc._RENDER_TYPE_CANVAS) {
467467
}
468468
// invert
469469
var t = cc.affineTransformInvert(this._transformWorld);
470-
var scaleX = cc.view.getScaleX(), scaleY = cc.view.getScaleY();
471-
bakeContext.transform(t.a, t.c, t.b, t.d, t.tx * scaleX, -t.ty * scaleY);
470+
bakeContext.transform(t.a, t.c, t.b, t.d, t.tx, -t.ty);
472471

473472
var child;
474473
cc.renderer._turnToCacheMode(this.__instanceId);
@@ -492,6 +491,7 @@ if (cc._renderType === cc._RENDER_TYPE_CANVAS) {
492491
if(_t._rendererCmd)
493492
cc.renderer.pushRenderCommand(_t._rendererCmd);
494493
cc.renderer._renderingToCacheCanvas(bakeContext, this.__instanceId);
494+
locBakeSprite.transform();
495495
this._cacheDirty = false;
496496
}
497497
};

0 commit comments

Comments
 (0)