参考UIScene.cpp和SceneEditorTest.cpp
使用scene的时候:
#include "cocostu@R_502_410@/CocoLoader.h"
#include "cocostu@R_502_410@/CCSSceneReader.h"
using cocostu@R_502_410@::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 "cocostu@R_502_410@/CCSGUIReader.h"
using cocostu@R_502_410@::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();