[Cocos2d-x]-main logic and structure of cocos2d-x games

Source: Internet
Author: User

Cocos2d-x learning exchange group: 140326755 

 

The main logic and structure of Game Development in Cocos2d-x is: first create a scene, add one or more layers on the scene, then you can add genie, menu, text on the specified layer, etc, you can perform an action (or move) for the genie or text to detect player touch-screen events, enable task scheduling to execute Collision Detection and update data, and manage and switch scenarios through the director class.

(1) Director (ccdirector)

In the cocos2d-x engine, the director class ccdirector is a Singleton, which is mainly used to manage and display scenes. It also provides some common attributes, such as obtaining window width and higher.

The director class is the organizer and leader of the game. The director makes rules to enable orderly operation of scenes, sets, and character roles in the game.

(2) camera (cccamera)

Each node requires a camera. When the node scales, rotates, and positions change, the camera must be overwritten so that the node can be re-rendered through the camera.

(3) scenario (ccscene)

It is the game level. The level consists of characters and backgrounds. It can also represent an interface. You can create only one scenario or multiple scenarios. It is a picture of a game. Generally, it is used to draw a scene first, and then overlay or combine one or more layers in the scene.

(4) layer (cclayer)

Our game content is usually displayed on the layer, and different effects are achieved by adding multiple layers. You can set the stack order of the layer to process the event response mechanism. The cocos2d-x provides some common layers: menu layers, color layers, etc. Each layer can contain a variety of content elements: Text, Genie, maps, etc.

(5) genie (ccsprite)

Genie are the core objects in the game, such as enemy planes, heroes, and bullets. Genie are pictures that can be changed constantly, A player operates one or more genie to interact with other gamers or system-controlled genie.

(6) Action)

It is the actions possessed by the genie, such as bullet movement and airplane flight.

(7) task scheduling mechanism

A timer is usually required in the game to call a specified callback function at a specified interval to change the screen display or process data. The cocos2d-x provides a built-in task scheduling mechanism, the schedule member function of ccnode. For example:

This-> schedule (schedule_selector (gamescene: update), 1.0f );

The update function is executed every second. If no time is specified, the update function is executed every frame.

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.