参考UIScene.cpp和SceneEditorTest.cpp
使用scene的时候:
#include "cocostudio/CocoLoader.h"
#include "cocostudio/CCSSceneReader.h"
using cocostudio::SceneReader;
cocos2d::Node *rootNode;
onEnter里面调用:
do
{
Node *root =导入scene;
CC_BREAK_IF(!root);
this->addChild(root,1);
} while (0);
导入scene函数,返回值为Node*
filePath = "UIComponentTest/UIComponentTest.json";
rootNode = SceneReader::getInstance()->createNodeWithSceneFile(filePath.c_str());
if (rootNode == nullptr)
{
return nullptr;
}
return rootNode;
使用UI:
#include "cocostudio/CCSGUIReader.h"
using cocostudio::GUIReader;
//导入ui
filePath = "guardsbattle/hallUi_1.json";
pUI = Layer::create();
addChild(pUI);
pWidget = dynamic_cast<Layout*>(GUIReader::getInstance()->widgetFromJsonFile(filePath.c_str()));
pUI->addChild(pWidget);
PS:最后都别忘了释放:
GUIReader::destroyInstance();
SceneReader::destroyInstance();