Skip to content

Fixed a bug of cc.Layer that its bake function doesn't work when the layer has a parent node #2691

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 1 commit into from
Feb 15, 2015
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions cocos2d/core/base-nodes/CCNodeCanvasRenderCmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ cc.Node.RenderCmd.prototype = {
// transform for canvas
var t = this.getNodeToParentTransform(),
worldT = this._worldTransform; //get the world transform

this._cacheDirty = true;
if (parentCmd) {
var pt = parentCmd._worldTransform;
// cc.AffineTransformConcat is incorrect at get world transform
Expand Down Expand Up @@ -447,7 +447,7 @@ cc.Node.RenderCmd.prototype = {

proto.setDirtyFlag = function (dirtyFlag) {
cc.Node.RenderCmd.prototype.setDirtyFlag.call(this, dirtyFlag);
this._setCacheDirty();
this._setCacheDirty(); //TODO it should remove from here.
if(this._cachedParent)
this._cachedParent.setDirtyFlag(dirtyFlag);
};
Expand Down
37 changes: 8 additions & 29 deletions cocos2d/core/layers/CCLayerCanvasRenderCmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@

if (!this._bakeSprite){
this._bakeSprite = new cc.BakeSprite();
this._bakeSprite._parent = this._node;
this._bakeSprite.setAnchorPoint(0,0);
}
}
};
Expand Down Expand Up @@ -93,19 +93,8 @@
var ctx = bakeContext.getContext();
locBakeSprite.resetCanvasSize(boundingBox.width, boundingBox.height);

var anchor = locBakeSprite.getAnchorPointInPoints(), locPos = node._position;
if(node._ignoreAnchorPointForPosition){
//bakeContext.translate(0 - boundingBox.x + locPos.x, boundingBox.height + boundingBox.y - locPos.y);
bakeContext.setOffset(0 - boundingBox.x, ctx.canvas.height - boundingBox.height + boundingBox.y );
//reset the bake sprite's position
locBakeSprite.setPosition(anchor.x + boundingBox.x - locPos.x, anchor.y + boundingBox.y - locPos.y);
} else {
var selfAnchor = this.getAnchorPointInPoints();
var selfPos = {x: locPos.x - selfAnchor.x, y: locPos.y - selfAnchor.y};
//bakeContext.translate(0 - boundingBox.x + selfPos.x, boundingBox.height + boundingBox.y - selfPos.y);
bakeContext.setOffset(0 - boundingBox.x, ctx.canvas.height - boundingBox.height + boundingBox.y);
locBakeSprite.setPosition(anchor.x + boundingBox.x - selfPos.x, anchor.y + boundingBox.y - selfPos.y);
}
bakeContext.setOffset(0 - boundingBox.x, ctx.canvas.height - boundingBox.height + boundingBox.y );
locBakeSprite.setPosition(boundingBox.x, boundingBox.y);

//visit for canvas
node.sortAllChildren();
Expand All @@ -114,7 +103,7 @@
children[i].visit(this);
}
cc.renderer._renderingToCacheCanvas(bakeContext, this.__instanceId);
locBakeSprite.transform(this); //because bake sprite's position was changed at rendering.
locBakeSprite.transform(); //because bake sprite's position was changed at rendering.
this._cacheDirty = false;
}
};
Expand Down Expand Up @@ -234,19 +223,9 @@
var bakeContext = locBakeSprite.getCacheContext();
var ctx = bakeContext.getContext();
locBakeSprite.resetCanvasSize(boundingBox.width, boundingBox.height);
var anchor = locBakeSprite.getAnchorPointInPoints(), locPos = node._position;
if(node._ignoreAnchorPointForPosition){
//bakeContext.translate(0 - boundingBox.x + locPos.x, boundingBox.height + boundingBox.y - locPos.y);
bakeContext.setOffset(0 - boundingBox.x, ctx.canvas.height - boundingBox.height + boundingBox.y );
//reset the bake sprite's position
locBakeSprite.setPosition(anchor.x + boundingBox.x - locPos.x, anchor.y + boundingBox.y - locPos.y);
} else {
var selfAnchor = this.getAnchorPointInPoints();
var selfPos = {x: locPos.x - selfAnchor.x, y: locPos.y - selfAnchor.y};
//bakeContext.translate(0 - boundingBox.x + selfPos.x, boundingBox.height + boundingBox.y - selfPos.y);
bakeContext.setOffset(0 - boundingBox.x, ctx.canvas.height - boundingBox.height + boundingBox.y);
locBakeSprite.setPosition(anchor.x + boundingBox.x - selfPos.x, anchor.y + boundingBox.y - selfPos.y);
}

bakeContext.setOffset(0 - boundingBox.x, ctx.canvas.height - boundingBox.height + boundingBox.y );
locBakeSprite.setPosition(boundingBox.x, boundingBox.y);

var child;
cc.renderer._turnToCacheMode(this.__instanceId);
Expand All @@ -268,7 +247,7 @@
} else
cc.renderer.pushRenderCommand(this);
cc.renderer._renderingToCacheCanvas(bakeContext, this.__instanceId);
locBakeSprite.transform(this);
locBakeSprite.transform();
this._cacheDirty = false;
}
};
Expand Down