Cocos2d-x3.0 從代碼中獲取cocostudio編輯的UI控件
阿新 • • 發佈:2017-06-03
ucid 編輯 top ica sans sce nero val -i
利用addTouchEventListener函數就能夠綁定button的回調事件了~
依據名字查找控件
須要包括的頭文件及名字空間:
獲取UI控件的方法例如以下:
m_achievementLayer = dynamic_cast<Layout*>(GUIReader::getInstance()->widgetFromJsonFile("achievements/achievements.json")); addChild(m_achievementLayer); Widget* scoreWidget = dynamic_cast<Widget*>(m_achievementLayer->getChildByName("ImageView_231")); m_score = dynamic_cast<TextAtlas*>(scoreWidget->getChildByName("LabelAtlas_307")); m_score->setStringValue("45");
加入button回調事件
Button* startButton = dynamic_cast<Button*>(m_achievementLayer->getChildByName("Button_336")); startButton->addTouchEventListener(this, toucheventselector(GameScene::touchStartButton));
利用addTouchEventListener函數就能夠綁定button的回調事件了~
回調函數實現:
void GameScene::touchStartButton(Ref* pSender, TouchEventType type) { switch (type) { case TOUCH_EVENT_ENDED: //do something break; } }
Cocos2d-x3.0 從代碼中獲取cocostudio編輯的UI控件