COCOS2DX Ccnode is often used as a parent container, with some UI controls, and finally a complex custom UI control. But when you use someone else's custom controls and write your own custom questions, you'll step on some pits.
To get a custom UI control first, be sure to make sure that his position is where the control is located, that is , the anchor Point, so you know how to change the settings position.
Second, you know that the parent container area is full of sub-containers, because the range of child nodes inside the Ccnode can exceed the ccnode area you set . The reason is that ccnode can have no area, this is different from the Panel of the winform desktop, the area is only set when the zone is used.
So the most necessary thing to know is how the child nodes are arranged, and after all the child nodes are arranged, the parent container's anchor point is where the child node is.
For example, using a node to add a cclabelttf,ccLabelttf anchor Point is 0.5,0.5 If you do not adjust,Node->setpositon (0,0) then only the second quadrant of CcLabel will be shown.
So if the custom UI component is used or given to other people, it is best to have an art, the composition and position of the child nodes, the coordinates of the parent container when the coordinates of how to offset, the default parent container anchor point location where, whether can change, or really is a big hole!
ccnode* n1 = Ccnode::create ();
strokelabel* L1 = strokelabel::create (40);
L1->setstring ("11111111");
N1->addchild (L1);
N1->setanchorpoint (CCP (0.5,0.5));
N1->setcontentsize (Ccsizemake (400,400));
N1->setposition (480,320);
AddChild (N1);
This code, Strokelabel can be replaced with Cclabelttf, remove setcontentsize and there will be 2 different effects
Reason
void Ccnode::setcontentsize (const ccsize & size)
{
if (! size.equals (m_obcontentsize))
{m_obcontentsize = size;
m_obanchorpointinpoints = CCP (M_obcontentsize.width * m_obanchorpoint.x, M_obcontentsize.height * m_obAnchorPoint.y);
}
}
Personally, it makes sense for ccnode to have only the Contentsize anchor point set.
Use Ccnode as a container for easy-stepping pits