Quantcast
Channel: cocos2d-x - Cocos Forums
Viewing all articles
Browse latest Browse all 2748

Why the layer must be created from my class and not from layer class?

$
0
0

@lionking0 wrote:

I am confused about something.
I have the following example:

mainMenu.h

class mainMenu : public Node {
public:
    static Scene* createScene();
    virtual bool init();
    void GoToGameScene(Ref *pSender);
    CREATE_FUNC(mainMenu);


private:
    mainMenu() {};
    ~mainMenu() {};


};

mainMenu.cpp

Scene* mainScene::createScene(){
    auto scene = Scene::create();
    auto layer = mainScene::create();
    scene->addChild(layer);

    return scene;
}

Focus on this part.

auto scene = Scene::create();
auto layer = mainScene::create();

Why do we create layer from mainScene not from Layer

For example: Why we do this:

auto layer = mainScene::create();

If we can do it, like creating a scene

auto layer = Layer::create();

Posts: 9

Participants: 3

Read full topic


Viewing all articles
Browse latest Browse all 2748

Latest Images

Trending Articles



Latest Images