cocos2d-x CheckBox的使用

前端之家收集整理的这篇文章主要介绍了cocos2d-x CheckBox的使用前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。


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; } }

原文链接:https://www.f2er.com/cocos2dx/340263.html

猜你在找的Cocos2d-x相关文章