简体   繁体   中英

Cocos2d - how to scale two CCNodes with respect to each other

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?
  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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM