如何调用cocostudio创建场景中的按钮控件
2个回答
展开全部
如何调用cocostudio创建场景中的按钮控件
cocos2d::gui::TouchGroup* touchGroup = static_cast<cocos2d::gui::TouchGroup*>(render->getNode());
UIWidget* widget = static_cast<UIWidget*>(touchGroup->getWidgetByName("Panel_20"));
UIButton* button = static_cast<UIButton*>(widget->getChildByName("Button_24"));
//为按钮添加触控事件
button->addTouchEventListener(this, toucheventselector(MenuScene::touchEvent));
return pNode;
}
[cpp] view plaincopyprint?
cocos2d::CCNode* MenuScene::createGameScene()
{
CCNode *pNode = SceneReader::sharedSceneReader()->createNodeWithSceneFile("yourJson.json");//加载第一个场景
if (pNode == NULL)
{
return NULL;
}
_node = pNode;
//从场景中获取ui按钮控件
CCComRender *render = static_cast<CCComRender*>(_node->getChildByTag(10013)->getComponent("GUIComponent"));
cocos2d::gui::TouchGroup* touchGroup = static_cast<cocos2d::gui::TouchGroup*>(render->getNode());
UIWidget* widget = static_cast<UIWidget*>(touchGroup->getWidgetByName("Panel_20"));
UIButton* button = static_cast<UIButton*>(widget->getChildByName("Button_24"));
//为按钮添加触控事件
button->addTouchEventListener(this, toucheventselector(MenuScene::touchEvent));
return pNode;
}
cocos2d::CCNode* MenuScene::createGameScene()
{
CCNode *pNode = SceneReader::sharedSceneReader()->createNodeWithSceneFile("yourJson.json");//加载第一个场景
if (pNode == NULL)
{
return NULL;
}
_node = pNode;
//从场景中获取ui按钮控件
CCComRender *render = static_cast<CCComRender*>(_node->getChildByTag(10013)->getComponent("GUIComponent"));
cocos2d::gui::TouchGroup* touchGroup = static_cast<cocos2d::gui::TouchGroup*>(render->getNode());
UIWidget* widget = static_cast<UIWidget*>(touchGroup->getWidgetByName("Panel_20"));
UIButton* button = static_cast<UIButton*>(widget->getChildByName("Button_24"));
//为按钮添加触控事件
button->addTouchEventListener(this, toucheventselector(MenuScene::touchEvent));
return pNode;
}
按钮单击相应函数如下:
[cpp] view plaincopyprint?
void MenuScene::touchEvent(CCObject *pSender, TouchEventType type)
{
CCScene *pScene = GetReadyScene::scene();//创建你需要切换的场景对象
CCDirector::sharedDirector()->replaceScene(pScene);
}
[cpp] view plaincopyprint?
void MenuScene::touchEvent(CCObject *pSender, TouchEventType type)
{
CCScene *pScene = GetReadyScene::scene();//创建你需要切换的场景对象
CCDirector::sharedDirector()->replaceScene(pScene);
}
void MenuScene::touchEvent(CCObject *pSender, TouchEventType type)
{
CCScene *pScene = GetReadyScene::scene();//创建你需要切换的场景对象
CCDirector::sharedDirector()->replaceScene(pScene);
}
cocos2d::gui::TouchGroup* touchGroup = static_cast<cocos2d::gui::TouchGroup*>(render->getNode());
UIWidget* widget = static_cast<UIWidget*>(touchGroup->getWidgetByName("Panel_20"));
UIButton* button = static_cast<UIButton*>(widget->getChildByName("Button_24"));
//为按钮添加触控事件
button->addTouchEventListener(this, toucheventselector(MenuScene::touchEvent));
return pNode;
}
[cpp] view plaincopyprint?
cocos2d::CCNode* MenuScene::createGameScene()
{
CCNode *pNode = SceneReader::sharedSceneReader()->createNodeWithSceneFile("yourJson.json");//加载第一个场景
if (pNode == NULL)
{
return NULL;
}
_node = pNode;
//从场景中获取ui按钮控件
CCComRender *render = static_cast<CCComRender*>(_node->getChildByTag(10013)->getComponent("GUIComponent"));
cocos2d::gui::TouchGroup* touchGroup = static_cast<cocos2d::gui::TouchGroup*>(render->getNode());
UIWidget* widget = static_cast<UIWidget*>(touchGroup->getWidgetByName("Panel_20"));
UIButton* button = static_cast<UIButton*>(widget->getChildByName("Button_24"));
//为按钮添加触控事件
button->addTouchEventListener(this, toucheventselector(MenuScene::touchEvent));
return pNode;
}
cocos2d::CCNode* MenuScene::createGameScene()
{
CCNode *pNode = SceneReader::sharedSceneReader()->createNodeWithSceneFile("yourJson.json");//加载第一个场景
if (pNode == NULL)
{
return NULL;
}
_node = pNode;
//从场景中获取ui按钮控件
CCComRender *render = static_cast<CCComRender*>(_node->getChildByTag(10013)->getComponent("GUIComponent"));
cocos2d::gui::TouchGroup* touchGroup = static_cast<cocos2d::gui::TouchGroup*>(render->getNode());
UIWidget* widget = static_cast<UIWidget*>(touchGroup->getWidgetByName("Panel_20"));
UIButton* button = static_cast<UIButton*>(widget->getChildByName("Button_24"));
//为按钮添加触控事件
button->addTouchEventListener(this, toucheventselector(MenuScene::touchEvent));
return pNode;
}
按钮单击相应函数如下:
[cpp] view plaincopyprint?
void MenuScene::touchEvent(CCObject *pSender, TouchEventType type)
{
CCScene *pScene = GetReadyScene::scene();//创建你需要切换的场景对象
CCDirector::sharedDirector()->replaceScene(pScene);
}
[cpp] view plaincopyprint?
void MenuScene::touchEvent(CCObject *pSender, TouchEventType type)
{
CCScene *pScene = GetReadyScene::scene();//创建你需要切换的场景对象
CCDirector::sharedDirector()->replaceScene(pScene);
}
void MenuScene::touchEvent(CCObject *pSender, TouchEventType type)
{
CCScene *pScene = GetReadyScene::scene();//创建你需要切换的场景对象
CCDirector::sharedDirector()->replaceScene(pScene);
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询