Scene, ctor, layer and Sprite

Source: Internet
Author: User

Scene:

In applications, scene is a relatively independent component. In many other engines, it is also called "canvas" or "stage ".

In the cocos2d-x, one application can have multiple scene, but only one is acitve at any time. A ccscene consists of multiple ccnodes. Generally, it contains several cclayers, and cclayers contain multiple ccsprite. It should be noted that ccscene, cclayer, and ccsprite all inherit ccnode, except that the latter has other parent classes which are implemented using multi-inheritance. It is known that the visual data organization of the cocos2d-x is a scene tree, but some of the intermediate nodes are given additional logic (such as ccscene and cclayer)

Because scene is a subclass of ccnode, you can perform manual or actions transformation.

There is a special scene called cctransitionscene. It is derived from ccscene and can implement special effects such as fading and page turning.

Director:

Director is a shared singleton object used to control switching between scene. Director knows the current active scene. You can use ctor to push a new scene at the top of the stack. Apply the previous scene B to the stack and push
Scene A, but does not destroy scene B from memory. If scene a pops up at the top of the stack, it will switch to scene B and its status will be restored to the status of the previous stack.

Director is also responsible for the initialization of OpenGL ES.

Layer:

A layer is a ccnode that can handle touch events. You can see in the code that it not only inherits ccnode, but also inherits cctouchdelegate. The cclayer knows how to draw itself and allows the player to see other layers. Cclayer is very useful when defining the appearance and behavior of a game, so you should spend a lot of coding time to develop the cclayer subclass you need.

Cclayer can process events in cctouchbegan, cctouchmoved, cctouchended, and cctouchcancelled, and all layers in the scenario will receive these events until a layer is processed.

In addition to being able to develop the cclayer subclass you need, the cocos2d-x also provides several good layers, such as ccmenu, cccolorlayer and cclayermultiplex.

Cclayer can contain any ccnode subclass, including ccsprite, cclabels, and other cclayer subclasses. Cclayer can also be changed manually or using actions.

The following is an example of using a gradient layer:

 1    CCLayerGradient* layer1 = CCLayerGradient::create(ccc4(255, 0, 0, 255), ccc4(255, 0, 255, 255)); 2    layer1->setContentSize(CCSizeMake(80, 80)); 3    layer1->setPosition(ccp(50,50)); 4    addChild(layer1); 5 6    CCLayerGradient* layer2 = CCLayerGradient::create(ccc4(0, 0, 0, 127), ccc4(255, 255, 255, 127)); 7    layer2->setContentSize(CCSizeMake(80, 80)); 8    layer2->setPosition(ccp(100,90)); 9    addChild(layer2);1011    CCLayerGradient* layer3 = CCLayerGradient::create();12    layer3->setContentSize(CCSizeMake(80, 80));13    layer3->setPosition(ccp(150,140));14    layer3->setStartColor(ccc3(255, 0, 0));15    layer3->setEndColor(ccc3(255, 0, 255));16    layer3->setStartOpacity(255);17    layer3->setEndOpacity(255);18    ccBlendFunc blend;19    blend.src = GL_SRC_ALPHA;20    blend.dst = GL_ONE_MINUS_SRC_ALPHA;21    layer3->setBlendFunc(blend);22    addChild(layer3);

Sprite:

The concept of Sprite is similar to that of other 2D engines. It is a 2D image that can be rotated, translated, and scaled.

Sprite can contain other sprite nodes as sub-nodes. When the parent node is changed, the sub-nodes are changed together.

Sprite can be changed manually or using 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.