-
Book Overview & Buying
-
Table Of Contents
Cocos2d-x cookbook
By :
In this recipe, we will create a checkbox. In Cocos2d-x version 2, a checkbox was created by using the MenuItemToggle class. However, doing so was quite cumbersome. In Cocos2d-x version 3, we can create a checkbox by using the Checkbox class that can be used in Cocos Studio.
So let's prepare the images of the checkbox before you start. Here, we have prepared the images of the required minimum On and Off status. Please add these images to the Resouces/res folder.
The Off status image will look something like this:

The On status image will look something like this:

Let's create a checkbox by using the Checkbox class. First, you will generate a checkbox instance by using the check_box_normal.png image and the check_box_active.png image. You will also specify the callback function as a lambda expression by using the addEventListener method when the checkbox status is changed. Create the checkbox by using the following code:
auto size = Director::getInstance...
Change the font size
Change margin width
Change background colour