CheckBox

We are all used to filling out checkboxes on paper forms like job applications and rental agreements. You can also have checkboxes in your games. Perhaps, you want to have the ability for your player to make a simple yes or no choice. You might also hear this referred to as a binary choice (0 and 1). A CheckBox permits the user to make this type of choice. There are 5 different states a Checkbox can have: normal, selected and disabled. It is simple to create a CheckBox:

#include "ui/CocosGUI.h"

auto checkbox = CheckBox::create("check_box_normal.png",
                                 "check_box_normal_press.png",
                                 "check_box_active.png",
                                 "check_box_normal_disable.png",
                                 "check_box_active_disable.png");

checkbox->addTouchEventListener([&](Ref* sender, Widget::TouchEventType type){
        switch (type)
        {
                case ui::Widget::TouchEventType::BEGAN:
                        break;
                case ui::Widget::TouchEventType::ENDED:
                        std::cout << "checkbox 1 clicked" << std::endl;
                        break;
                default:
                        break;
        }
});

this->addChild(checkbox);

As you can see in the above example we specify a .png image for each of the possible states the Checkbox can be in. Since there are 5 possible states that a CheckBox can be in, it is up 5 graphics, one for each of its states. Example graphics:

On screen a Checkbox might look like this:

results matching ""

    No results matching ""