[Cocos2dx note 015] three states of cocos2dx buttons

Source: Internet
Author: User
After a few days of completion, I finally moved the existing project from cocos2dx 2.2.2 to cocos2dx 3.2, and almost gave up 3.2. But at the last moment, I completed the completion.
Cocos2dx 2. x to 3. X is a huge change, which can be regarded as completely different. The previous class names start with CC and are all removed. Many Enum use Enum class.
So, you know 2.x, sorry, you are more difficult than learning 3. X. If you use the 2.x method in 3.x, it will be all pitfall...




Let's get down to the truth,
2. x is invisible when the button is set to disabled. 3. X is not disabled, but does not respond to the touch event.
When editing the cocostudio UI, the buttons are in three States (there are three images in different States), but there is no function to change the State accordingly.
Therefore, the source code is analyzed and it is found that it is an image in onpressstatechangedtodisabled (); the image is changed to disabled. Find another
In the UI of its base class: setbright and sethighlight of the widget call this onpressstatechangedtodisabled, but setenabled is only changed to a member change,
Therefore, if you set disabled here, it will not have any effect. In addition to the above two functions, there is also a function setbrightstyle to set whether the button is normal or highlighted
The following is the definition of brightstyle.
Enum class brightstyle
{
None =-1,
Normal,
Highlight
};
The following is a function for disabling and enabling packaging.
// Set the button to disable the Enable status
Inline void setbuttonenabled (ui: button * parambutton, bool paramenabled)
{
If (isnull (parambutton) return;
If (paramenabled)
{
Parambutton-> setbright (true );
Parambutton-> setenabled (true );
Parambutton-> settouchenabled (true );
}
Else
{
Parambutton-> setbright (false );
Parambutton-> setenabled (false );
Parambutton-> settouchenabled (false );
}
}

[Cocos2dx note 015] three states of cocos2dx buttons

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.