Loading the menu scene at start of the app

To load the main menu scene instead of the HelloWorldScene on startup, open the AppDelegate.cpp file. Here on the top, include MainMenuScene.h. In the applicationDidFinishLaunching() function, find the following line of code:

CCScene *pScene = HelloWorld::scene(); 

Replace it with the following code:

CCScene *pScene = MainMenu::scene(); 

That is all; now if you build and run it, you will see the main menu loaded:

Loading the menu scene at start of the app

Now if you click on the play button, the game will start. How to go back to the main menu? We will add a button in the gameover() function, which will take us back to the main menu, but first let's ...

Get Learning Cocos2d-x Game Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.