Search code examples
cocos2d-xappdelegate

How to get running scene class type in Cocos2d-x


In Cocos2d i use to get my current running scene through the code:

CCScene *runningScene = [[CCDirector sharedDirector] runningScene];
    if ([runningScene isKindOfClass:[GameScene class]])

Is there any similar method to get this on cocos2d-x also???

I am using:

CCScene *scene = (CCScene *)CCDirector::sharedDirector()->getRunningScene();

but how to compare it with current scene??


Solution

  • You can use dynamic cast which returns pointer of given type or returns NULL value.

    CCScene *scene = CCDirector::sharedDirector()->getRunningScene();    
    GameScene* gameScene = dynamic_cast<GameScene*>(scene);    
    if(gameScene != NULL)
    {
       // scene is type of GameScene
    }