init method parameters and LAYER_NODE_FUNC

init method parameters and LAYER_NODE_FUNC
0.0 0


I want to have a layer with an init method like so:

bool GameOverLayer::init(int score, CCString* levelName)

But this breaks the line LAYER_NODE_FUNC(GameOverLayer); in the header. How can I do this with cocos2d-x?


you can replace “LAYER_NODE_FUNC(GameOverLayer);” with:

static GameOverLayer* create(int score, CCString* levelName);
bool init(int score, CCString* levelName);

and in your .cpp file do something like this:

GameOverLayer* GameOverLayer::create(int score, CCString* levelName)
    GameOverLayer *pGOL = new GameOverLayer();
    if (pGOL && pGOL->init(score, levelName)) {
        return pGOL;
    return NULL;

bool GameOverLayer::init(score, levelName)
    bool ret = false;   
    if ((ret = CCLayer::init()))


    return ret;

s. i suppose you use cocos2d-x 2.0.1


Thanks, that worked perfectly