How to create macro function with args for CREATE_FUNC macro in cocos2dx
In sample project,create scene object with CREATE_FUNC("scene name")
CREATE_FUNC macro is create scene and call autorelease function like below
#define CREATE_FUNC(__TYPE__) \
static __TYPE__* create() \
{ \
__TYPE__ *pRet = new(std::nothrow) __TYPE__(); \
if (pRet && pRet->init()) \
{ \
pRet->autorelease(); \
return pRet; \
} \
else \
{ \
delete pRet; \
pRet = nullptr; \
return nullptr; \
} \
}
But there are no args for pathing value with another scene.
So create CREATE_FUNC macro with args
#define CREATE_FUNC_WITH_ARGS(__TYPE__) \
template \
static __TYPE__* create(Args&&... args) \
{ \
__TYPE__ *pRet = new(std::nothrow) __TYPE__(); \
if (pRet && pRet->init(std::forward(args)...)) \
{ \
pRet->autorelease(); \
return pRet; \
} \
else \
{ \
delete pRet; \
pRet = NULL; \
return NULL; \
} \
}
This is available in cocos2dx 3.15.1