101 cocos2d-x projects: Scenes, ctor, Layers, Sprites

Source: Internet
Author: User

  • Cocos2d-x 101 encounter/directory
    1. Installation and environment setup-xcode
    2 Scenes, Director, Layers, Sprites
    3. Create an image menu
    4. Create a new scenario on HelloWorld
    5. Add a sprite.
    5.1 scale down sprite and display it completely
    6 action, mobile sprite
    3.0 Click Event, CCTouchDelegate has been disabled
    8 use the touch event mobile genie


2. Scenes, Director, Layers, Sprites


To develop a cocos2d application, you must first understand the following four concepts:

Scenes

Director

Layers

Sprites

Scenes

Scene (CCScene class) is an independent block in an app workflow. Scene is also called screents or "stages". An app may have multiple scenes, but only one of them can be activated at any time. For example, a game may have the following scenes: Intro, Menu, Level 1, Cutscene 1, Level 2, Winning cutscene, losing cutscene, High scores screen, etc. you can define these scenes as independent application blocks. These scenes contain the interconnected logic (when interrupted or completed, the intro enters the menu, level1 guides you through the cutscene Channel 1 if the cutscene is completed or lost, and so on)

A cocos2dCCScene object is composed of one or more layers (layers are CCLayer objects. Layer provides the appearance and behavior of scene. Generally, one or more layers are used to instantiate a scence directly. The CCScene subclass CCTrasitionScene implements mobile transitions, provides the transfer effect between two scenes (such as fade out/in, slide from a side, and so on ).) because scenes is a CCNode subclass, scenes can manually or use actions to change coordinates.

Director

CCDirector is responsible for moving forward or backward between scenes.

CCDirector is a shared object in singleton mode. It knows which scene is active. CCDirector processes scenes calls in stack mode (when another scene enters, the current scene is suspended, and then the original scene is returned). CCDirector is responsible for replacing CCScene, when the CCLayer is pushed, the current scene is replaced or ended. In addition, CCDirector initializes OpenGL ES.

Layers

Layer: Layers

A CCLayer object defines a descriptive area and a descriptive rule. CCLayer can achieve a translucent effect, allowing you to see the layers behind it. In summary, CCLayer is used to define the appearance and event behavior. Therefore, when writing a cocos2d program, most of the work is to write the CCLayer subclass to achieve the desired effect.

CCLayer is responsible for event processing. Events will be passed from the first to the last layers until a layer gets the event and processes it.

Although you need to customize a CCLayer class at a time, cocos2d has implemented multiple layers (such as menu layer: CCMenu, color layer: CCColorLayer, and so on ).

Layers can contain CCSprite objects, CCLabel objects, and other layer objects. Layers is a subclass of CCNode, so they can also use actions to convert coordinates. See Actions for more detail about actions.

Sprites

Cocos2d sprite objects are 2d images that can be moved, selected, scaled, and animated. child members of CCSprite objects can contain other CCSprite objects. When a CCSprite object converts a coordinate system, the CCSprite object it contains also converts the coordinate system. Sprites is a subclass of CCNode, so they can also use actions to convert coordinates. See Actions for more detail about actions.

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.