Basic Cocos2d Study Notes

Source: Internet
Author: User

Cocos2dThe basic object of study notes is the content to be introduced in this article.Cocos2dThanks to ZhiyiCocos2dTutorials. Some important points are recorded when you read the tutorials for reference at any time. Let's take a look at the details.

1. Scenario (CCScene): constitute the wholeGamesThe process picture is what we call the scenario.

Different scenarios provide different operations, which can be roughly divided into the following scenarios:

Display scenario: play a video or simply output text on the image to implement the game's opening introduction, victory, failure prompt, and help introduction.

Options: Main Menu, game parameters, etc.

Game scenario: This is the main content of the game. In addition to this scenario, other types of scenarios are basically implemented in a general architecture.

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

2. layer (CCLayer)

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

Layer overlays are ordered. For example, the background of an image numbered 1 is located at the bottom, in the middle of the second, and at the top of the third. The content in the top layer will overwrite the content in the bottom layer.

This order is also used for event response mechanisms in programming models. That is, Layer 3 first receives the system event (click the screen event with your finger), followed by ID 2 and last number 1. When an event is transmitted, if a layer processes the event, the layer at the end will no longer receive the event.

We can simply understand the layer as a window in Microsoft Windows Programming (hWnd, WinForm, and TForm in Delphi ).

Each layer can contain a variety of content elements: Text (Label), Link (HTMLLabel), Sprite, map, and so on. Here, genie is the focus.

The main functions of Layer are as follows:

1) receives touch input from the iPhone.

2) receives an Accelerometer input.

In addition, the layer object itself does not provide more functions.

Cocos2DFor ease of use, the following three bureaus are provided:

ColorLayer color layer: This is a transparent layer that can be filled with colors according to RGB settings. You can use setContentSize to set the layer size and change the color block size. The layer also supports action, flickering, and gradient.

Menu layer: this is a collection class based on Menu objects. The MenuItem class instances form Menu management selection screen layers with various buttons. (Note: The instance in this layer must be a MenuItem class or subclass instance ). The Menu class provides methods to display MenuItem class instances in a horizontal, vertical, or multi-row order.

To achieve different button effects, the system provides multiple types of MenuItem. Each button has three basic statuses: Normal, optional, and disabled.

3. Genie (CCSprite)

Genie is the main object of game development and processing.

Technically speaking, genie is an image that can be changed constantly. The following changes are returned:

Move location

Rotate (with its own geometric center or a screen coordinate as the axis)

Zoom in and out

Motion (displays a series of images at intervals to form motion effects)

A game is a game where one or more Ai-controlled genie interact with an enemy genie controlled by one or more systems: melee, remote shooting, and close-to-conversation.

4. Director (CCDirector)

According to the object-oriented design principles and reverse dependency principles: the wizard should not rely on the layer, the layer should not rely on the scenario, and the scenario should not rely on the entire process. The director is the representative of the entire process. He is responsible for scenario switching throughout the game.

There is usually only one director, so the return object is singleton ). The Cocos2D framework has already predefined the instance, so we can use it directly without creating it.

The Director accepts the requirements of the layer object/scenario, terminates, presses the stack, activates the current scenario according to the pre-designed process, and guides the next scenario.

Note: at any time, only one Scene object instance is active. This object can be used as an inclusive object of the current game content. For menus (Menu objects, inherited Layer objects), it is usually the main unit of the current scene. The above is the overall object architecture of a game.

CCDirectorObjectThe function is similar to the main window in Microsoft Windows programming.Object(The difference is thatObjectIs not visible). It is responsible for creating and managing the application/Game Main Window and displaying and executing a scenario under specific conditions (a View in Windows Programming-View)

5. schedule

InGamesDuring design, we need to change the screen display intermittently to reflectGamesThe most simple result of the operation is to prompt the user that the operation has been run.GamesTime. Therefore, we need to useCocos2DBuilt-in task scheduling mechanism, that is, the CocosNode method: schedule.

Schedule is similar to a timer, which calls a specified number of callback records at a specified interval.

Summary:Cocos2dLearning notes BasicsObjectI hope this article will help you!

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.