![]() Void QuitLayer::goBack(CCObject* pSender)ĬCDirector::sharedDirector()->replaceScene(pScene) Void QuitLayer::goQuit(CCObject* pSender) Menu->setPosition(ccp(screenWidth/2, screenHeight/2)) QuitBox->setPosition(ccp(screenWidth/2,screenHeight/2)) ĬCMenuItem * butYes= CCMenuItemImage::create("butyes.png"ĬCMenuItem * butNo= CCMenuItemImage::create("butno.png"ĬCMenu *Menu = CCMenu::create(butYes,butNo,NULL) PSprite->setPosition( ccp(size.width/2, size.height/2) ) ĬCSprite * quitBox = CCSprite::create("quitdialog.png") PSprite = CCSprite::create("introback.png") on "init" you need to initialize your instanceĬCSize size = CCDirector::sharedDirector()->getWinSize() There's nothing very clever here - it uses graphics called 'quitdialog.png' 'butyes.png' etc to construct the dialog box. implement the "static node()" method manually So I made a very basic called call 'QuitLayer' as follows:Ĭlass QuitLayer : public cocos2d::CCLayer I decided on the latter as it would be easy to reuse the code. ![]() There are three options I guess, showing an extra menu on your 'HelloWorld' scene, calling a native java dialog, or showing a 'Quit' layer. Here's how I did it.įirstly, you need to decide how you want to display a 'Do you want to quit' type money. ![]() Without this your app will fail the test procedure for some curated stores (eg Samsung). For click event of these three item, three function are added for handling the click event.With the default Cocos2dx template the back button on your phone won't close the application. And added to the layer for displaying on the screen. Init() function will create a menu with 3 menu items( CCMenuItemFont). Scene() function will create a scene and return the pointer to the director.Īnd MainMenu::create() will create a MainMenu layer and you want to add it to the scene. Void MainMenu::onOptions(CCObject* pSender) Void MainMenu::onNewGame(CCObject* pSender) combine to form a menu and allign VerticallyĬCMenu* menu = CCMenu::create( item1, item2, item3, NULL ) on “init” you need to initialize your instanceĬCMenuItemFont* item1 = CCMenuItemFont::create( “New Game”, this, menu_selector(MainMenu::onNewGame) ) ĬCMenuItemFont* item2 = CCMenuItemFont::create( “Options”, this, menu_selector(MainMenu::onOptions) ) ĬCMenuItemFont* item3 = CCMenuItemFont::create( “Quit”, this, menu_selector(MainMenu::onQuit) ) If you remember this is exactly similar to the HelloWorldScene class which is created automatically by the cocos2dx template.įollowing is the contents of MainmenuScene.cpp And assigned three function for 3 buttons in the menu as designed by us in the beginning of this chapter. We had created MainMenu layer from CCLayer. implement the “static node()” method manually there’s no ‘id’ in cpp, so we recommand to return the exactly class pointer ![]() Method ‘init’ in cocos2d-x returns bool, instead of returning ‘id’ in cocos2d-iphone ![]() Create 2 files MainmenuScene.h and MainmenuScene.cpp.ĭownload the code here for this tutorial.įollowing is the contents of MainmenuScene.h For this we have to create a main menu layer and attach it to a main menu scene.
0 Comments
Leave a Reply. |