Member function CCScene::node in coco2d-x deprecated, what should I use now?

In Step by Step Cocos2dxSimpleGame tutorial (Chapter 7 - Some Icing on the Cake), the author uses following code to create game over scene:

GameOverScene *gameOverScene = GameOverScene::node();

which node()is deprecated in cocos2d-x 2.0.1. So I try to replace with following:

GameOverScene *gameOverScene = GameOverScene::create();

but Xcode returns

Cannot initialize a variable of type 'GameOverScene *' with an value of type 'cocos2d::CCScene'

as they declared as different type (node() returns GameOverScene*, while create() returns cocos2d::CCScene).

So, what should I use to replace node()? Is create() the right way or I should use other function?

Yes, you should use create.
The same as node, subclass should implement its own create.

Minggo Zhang wrote:

Yes, you should use create.
The same as node, subclass should implement its own create.

Thanks Minggo, but can you specify how to use it?

I’ve tried:

GameOverScene *gameOverScene = GameOverScene::create();

XCode compile with error as GameOverScene::create() returns cocos2dx::CCScene instead of GameOverScene as node() did. I also tried:

GameOverScene *gameOverScene = (GameOverScene *) GameOverScene::create();

This time, Xcode compile successfully, but when run on a iPhone simulator, it return fail when access line right after create (i.e. gameOverScene->getLayer()->……).

Did you implement GameOverScene::create()?

Minggo Zhang wrote:

Did you implement GameOverScene::create()?

I see, problem solved, thanks Minggo.

Just in case if anyone like to know how to implement, below are the details:

in GameOverScene.h, add following line inside class GameOverScene

static GameOverScene *create(void);

in GameOverScene.cpp, add new function create

GameOverScene *GameOverScene::create()
{
    GameOverScene *pRet = new GameOverScene();
    if (pRet && pRet->init())
    {
        pRet->autorelease();
        return pRet;
    }
    else
    {
        CC_SAFE_DELETE(pRet);
        return NULL;
    }
}

Finally, in HelloWorldScene, when declare gameOverScene, instead of using GameOverScene::node(), use the following:

GameOverScene *gameOverScene = GameOverScene::create();

Done. and similar approach also applied to GameOverLayer.

Use LAYER_CREATE_FUNC(myScene) instead of LAYER_NODE_FUNC(myScene) in youre header