Override scene


#1

Hi there!

I’m trying to create different gameScenes in my game, but there are similar parts like exit from the gameScene, so the solution should be inheritance, unfortunately, I don’t know how, this is what I achieved, but I think it’s not the correct way (however it works). So:

AbstractGameScene.h

class AbstractGameScene : public cocos2d::CCLayer
{
public:
    void init();    
    //static cocos2d::CCScene* scene();
    //CREATE_FUNC(AbstractGameScene);
private:
};

AbstractGameScene.cpp

void AbstractGameScene::init(){
    //add backgrounds, buttons, etc
}

SortSizeScene.h

class SortSizeScene : public AbstractGameScene
{
public:
    virtual bool init();
    static cocos2d::CCScene* scene();
    CREATE_FUNC(SortSizeScene);  
};

SortSizeScene.cpp

CCScene* SortSizeScene::scene(){
    CCScene *scene = CCScene::create();
    SortSizeScene *layer = SortSizeScene::create();
    scene->addChild(layer);
    return scene;
}

bool SortSizeScene::init(){
    if ( !CCLayer::init() ){
        return false;
    }
    AbstractGameScene::init();   
    return true;
}