Cocoa learning notes for beginners

Source: Internet
Author: User

CocoaStudy NotesCocoa2dBasic Learning is the content to be introduced in this article.GamesDevelopment should be a sincere passion, so this article can help you solve some problems. If you are a beginner, I think you need to read it. Let's talk about the details.

Cocoa2d Basics

GamesEngine:

I. Scenario CCScene

1. Display scenario 2. Option scenario 3. GamesScenario

In each scenario, different features are implemented through the superposition and grouping of different layers. Therefore, a scenario usually consists of one or more layers.

2. layer CCLayer

Layer is what we writeGamesMore than 99% of our time is implemented on the layer.GamesContent.

Eg: OneGamesThe main Menu screen is superimposed on three layers: Background layer Animation layer Menu layer

In order for different layers to be combined to produce a unified effect, these layers are basically transparent or translucent, And the layers are stacked sequentially, just like the event response mechanism.

Cocoa2dFrom the technical implementation perspective, some common layers are provided: the Menu layer for processing menus, and the ColorLayer for processing colors.

Each layer can contain a variety of content elements, such as text (Label) links (HTMLLabel) Sprite maps.

Iii. Genie CCSprite

Genie is the main target of game development and processing, and it is a local airplane. Tanks are the genie of system AI control. They represent the planes controlled by players. Even a piece of Cloud Flying randomly, a bird is a genie.

Features: Position movement, rotation, enlargement, and contraction

Iv. Director CCDirector

The wizard should not rely on the layer, the layer should not rely on the scenario, and the scenario should not rely on the process.

The director's representative process is responsible for scenario switching throughout the game process, accepting the requirements of the layer object/scenario, terminating according to the pre-designed process, pressing the stress, activating the current scenario, and guiding the next scenario. However, there is usually only one Director. This is an example (singleton). The Coco2D framework has predefined this instance and can be directly used without the need to create it.

At any time, only one Scene object instance is in the active state. This object can be used as the overall inclusion object of the current game content. For Menu objects, it inherits Layer objects ), usually belongs to the main layer of the current scenario.

Implementation class of Cocos2D-iPhone

CCDirector

Creates and manages applications and game main windows, and displays execution scenarios under specific conditions.

Set the Display Properties of the main program window.

Management and display scenarios.

The following methods are used to manage ctor objects:

1. The main program starts and displays the method of the first scenario: (void) runWithScene :( Scene *) scene;

2. Suspend the currently running scenario and press the stack to the queue of the generation execution scenario. Set the input scenario to the current execution scenario: (void) pushScene :( Scene *) scene;

3. In the last scenario in the execution scenario queue, the current scenario is released: (void) popScene;

When there is no substitute execution scenario in the contemporary execution queue, the system exits from the slave node and calls the end method.

4. Replace the current execution scenario directly with one scenario and release the current scenario: (void) replaceScene :( Scene *) scene; the number of returned workers is frequently used.

5. end scenario: (void) end;

6. pause the running of the scenario: (void) pause; the screen crashes, and the time task stops.

7. resume scenario running:-(void) resume;

CCScene

In the current version, there are basically no special features attached. It can be considered as a container of Layer objects.

CCLayer

Function: receives screen touch input from iPone.

Receive Power perception Input

The following three layers are provided:

ColorLayer color layer (you can set the layer size through setContentSize to change the color block size)

Menu layer (the instance must be a MenueItem class or a subclass instance)

The MultiplexLayer composite layer can contain composite layers of multiple layers.

CCSprite

An independent image block is usually a moving (Action) effect, such as moving, rotating, amplifying, and narrowing.

We can set the attributes of Sprite for its motion, or through Action to achieve the same purpose. (95% of the content is simulated by the genie)

1. cache image content to reduce the number of reads of files with the same content

2. Submit painting in batches to reduce the number of OpenGL function calls.

There is a CCSpriteFrameCache class in the example. This class uses images to manage all frames of the Image Rendering effect. This class is directly connected to provide support for a simple image processing tool http://zwoptex.zwopple.com/output file.

Summary:CocoaStudy NotesCocoa2dI hope this article will be helpful to you! IfGamesFor developers interested, see edit recommendations.

Related Article

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.