Now we need to position them on the screen like OK we had created various items like menu item, label, sprite. We have to pass the image name to Create function in the class CCSprite to create and draw an image. This is how a label with text “Hello World”, font “Arial” of size “24” is created.ĬCSprite* pSprite = CCSprite::create(“HelloWorld.png”) In that function code for handling the click event is writen.ĬCLabelTTF* pLabel = CCLabelTTF::create(“Hello World”, “Arial”, 24) And on clicking on that image (click event), it will call a function HelloWorld::menuCloseCallback. Menu_selector(HelloWorld::menuCloseCallback)) Ī menu item with Image(normal and mouse over) is added. On the Init() function MenuItem, Label and Images are added to this Helloworld layerĬCMenuItemImage *pCloseItem = CCMenuItemImage::create( This is inherited from a Layer class(CCLayer) and have a function scene which will return a scene object to the “ Director” in the Class AppDelegate. This class is the main class of the game. The MainMenu of our game BubbleBurst look like For click event of these three item, three function are added for handling the click event. 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. ![]() We can set the window title by function setViewName. ![]() flag stored in app delegate to know whether we are retina I'd hate to do something like this but I will if no better solution exists: float padding = 4.0f Any ideas as to why?Ĭode: CCMenuItemSprite *itemPlay = On non-retina device the padding appears as expected, but when in retina mode on simulator the padding seems to be doubled. I'm using to layout several buttons (CCMenuItemSprite) vertically.
0 Comments
Leave a Reply. |