About Cocos2d-x getting UI controls to null considerations

Source: Internet
Author: User

Cocos2d-x can make static pages with Cocos Studio, and when we manipulate the controls in our code, we need to use the API to get the controls to manipulate them. For beginners, getting a control can cause a program to crash with some inexplicable errors, and here's where it's possible to get a control that is NULL.

There are two ways to get a UI control (I know only two of them at this time):

1, through the  parent node->getchildbyname ("Control name")   layer obtained, this method in obtaining child nodes of child nodes, slightly cumbersome, can be used in the second way.

2, through   cocos2d::ui::helper::seekwidgetbyname (the base container, "control name"); getting  This method is convenient when getting child nodes of a child node  .

The following possibilities are possible (not exhaustive) when getting controls that cause the control address to be NULL:

1. The control name does not match the name of the control in Cocos studio, with particular attention to capitalization.

2. Cocos Studio Publishing resources are not synchronized with the code:

① maybe you edited it in Cocos Studio, but there is no publishing resource that is not available in the code.

② may be that you have published a resource in Cocos Studio but changed the file path on the second change and then published it again, but forgot to change the path in the code, resulting in the get null. (This kind of situation is easy to ignore, I am this kind of situation to toss a day of time hope can help everybody).

About Cocos2d-x getting UI controls to null considerations

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.