[Cocos2d-x Study Notes] zoder, Tag, scene switching, various creation methods of the genie, three special layers, coordinate system

Source: Internet
Author: User

Zoder:

1. It is the value describing the rendering order. Each ccnode has a zoder. The default value is 0.

2. The greater the zoder, the more it will be drawn later. If the zoder value is the same, it depends on the order of arrival (global variable plus one each time). The first added node is drawn first, zoder only compares nodes with the same parent node.

Tag: ID card of a node. It is convenient to get the Node object through getchildbytag. Its significance is to reduce the member variables.

The tag is valid only between nodes with the same parent node.

The tag cannot be the same among the sons of the same parent node. In the same case, Cocos does not report an error. getchildbytag may obtain the ccnode

Generally, enumeration is used to indicate tags to prevent duplication.

Tags are sometimes used when IDs are used

 

Scenario Switching

Ccdirector

Runwithscene running scenario

Replacescene released in original scenario

Original scenarios reserved for pushscene Switching

Use and switch popscene and push

Pause pause

Resume. I forgot this.

End

 

Genie Creation

1. directly create an genie through a file

Ccsprite * sprite = ccsprite: Create ();

2. Create genie through texture

Cctexture2d * texture = cctexturecache: sharedtexturecache ()-> addimage ("blocks.png ");

Ccsprite * sprite = ccsprite: createwithtextrue (texture );

3. Create an genie through the genie Frame

Ccsprtieframe * frame = ccsprtieframe: createwithtexture (texture, ccrectmake (0, 0, 80, 80 ));

Ccsprite * sprite = ccsprite: createwithspriteframe (FRAME );

4. Create an genie through the sprite frame Cache

Ccspriteframecache: sharedspriteframecache ()-> addspriteframe (frame, "myframe ");

Ccsprite * sprite = ccsprite: createwithspriteframename ("myframe ");

 

Three special layers

Cclayercolor can change the background and set the size.

Cclayercolor * layer = cclayercolor: Create (ccc4 (255, 0, 0,255), winsize. weith/2, winsize. Height/2 );

 

Cclayergradient layer with gradient effect (color, transparency, direction)

Cclayergradient * layer = cclayergradient: Create (ccc4 (0,255, 0, 0), ccc4 (0, 0,255,255 ));

 

Cclayermultiplex is rarely used. It can contain several layers, but only displays one of them.

Cclayermultiplex * multi = cclayermulitiplex: Create (layer1, Layer2, null );

Multi-> switchto (1); // display Layer2

 

Coordinate System

GL coordinate system: the origin is in the lower left corner.

Ui most standard system: the origin is in the upper left corner.

 

World coordinate system: it is the coordinate system of the window. It is the GL coordinate system, and the origin is in the lower left corner of the window.

Node coordinate system: it is a node coordinate system, and it is also a GL coordinate system. Unlike the world coordinate system, its origin is the lower left corner of the node.

When a node calls setposition, the parameter used is the coordinate system of its parent node (rendering tree.

The size of the cclayer is the same as that of the window by default, so the coordinate system and the world coordinate system overlap.

The default size of ccscene is the same as that of the window, so the coordinate system and the world coordinate system overlap.

 

Conversion between GL coordinates and world coordinates

Ccdirector: shareddirector ()-> converttoui ();

Ccdirector: shareddirector ()-> converttogl ();

Conversion between world coordinates and node coordinates

Ccnode: convertonodespace (ccpoint ptinworld );

Ccnode: convertoworldspace (ccpoint ptinnode );

Convert by Anchor Point

Ccnode: convertonodespacear (ccpoint ptinworld); returns the node coordinate, starting from the anchor point.

Ccnode: convertoworldspacear (ccpoint ptinnode );

Use touth for parameter conversion

Ccnode: converttouchtonodespace: Convert the touch to the coordinates of the node coordinate system.

 

[Cocos2d-x Study Notes] zoder, Tag, scene switching, various creation methods of the genie, three special layers, coordinate system

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.