Skip to content

Closed #2429: Fixed a bug of cc.Layer's bake function. #2430

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 4, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions cocos2d/core/layers/CCLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,17 +146,16 @@ if (cc._renderType === cc._RENDER_TYPE_CANVAS) {
var _t = this;
var children = _t._children, locBakeSprite = this._bakeSprite;
//compute the bounding box of the bake layer.
this._transformForRenderer();
var boundingBox = this._getBoundingBoxForBake();
boundingBox.width = 0 | boundingBox.width;
boundingBox.height = 0 | boundingBox.height;
boundingBox.width = 0|(boundingBox.width+0.5);
boundingBox.height = 0|(boundingBox.height+0.5);
var bakeContext = locBakeSprite.getCacheContext();
locBakeSprite.resetCanvasSize(boundingBox.width, boundingBox.height);
bakeContext.translate(0 - boundingBox.x, boundingBox.height + boundingBox.y);

// invert
var t = cc.affineTransformInvert(this._transformWorld);
var scaleX = cc.view.getScaleX(), scaleY = cc.view.getScaleY();
bakeContext.transform(t.a, t.c, t.b, t.d, t.tx * scaleX, -t.ty * scaleY);
bakeContext.transform(t.a, t.c, t.b, t.d, t.tx , -t.ty );

//reset the bake sprite's position
var anchor = locBakeSprite.getAnchorPointInPoints();
Expand All @@ -169,6 +168,7 @@ if (cc._renderType === cc._RENDER_TYPE_CANVAS) {
children[i].visit(bakeContext);
}
cc.renderer._renderingToCacheCanvas(bakeContext, this.__instanceId);
locBakeSprite.transform(); //because bake sprite's position was changed at rendering.
this._cacheDirty = false;
}
};
Expand Down Expand Up @@ -230,7 +230,7 @@ if (cc._renderType === cc._RENDER_TYPE_CANVAS) {
* CCLayerColor is a subclass of CCLayer that implements the CCRGBAProtocol protocol. <br/>
* All features from CCLayer are valid, plus the following new features: <br/>
* - opacity <br/>
* - RGB colors </p>
* - RGB colors </p>
* @class
* @extends cc.Layer
*
Expand Down Expand Up @@ -467,8 +467,7 @@ if (cc._renderType === cc._RENDER_TYPE_CANVAS) {
}
// invert
var t = cc.affineTransformInvert(this._transformWorld);
var scaleX = cc.view.getScaleX(), scaleY = cc.view.getScaleY();
bakeContext.transform(t.a, t.c, t.b, t.d, t.tx * scaleX, -t.ty * scaleY);
bakeContext.transform(t.a, t.c, t.b, t.d, t.tx, -t.ty);

var child;
cc.renderer._turnToCacheMode(this.__instanceId);
Expand All @@ -492,6 +491,7 @@ if (cc._renderType === cc._RENDER_TYPE_CANVAS) {
if(_t._rendererCmd)
cc.renderer.pushRenderCommand(_t._rendererCmd);
cc.renderer._renderingToCacheCanvas(bakeContext, this.__instanceId);
locBakeSprite.transform();
this._cacheDirty = false;
}
};
Expand Down