1

I have two CCNodes in Cocos2d that I want to dynamically scale in sync with each other. Both CCNodes are background nodes. Visually one CCNode, NodeA, is above the other CCNode, NodeB in the y direction. But when I scale both nodes at the same time as in the code below:

Edit #1 -

Node B is part of a CCLayer, HUDLayer. The HUDLayer doesn't scale but NodeB in the HUDLayer does scale. So the code looks like

NodeA.anchorPoint = ccp(0.5f, 0.0f);
NodeA.scale = scale;
HUDLayer.NodeB.anchorPoint = ccp(0.5f, 0.0f);
HUDLayer.NodeB.scale = scale;

4)  Would NodeB being part of a CCLayer effect the Nodes scaled relative positions?

End Edit #1

Edit #2

 The contentSize of CCNode is (0,0).  How do I set the contentSize of CCNode manually?

End Edit #2

Edit #3

I found this post where one of the answers talks about setting a CCNode's relativeToAnchorPoint property to YES. I can't find how to do this on Google. Does anyone know how to set relativeToAnchorPoint?

End Edit #3

NodeA drops below NodeB in the y direction. So this brings up a few questions:

1)  Are CCNodes scaled with respect to an anchorPoint?
2)  Why is NodeA dropping below NodeB in the y direction?
3)  How can two CCNodes be scaled with their relative positions remaining constant?
Community
  • 1
  • 1
James Testa
  • 2,901
  • 4
  • 42
  • 60
  • it's not so much the scaling happens in respect to the anchor point, but their position. So the anchor point at .5, 1 will have its top most point stay in the same position as it grows. – dqhendricks Mar 25 '13 at 15:20
  • So is the trick that I need to find an anchorPoint for both Nodes so that they stay fixed relative to each other? – James Testa Mar 25 '13 at 15:59
  • I don't know what the exact effect your looking for is, but yeah, basically. Keep in mind that the anchor point is relative to the contentSize of the object, and adding child nodes does not alter the contentSize. Only the texture, or manual setting affect the contentSize. – dqhendricks Mar 25 '13 at 16:21
  • The CCLayer has a contentSize, but does a CCNode have a contentSize? – James Testa Mar 25 '13 at 17:24
  • It has one, but by default it is (0,0), since there is no texture that would give it a size by default. As I've said, adding children does not change the node's size. You could give it a size manually however. If something has no size, then the anchor point setting really has no effect (the anchor point will always be at 0,0 of the node). – dqhendricks Mar 25 '13 at 17:51
  • Right, that is what I have noticed is that the anchorPoint has no effect on the CCNode. In fact the anchorPoint doesn't seem to have any effect on NodeB either. – James Testa Mar 25 '13 at 17:59
  • Now if instead of nodes, they were sprites with textures (which sets a contentSize automatically), or if you were to set the contentSize for your nodes manually, the anchor point would then start having an effect. – dqhendricks Mar 25 '13 at 18:01
  • I tried setting the contentSize as ccnode.contentSize = CGSizeMake(480.0f, 320.0f); but it didn't seem to cause the anchorPoint code to work with ccnode.anchorPoint = ccl(0.5f, 0.0f);. – James Testa Apr 08 '13 at 23:10
  • How does one scale to the children in cocos2d? – James Testa Apr 09 '13 at 01:38

1 Answers1

3
  1. Yes
  2. see 1 especially if they are not the same size
  3. set their anchorpoint to 0.5,0 so they both align on the bottom when scaling
CodeSmile
  • 64,284
  • 20
  • 132
  • 217
  • That still doesn't work. Must be something else I am missing. I added more information in Edit #1. Btw I've got your book and its a great book. – James Testa Mar 25 '13 at 15:27