[Cocos2d 2.x IOS study Note 3] About cocos2d Design Mode

Source: Internet
Author: User

The cocos2d design mode is different from the MVC mode used for iOS application development. We know that in MVC mode, the model and view are completely separated, and two parts are connected through viewcontrollers. Cocos2d generally does not use the MVC mode. The root cause is that the running mode and structure of cocos2d are completely different. The following are my opinions.

Cocos2d 2.x is developed based on OpenGL ES 2, soProgramThe running process is the update frame process, that is, the page frame is constantly updated to run the program. Therefore, logical judgment or game AI must be computed in update. Therefore, both view and model must be updated to make the two closer. This is one of the reasons.

On the other hand, a general game will have many objects, such as the characters in various games, the display, animation, and AI of each object are different, and may be very complicated, if the display and AI are separated, the display should be determined by AI in the update process, and the display status, such as location, in turn affects the AI judgment process. This cross-linking will become extremely troublesome, it is estimated that numerous protocols are required. Therefore, it is better to encapsulate AI in a class to display an object. This is the second reason.

Then there is the cocos2d software architecture. It can be said that cocos2d games are like making a movie. Even the objects in cocos2d refer to the exclusive terms in film shooting. The hierarchical relationship diagram of cocos2d node:


This figure is taken from learning cocos2d.

As you can see, unlike the general architecture of iOS, we should first review the general situation of IOS. The program starts and produces a window. Then there are various views in the window, which are controlled by viewcontroller.

So what is cocos2d like?

The program starts to generate a ccdirector (Director), and there are many scene (scenarios) under Director, and Director (Director) is responsible for switching various scene (scenarios ). Then there are different layers under a scene, just like scenes in a movie have backgrounds, figures, and items, and these things are at different layers. Then each layer can have different Sprite, which is the object to be controlled. For example, there may be many people on the Character layer. Each person is a sprite. Professional translation is called a child image. I think it can be called a role or a prop. So for a Sprite, such as a person, it has both thinking, internal (model) and performance (view), as long as a complete sprite (class) is added to the layer, the next thing is to let the sprite behave as update (the time passes.

Therefore, in game development, the more common way is to regard sprite as a whole, and encapsulate its model and view together through a class, it feels like a creature created in the virtual world of the game, and then you are like a god in the game, adding "creature" to the game world as you wish, then, you can fully view the activity of "creature". Of course, as a "God", you have mastered all the information in the game. It feels more and more like the hacker empire. However, when the AI level is high enough, you can truly become the "God" of the virtual world to create a virtual universe.


Through the above analysis, I think we know exactly how to develop a game using cocos2d, that is

Create a game world like God! Direct the game process like a director!

I think this is also a pleasure to make a game!

Question: How to Create a game world?

How did God create the world?

First, create basic particles, then the particles form various substances, and then the substances form a variety of more responsible substances. Then, some substances form a creature, from plants to animals, finally to the most responsible human.


The same is true for games. In order to make the program structure clear, when writing the class, it should also be similar to the above structure, first write some basic classes, and then inherit to write more specific child classes. For example, in a game, there are movable and non-movable items. Then, you can first create a base class, such as gameobject, to put the common attributes, and then write sub-classes in different situations, this makes it clearer.

Let's talk about this first! Next, let's talk about the specific program structure! Anatomy!


[Note: This article is originalArticle. If you need to reprint it, please indicate the source! Thank you for your cooperation.]


 

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.