Created
July 3, 2012 18:25
-
-
Save jls/3041591 to your computer and use it in GitHub Desktop.
Cocos2d-x Static Constructor Macro
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
#define STATIC_CONSTRUCTOR(className, methodPostfix, methodArgs, initArgs, constructorArgs) \ | |
static className* create ## methodPostfix methodArgs \ | |
{ \ | |
className *instance = new className constructorArgs; \ | |
if (instance && instance->init ## methodPostfix initArgs) \ | |
{ \ | |
instance->autorelease(); \ | |
} \ | |
else \ | |
{ \ | |
CC_SAFE_DELETE(instance); \ | |
} \ | |
return instance; \ | |
}; | |
// This example call: | |
// STATIC_CONSTRUCTOR(MyScene, WithTitle, (const char *title), (title), ()) | |
// | |
// generates: | |
//static MyScene* createWithTitle(const char *title){ | |
// MyScene *instance = new MyScene(); | |
// if(instance && instance->initWithTitle(title)){ | |
// instance->autorelease(); | |
// }else{ | |
// CC_SAFE_DELETE(instance); | |
// } | |
// return instance; | |
//} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment