The push, pop, replacement or end of the current scene is made by director. It knows which scene is currently active, and it handles a stack of scenes to allow things like “scene calls” (pausing a Scene and putting it on hold while other enters, and then returning to the original). The Director takes care of various scenes. In our project in file AppDelegate.cpp: Helloworld scene is created using Inside this one scene there can be many layers. All the inputs, audio, images are all drawn on the scene which is visible. To say it simply Only one scene can be running at a time. Layers are subclass of CocosNode, they can be transformed manually or by using actions.Ī “scene” in Cocos2d is just a special sort of node that acts as the ultimate parent for all other nodes that are visible. In our project in file HelloWorldScene.h: A layer is createdĬlass HelloWorld : public cocos2d::CCLayerĪnd “X” button and label “HelloWorld” are all added to this layer. Each layer may contain images, animations, labels, buttons, Sprites etc There can be one or more layer in a scene. To understand these files first of all you have to understand the Architecture of cocos2dx. So now we see what each file do for your first project. The new project now has a list of files of type. Yea you had created a basic BubbleBurst with cocos2dx template in visual studio 2010. PLabel->setPosition(ccp(size.width / 2, size.height – 50)) Īnd finally we need to add it to the layer to draw on the screen like 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.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |