Use Ccnode as a container for easy-stepping pits

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.