cocos2d::ui::Text* _displayText;
void selectedEvent(Ref* pSender,cocos2d::ui::CheckBox::EventType type);
Size size = Director::getInstance()->getVisibleSize();
_displayText = cocos2d::ui::Text::create("No Event","fonts/Marker Felt.ttf",32);
_displayText->setAnchorPoint(Vec2(0.5f,-1));
_displayText->setColor(Color3B(159,168,176));
_displayText->setPosition(Vec2(size.width / 2.0f,size.height / 2));
this->addChild(_displayText);
cocos2d::ui::CheckBox* cBox = cocos2d::ui::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");
cBox->setPosition(Vec2(size.width / 2,size.height /2 -50));
cBox->setZoomScale(1.5);
//cBox->setEnabled(false);
//cBox->setBright(false);
cBox->setSelected(true);
cBox->setContentSize(Size(80,80));
cBox->setName("checkBox Test");
cBox->addEventListener(CC_CALLBACK_2(HelloWorld::selectedEvent,this));
this->addChild(cBox);
void HelloWorld::selectedEvent(Ref* pSender,cocos2d::ui::CheckBox::EventType type) { switch (type) { case cocos2d::ui::CheckBox::EventType::SELECTED: _displayText->setString(String::createWithFormat("Selected")->getCString()); break; case cocos2d::ui::CheckBox::EventType::UNSELECTED: _displayText->setString(String::createWithFormat("Unselected")->getCString()); break; default: break; } }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。