如何调用cocostudio创建场景中的按钮控件
2个回答
展开全部
首先使用cocostudio创建两个场景,在其中一个场景中添加一个了使用cocostudio创建的ui按钮控件,下面实例代码就是教你如何使用第一个场景中按钮切换到另一个场景的主要代码:
[cpp] view plaincopyprint?在CODE上查看代码片派生到我的代码片
如何调用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?在CODE上查看代码片派生到我的代码片
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?在CODE上查看代码片派生到我的代码片
void MenuScene::touchEvent(CCObject *pSender, TouchEventType type)
{
CCScene *pScene = GetReadyScene::scene();//创建你需要切换的场景对象
CCDirector::sharedDirector()->replaceScene(pScene);
}
[cpp] view plaincopyprint?在CODE上查看代码片派生到我的代码片
void MenuScene::touchEvent(CCObject *pSender, TouchEventType type)
{
CCScene *pScene = GetReadyScene::scene();//创建你需要切换的场景对象
CCDirector::sharedDirector()->replaceScene(pScene);
}
对的,就是so easy,这也是我从TestCpp里面参考直接拿来使用的,现在网上这方面的资料还是相对较少些,所以当你不知道的时候多去参考里面的实例。以上代码的使用前提是你要对cocostudio的使用有一定熟悉,一些加载的头文件也得注意还要就是using namespace XXX的添加。
[cpp] view plaincopyprint?在CODE上查看代码片派生到我的代码片
如何调用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?在CODE上查看代码片派生到我的代码片
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?在CODE上查看代码片派生到我的代码片
void MenuScene::touchEvent(CCObject *pSender, TouchEventType type)
{
CCScene *pScene = GetReadyScene::scene();//创建你需要切换的场景对象
CCDirector::sharedDirector()->replaceScene(pScene);
}
[cpp] view plaincopyprint?在CODE上查看代码片派生到我的代码片
void MenuScene::touchEvent(CCObject *pSender, TouchEventType type)
{
CCScene *pScene = GetReadyScene::scene();//创建你需要切换的场景对象
CCDirector::sharedDirector()->replaceScene(pScene);
}
对的,就是so easy,这也是我从TestCpp里面参考直接拿来使用的,现在网上这方面的资料还是相对较少些,所以当你不知道的时候多去参考里面的实例。以上代码的使用前提是你要对cocostudio的使用有一定熟悉,一些加载的头文件也得注意还要就是using namespace XXX的添加。
推荐于2016-06-16 · 知道合伙人互联网行家
关注
展开全部
如何调用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);
}
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询