Cocos2d-x template project structure analysis 3

Source: Internet
Author: User

Next

Fat goat fart

Why are we so arrogant? Because we haven't reached that level yet, at least we haven't reached it. I think you can understand what you have done when you omit it. Now let's take a look at it. I want to find my own pace, just like the basic skills in dota.



1. resource folder

Stores game images, audio, configuration, and other resource files. You can create subfolders. The default directory is the game running directory.

2. include and source folders

Place the game header file and source code file. The project template adds main. h, main. cpp, and resource. h. They are platform-related program files, which are available on the windows platform.

Note: The program portal and resource file management are different on different platforms, but the cocos2d-x template has handled these details for us, not to be too much of them.

3. AppDelegate. h and AppDelegate. cpp files

A universal entry file for Cocos2d-x games, similar to the file where the main function is located in a general Windows project. In IOS, AppDelegate is also the entry file of the program.

AppDelegate. cpp contains automatically added code. The file implements the AppDelegate class. AppDelegate controls the game lifecycle.

Three important methods

A ---- called after the applicationDidFinishLaunching () application is started. The default implementation includes the necessary preparations for starting the game.


CCDerector engine controller. (Attribute settings are not mentioned. They are included in the book)

CCScene scenario.

The assignment engine runs this scenario.

We also need to perform other necessary initialization for our game here, such as reading game settings and initializing the random number list.

B ---- called when the applicationDidEnterBackground () program enters the background.


When you call. Pause music and action.

C ---- applicationDidEnterForeground ()


It appears in pairs with applicationDidEnterBG () and is used when the application returns to the foreground.


4. HelloWorldScene. h and HelloWorldScene. cpp

Defines the default game scenario in the Hello World project.

The game structure of cocos2d-x is scene --------------- layer -------------- genie.

These two files are the implementation files of the scenario. Each game group can be added to another component to form a hierarchy.

HelloWorldScene defines a HelloWorld class, which inherits from CCLayer because HelloWorld itself is a layer.


The HelloWorld class contains a static function and two instance methods.


A -------- static cocos2d: CCScene * scene ()

Setting a static function for creating a scenario at the layer is a common technique.

Static cocos2d: CCScene * scene () in addition to this creation method

CCScene * scene = CCScene: create ();

HelloWorld * layer = HelloWorld: create ();

Scene-> addChild (layer );

Note that addChild () can place one game element into another. (The element is displayed only when it is placed in other game elements that have already been presented .)


B ---------- bool init ()

Initialize the HelloWorld class

Aa --- initialize the parent class

CC_BREAK_IF (! CCLayer: init (); macro definition (# define CC_BREAK_IF (cond) if (cond) break)

AB --- create a menu bar and add it to the Layer

CCMenuItemImage * pCloseItem = CCMenuItemImage: create ("CloseNormal.png", "CloseSelected.png", this, menu_selector (HelloWorld: menuCloseCallback ));

PCloseItem-> setPosition (ccp (CCDirector: shareddire()-> getWinSize (). width-20, 20 ));

CCMenu * pMenu = CCMenu: create (pCloseItem, NULL );

PMenu-> setPosition (CCPointZero );

This-> addChile (pMenu, 1 );


Ac --- create a "Hello World" label and add it to the Layer

CCLabelTTF * pLabel = CCLabelTTF: create ("Hello World", "Arial", 24 );

CCSize size = CCDirector: shareddire()-> getWinSize ();

PLabel-> setPosition (ccp (size. width/2, size. height-50 ));

This-> addChile (pLabel, 1 );


Ad---create a wizard that displays helloworld.png and add it to the Layer

CCSprite * pSprite = CCSprite: create ("HelloWorld.png ");

PSprite-> setPosition (ccp (size. width/2, size. height/2 ));

This-> addChiled (pSprite, 0 );

Return true;

I need to repeat it here, because my programming skills are weak and I don't know where to get started. Ah, dish.

Why do we need to initialize the class in the init method instead of the constructor initialization. This is a problem with the programming style of cocos2d-x.

There are a variety of test examples under the test project.


Now our cocos2d-x has opened its door.

The main concepts of these three chapters,

A: What is cocos2d-x, based on cocos2d-iphone multi-platform two-dimensional game engine, attention is two-dimensional. Powerful drawing code is encapsulated for developers, allowing developers to focus on game development rather than drawing operations.

B: The program entry file of the AppDelegate project. Provides control events for the life cycle of a program.

C: game elements, any element that can be presented, scene, layer, and genie

D: CCNode: addChild

The previous chapters will be slow and the future will be faster and faster. Hope to help you


I would like to recommend a good-looking cartoon, a foreign man: Wang wuyetan.

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.