Next, the order of the articles I write is based on the game development process. Some may not be very reasonable. You can check the order based on your own needs.
In the last HelloWorld, I briefly introduced the concepts of layers and scenarios. Today I will focus on this. Create a new MenuScene class and add the virtual bool init () and static cocos2d: CCScene * scene () functions to the header file. CCScene is a subclass of CCNode and is an abstract concept, at that time, CCNode was different from CCScene's anchpoint in the center of the screen. We used CCScene as the parent node of all nodes. Now we need to implement Scene in the cpp file.
To implement scene initialization, you must add the macro LAYER_NODE_FUNC (MenuScene) to the header file. This macro is the CCLayer inside the engine. (So you also want your MenuScene class to inherit from CCLayer). Its main function is to add a node () function for a layer you have created, this function is used to create an instance and add it to autorelease. This means that no pointer from the node () function needs to be released manually. Scene is the basic unit for CCDirector switching.
The next step is to initialize the init function. If you want to add an image button to the background image, you can use the following methods:
1: CCMenuItemImage
2: CCTextrue2D
If CCTextrue2D is used, OpenGL is used to draw Image Textures instead of image streams. Therefore, memory usage is lower. This-> addChild (....., 1) add the item to the layer. 1 is the sequence on zOrder and Y coordinate. The high layer will cover the things drawn by the lower layer.
3: CCMenuToggle
3: CCMenuToggle
The cocos2d-x provides a convenient item that represents a button similar to a switch and can be initialized using label and sprite
4: CCSprite
The genie is the most expressive in the game. You can use the genie to create any element.
These elements are required to create a basic menu, however, to use these methods flexibly, you still need to exercise more, such as the scenario switching effect and how to obtain nodes through tags... Specific functions can be viewed on the official website.
Author: John_cdy