Search code examples
c++cocos2d-xcocos2d-x-3.0

Execution flow in cocos2d-X


I am newbie in cocos2d-x.I want to know the execution flow.After searching many websites and forums,still I am unable to understand that from where actual execution starts.


Solution

  • All the classes are in the Classes directory of the project.

    In the AppDelegate class you define the initial scene of the game through a Director instance. For example:

    // create a scene. it's an autorelease object
    auto scene = MainMenuScene::createScene();
    
    // run
    director->runWithScene(scene);
    

    Then in the init function of each Scene you can add a callback to allow calling a function when an event happens. For example:

    auto playItem = MenuItemImage::create("MainMenuScreen/Play_Button.png", "MainMenuScreen/Play_Button.png", CC_CALLBACK_1(MainMenuScene::GoToGameScene, this));
    

    Then in a particular event of each scene you can move to another scene through the Director singleton. For example.

    auto scene = GameScene::createScene();
    Director::getInstance()->replaceScene(scene);
    

    You can find example source code at this link.