[ad_1]
I feel there’s a distinction between the CCLayer and CCNode conduct once I change their AnchorPoint.
I’ll describe what I imply and please any person clarify it.
Scenario:
I begin with CCNode
CCNode *node = ...;
node.setContentSize(ccp(W,H));
// 1.
node.setAnchorPoint(ccp(0,0));
node.setPosition(ccp(X,Y); // This line will transfer the node in a approach that its (0,0)-point might be positioned at (X,Y).
// 2.
node.setAnchorPoint(ccp(1,1));
node.setPosition(ccp(X,Y); // This line will transfer the node in a approach that its (0,0)-point might be placeed at (X-W,Y-H).
//In different phrase, this line will transfer the (W,H)-point of the node to (X,Y)
In addition to the Positioning, all actions (like Rotating, Scaling) are primarily based on this anchor level.
This coverage is truthful sufficient and you will not get confused when transferring a scaled node (setScale(X)
) to some place as a result of the node’s place ( and not node’s contents!) won’t change within the display after any actions.
( PS: We knew that rotating/scaling a node will rotate/scale inner node contents)
Let’s proceed with CCLayer
:
CCLayer *layer= ...;
layer.setContentSize(ccp(W,H));
// 1.
layer.setAnchorPoint(ccp(0,0));
layer.setPosition(ccp(X,Y); // This line will transfer the layer in a approach that its (0,0)-point might be positioned at (X,Y)
// 2.
layer.setAnchorPoint(ccp(1,1));
layer.setPosition(ccp(X,Y); // Unfortunately, This line will transfer the layer in a approach that its (0,0)-point might be placeed at (X,Y).
Although CCLayer additionally use the anchor level for scaling, rotating and … functions, It does NOT use its anchor level for positioning!!!
Question >>>> WHY? and How can I’ve the identical CCNode-like setPosition()
behaviour for CCLayer
?
PS: I’ve additionally tried ->ignoreAnchorPointForPosition(true)
however it did not assist.
(@cocos2d-x model is 2.2.3)
[ad_2]