On the basis of the previous section, see How to achieve the switch of the scene.
Add a Scene Welcomescene
#include "WelcomeScene.h" #include "GameScene.h" using namespace cocos2d;
ccscene* Welcomescene::scene () {ccscene * scene = NULL;
do {scene=ccscene::create ();
welcomescene* gamescene=welcomescene::create ();
Scene->addchild (Gamescene);
}while (0);
return scene;
BOOL Welcomescene::init () {this->settouchenabled (true);
BOOL BRet = false;
do {ccsprite* PMap = ccsprite::create ("Welcome_bg.png");
Ccsize size = Ccdirector::shareddirector ()->getwinsize ();
Pmap->setposition (CCP (SIZE.WIDTH/2, SIZE.HEIGHT/2));
This->addchild (pMap, 0); Ccmenuitemimage *pcloseitem = ccmenuitemimage::create ("Startgamenormal.png", "Startgamepresse
D.png ", this, Menu_selector (Welcomescene::menustartcallback)); ccmenu* Pmenu = Ccmenu:: Create (Pcloseitem, NULL);
Pmenu->setposition (SIZE.WIDTH/2,SIZE.HEIGHT/2);
This->addchild (Pmenu, 1);
}while (0);
Bret=true;
return bRet;
} void Welcomescene::menustartcallback (ccobject* psender) {Ccscene * Scene=gamescene::scene ();
Ccdirector::shareddirector ()->replacescene (scene); }