Cocos2d-x Study Notes (2)-Basic Elements of scenarios

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.