Cocos2d-x 3.0 final Terminator series tutorial 04-engine Architecture Analysis

Source: Internet
Author: User

Once upon a time, an Android-based student always asked me:

Instructor Shen, why is the window in Android called Activity? Why do I need to write setContentView (R. layout. main) IN THE onCreate method )?

I said:

Can you follow the steps I taught you to implement a window?

Step 1 add an Activity tag in AndroidManifest. xml

Step 2 Write a class that inherits the Activity and overwrites the onCreate Method

He said:

I want to know why I need to implement the Activity and onCreate methods before I can complete this exercise.

I said:

You can create a window by implementing the Activity and onCreate methods, and you will understand why you are doing this in the future.

He said:

I must understand before doing so.

I said:

You must do it to understand.

.................................

In the evening, we both drank too much .................................. ........................................ ................

----------------------------------------- Split line --------------------------------------------------------------

1. The project source code directory after cocos new is as follows:

-- Classes project source code file (here is the user source code, excluding the engine, each project will have an AppDelegate class inheriting the Application)

AppDelegate. h

AppDelegate. cpp

......

-- Resources project resource files (images, sounds, videos, map files, animation files, and particle files)

-- Cocos2d engine source code (I think it is extremely reasonable to put the source code back into the project directory)

-- Proj. android project file

-- Proj. ios_mac xcode project file

-- Proj. linux

-- Proj. win32 VS2012 project file

-- Proj. wp8-xaml

2. Entrance of Cocos2d-x Project

It is clear that all programs have entered from the main function, and different platforms have different platforms. windows platform is

Winmain function. The Android platform is an entry Activity, and the ios and linux platforms are also main functions.

Is how to solve it, we look at the Cocos2d-x system architecture, such:

Cocos2d-x games or applications developed with JavaScript language for use

In addition to generating apps for different platforms, game projects developed with JavaScript scripts can also be quickly ported to the Cocos2d-html5 platform.

C ++ Application Layer:

Cocos2d-x games or applications developed directly using Cocos2d-x C ++ APIs

---------------------- The above two layers are user code layer labels ---------------------------------------------------------------------------------------

Script interpretation layer:

Provide Lua script support library and JavaScript script support library, of course, this layer is developed using C ++ language, that is, the call of the system platform API and call the Cocos2d-x class library,

If we use a script to develop an application, we may need to modify this layer to make the script application layer and C ++ application communicate with each other, because some projects are not completely scripts or C ++.

Engine core layer:

Use C ++It encapsulates game logic and game plotting functions such as interface drawing, animation playing, music playing, network communication, text processing, file storage, particle processing, and physical engine used in game development.

These functions are mostly provided by the original open source project, integrated in the Cocos2d-x architecture, through the scene, layer, node, action and other Api concepts provided to developers, although the original imitation of cocos2d-iphone

But is there any imitation to surpass it. (But said cocos2d-iphone is also imitation of cocos2d-phthon, the current cocos2d founder Rica joined the Cocos2d-x team, how do you think ???)

Graphic APi layer:

Different platforms provide 3D graphics engines such as OpenGL and DirectX. However, they are extremely cumbersome to use. They wish to display a 6-Face Image and write 20 lines of code. Fortunately, the engine core layer is encapsulated.

(Here we can see, in fact, the bottom layer of the Cocos2d-x drawing is also 3 dimensions, but no development, the future of Cocos3D-x will also have Hello)

System layer:

Since both the layer Api layer and the engine core layer are open-source projects, most system platforms are integrated, such as Android, ios, windows, mac, and linux, bada and other system platforms support the graphic Api layer,

However, each system platform has its own program portal, window creation method, and message processing mechanism, and provides developed APIs at the system layer.

Bytes ---------------------------------------------------------------------------------------------------------------

(Fortunately, although the portal of each system is different, the message processing method is different, and the window creation method is different, but the drawing of the window is basically the same, so you only need to unify the content of different platforms,

In the game is nothing more than Screen Drawing and user interaction two parts, so in different platforms Cocos2d-x has implemented a window to create, and then in this window constantly draw content,

Then, the screen touch messages, button messages, and gravity sensing messages of different platforms are transmitted to the engine for unified processing by users,

The source code contains three important classes: Application ctor EglView,

The Application class is the entry class of the Cocos2d-x, responsible for receiving messages from various platform windows, including window loading is complete, the window enters the background, the window is restored to the foreground

Director is a Director class responsible for screen plotting, coordinate system transformation, message transmission, memory management, and engine main cycle.

EglView is a window object, which completes the plotting and communicates with platform messages.

Each platform has the main method.

Completed in the main method:

1. Create the platform window

2. Create an Application Object

3. Create EglView

4. The Application run method starts the main game loop. In the main loop, FPS ctor controls FPS, game logic, and game graphics.

)

------------------------------- Someone asked, Cocos2d-x on what to make money? -----------------------------------------

If there are many platforms support Cocos2d-x, there are a variety of applications and games, a new platform also want to support (such as win8), it is necessary to develop the system layer of the encapsulation code, at this time it is necessary to pay.

The engine is used for decoration and Investment Promotion (such as Wanda Plaza). The system layer provides venues (real estate companies), and various games at the application layer are merchants (shoes, jewelry, and bags)

The real estate company built two buildings in Beijing and cooperated with Wanda Plaza to attract merchants, attracting users (mobile phone users ),

In this way, with the user consumption-the investment attraction is divided into-the price of the real estate company's location increases.






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.