Created
March 22, 2016 05:27
-
-
Save sergey-shambir/7aa793a18b061465b43e to your computer and use it in GitHub Desktop.
Cocos2d-x make function
This file contains 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
template <class T, class ...TArgs> | |
T *make_cc(TArgs&&... args) | |
{ | |
T *ret = new (std::nothrow) T; | |
if (ret && ret->init(std::forward<TArgs>(args)...)) { | |
ret->autorelease(); | |
return ret; | |
} | |
CC_SAFE_RELEASE(ret); | |
return nullptr; | |
} | |
template <class T, class ...TArgs> | |
cocos2d::Scene *make_scene(TArgs&&... args) | |
{ | |
auto scene = cocos2d::Scene::create(); | |
auto layer = make_cc<T>(std::forward<TArgs>(args)...); | |
scene->addChild(layer); | |
return scene; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment