0
votes

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.

1
I don't usually use the positioning in SpriteBuilder. I prefer to edit the position with code. Just go to Item Code Connections, select doc root var and then write a name for the sprite. Now in your code just position it as always, "spriteName.position = ccp( wherever top left);"mursang
If the position is in relation to the top left corner (in the code and in the spritebuilder) shouldnt the distance to the top left stay constant when the parent node height increases?João Abrantes
It will be constant if, in code, you position it by points. But you have to be sure that the content node of the sprites is at top left or bottom left, so you have a reference. If it's at bottom, sprite.position = ccp(pointsX,size.height-pointsY); Where size is: CGSize size = [[CCDirector sharedDirector]viewSize]; So your sprite will be relative to the top left even when the view changes.mursang
What is the anchor point of you parent node? Can you add an image to show how the 2 scenarios look, so what you see and what you get?lucianomarisi
@lucianomarisi I have added the two images.João Abrantes

1 Answers

2
votes

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.