加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

cocos2d-x CheckBox的使用

发布时间:2020-12-14 16:53:18 所属栏目:百科 来源:网络整理
导读:?? 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",3
??

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读