本文整理汇总了C++中ComRender::setNode方法的典型用法代码示例。如果您正苦于以下问题:C++ ComRender::setNode方法的具体用法?C++ ComRender::setNode怎么用?C++ ComRender::setNode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ComRender
的用法示例。
在下文中一共展示了ComRender::setNode方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: createObject
cocos2d::Node* SceneReader::createObject(CocoLoader *cocoLoader, stExpCocoNode *cocoNode, cocos2d::Node* parent, AttachComponentType attachComponent)
{
const char *className = nullptr;
stExpCocoNode *pNodeArray = cocoNode->GetChildArray(cocoLoader);
std::string Key = pNodeArray[1].GetName(cocoLoader);
if (Key == "classname")
{
className = pNodeArray[1].GetValue(cocoLoader);
}
if(strcmp(className, "CCNode") == 0)
{
Node* gb = nullptr;
std::vector<Component*> _vecComs;
ComRender *pRender = nullptr;
int count = 0;
std::string key = pNodeArray[13].GetName(cocoLoader);
if (key == "components")
{
count = pNodeArray[13].GetChildNum();
}
stExpCocoNode *pComponents = pNodeArray[13].GetChildArray(cocoLoader);
SerData *data = new (std::nothrow) SerData();
for (int i = 0; i < count; ++i)
{
stExpCocoNode *subDict = pComponents[i].GetChildArray(cocoLoader);
if (subDict == nullptr)
{
continue;
}
std::string key1 = subDict[1].GetName(cocoLoader);
const char *comName = subDict[1].GetValue(cocoLoader);
Component *pCom = nullptr;
if (key1 == "classname" && comName != nullptr)
{
pCom = createComponent(comName);
}
CCLOG("classname = %s", comName);
if (pCom != nullptr)
{
data->_rData = nullptr;
data->_cocoNode = subDict;
data->_cocoLoader = cocoLoader;
if (pCom->serialize(data))
{
ComRender *pTRender = dynamic_cast<ComRender*>(pCom);
if (pTRender != nullptr)
{
pRender = pTRender;
}
else
{
_vecComs.push_back(pCom);
}
}
else
{
CC_SAFE_RELEASE_NULL(pCom);
}
}
if(_fnSelector != nullptr)
{
_fnSelector(pCom, (void*)(data));
}
}
CC_SAFE_DELETE(data);
if (parent != nullptr)
{
if (pRender == nullptr || attachComponent == AttachComponentType::EMPTY_NODE)
{
gb = CCNode::create();
if (pRender != nullptr)
{
_vecComs.push_back(pRender);
}
}
else
{
gb = pRender->getNode();
gb->retain();
pRender->setNode(nullptr);
CC_SAFE_RELEASE_NULL(pRender);
}
parent->addChild(gb);
}
setPropertyFromJsonDict(cocoLoader, cocoNode, gb);
for (std::vector<Component*>::iterator iter = _vecComs.begin(); iter != _vecComs.end(); ++iter)
{
gb->addComponent(*iter);
}
stExpCocoNode *pGameObjects = pNodeArray[12].GetChildArray(cocoLoader);
if (pGameObjects != nullptr)
{
int length = pNodeArray[12].GetChildNum();
for (int i = 0; i < length; ++i)
{
createObject(cocoLoader, &pGameObjects[i], gb, attachComponent);
}
}
//.........这里部分代码省略.........
示例2: createObject
Node* SceneReader::createObject(const rapidjson::Value &dict, cocos2d::Node* parent, AttachComponentType attachComponent)
{
const char *className = DICTOOL->getStringValue_json(dict, "classname");
if(strcmp(className, "CCNode") == 0)
{
Node* gb = nullptr;
if(nullptr == parent)
{
gb = Node::create();
}
std::vector<Component*> vecComs;
ComRender *render = nullptr;
int count = DICTOOL->getArrayCount_json(dict, "components");
for (int i = 0; i < count; i++)
{
const rapidjson::Value &subDict = DICTOOL->getSubDictionary_json(dict, "components", i);
if (!DICTOOL->checkObjectExist_json(subDict))
{
break;
}
const char *comName = DICTOOL->getStringValue_json(subDict, "classname");
Component *com = ObjectFactory::getInstance()->createComponent(comName);
if (com != nullptr)
{
if (com->serialize((void*)(&subDict)))
{
ComRender *tRender = dynamic_cast<ComRender*>(com);
if (tRender == nullptr)
{
vecComs.push_back(com);
}
else
{
render = tRender;
}
}
}
if(_fnSelector != nullptr)
{
_fnSelector(com, (void*)(&subDict));
}
}
if (parent != nullptr)
{
if (render == nullptr || attachComponent == AttachComponentType::EMPTY_NODE)
{
gb = Node::create();
if (render != nullptr)
{
vecComs.push_back(render);
}
}
else
{
gb = render->getNode();
gb->retain();
render->setNode(nullptr);
}
parent->addChild(gb);
}
setPropertyFromJsonDict(dict, gb);
for (std::vector<Component*>::iterator iter = vecComs.begin(); iter != vecComs.end(); ++iter)
{
gb->addComponent(*iter);
}
int length = DICTOOL->getArrayCount_json(dict, "gameobjects");
for (int i = 0; i < length; ++i)
{
const rapidjson::Value &subDict = DICTOOL->getSubDictionary_json(dict, "gameobjects", i);
if (!DICTOOL->checkObjectExist_json(subDict))
{
break;
}
createObject(subDict, gb, attachComponent);
}
return gb;
}
return nullptr;
}