João Abrantes
João Abrantes

Reputation: 4873

Positioning of elements inside CCNode

I made a CCNode in SpriteBuilder and add it a few children nodes (Labels, buttons and sprites). On SpriteBuilder I made the position of the children nodes to be constant in points in relation to the parent top left corner.

At run time I change the parent node content size but the children position doesn't stay constant in relation to the top.

Not Expanded

Expanded

To expand the node I do:

self.contentSize = CGSizeMake(self.contentSize.width, self.contentSize.height+50);

I check the color node (the node that gives the dark blue which is a child of the node being expanded and has 100% of it's height) contentsize before and after the expansion, and it indeed increases by 50 points but on the screenshots we can see that the dark blue area doesn't increase.

I also check the position of Title label before and after the expansion and it's the same in points in relation to the top left corner. However in the screenshots we can see that it is further away from the top.

Upvotes: 0

Views: 440

Answers (1)

Tibor Udvari
Tibor Udvari

Reputation: 3012

With no code it is hard to say.

Here is a code snippet that does what SpriteBuilder does visually

someNode.positionType = CCPositionTypeMake(CCPositionUnitNormalized, CCPositionUnitNormalized, CCPositionReferenceCornerBottomLeft);

I hope this can help you debug your problem. You have to inspect if the reference corner of your nodes position type is set correctly.

Upvotes: 2

Related Questions