Last active
August 29, 2015 14:02
-
-
Save kyokomi/2d2c99787868763a7853 to your computer and use it in GitHub Desktop.
CocoStudioのUIEditorで作ったLayoutから特定のWidgetを再帰的に取得します
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
@file WidgetUtil.h | |
@author kyokomi | |
@date 2014/06/21 | |
*/ | |
#ifndef __Kyokomi__WidgetUtil__ | |
#define __Kyokomi__WidgetUtil__ | |
#include "cocos2d.h" | |
#include "cocostudio/CocoStudio.h" | |
#include "ui/CocosGUI.h" | |
class WidgetUtil | |
{ | |
public: | |
static cocos2d::ui::Widget* getChildByNameRecursion(cocos2d::ui::Widget* rootWidget, std::string name) | |
{ | |
for (auto& child : rootWidget->getChildren()) | |
{ | |
if (child) | |
{ | |
cocos2d::ui::Widget* widgetChild = dynamic_cast<cocos2d::ui::Widget*>(child); | |
if (widgetChild) | |
{ | |
if (widgetChild->getName() == name) | |
{ | |
return widgetChild; | |
} | |
else | |
{ | |
auto widgetGrandChild = getChildByNameRecursion(widgetChild, name); | |
if (widgetGrandChild) | |
{ | |
return widgetGrandChild; | |
} | |
} | |
} | |
} | |
} | |
return nullptr; | |
} | |
}; | |
#endif /* defined(__Kyokomi__WidgetUtil__) */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
使い方
xxxxxx.json
は、各自UIEditorで作成してExportしたもの。