如何使用Cocos Studio v3.10通过按钮控件切换场景?

2025-04-29 04:03:48
推荐回答(1个)
回答1:

如何调用cocostudio创建场景中的按钮控件
cocos2d::gui::TouchGroup* touchGroup = static_cast(render->getNode());
UIWidget* widget = static_cast(touchGroup->getWidgetByName("Panel_20"));
UIButton* button = static_cast(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(_node->getChildByTag(10013)->getComponent("GUIComponent"));
cocos2d::gui::TouchGroup* touchGroup = static_cast(render->getNode());
UIWidget* widget = static_cast(touchGroup->getWidgetByName("Panel_20"));
UIButton* button = static_cast(widget->getChildByName("Button_