Drawing coordinate system. It is the most common coordinate system. It is the same as the coordinate system used by OpenGL. It takes the lower left corner as the origin, the right as the positive direction of the X axis, and the upward direction as the positive direction of the Y axis, as shown in 3-1. In the Cocos2d-x, all plot-related operations use the plot coordinate system, such as the position and anchorpoint attributes in the game element.
Texture coordinate system. The texture coordinate system uses the upper left corner as the origin, the right side as the positive direction of the X axis, and the downward side as the positive direction of the Y axis, as shown in 3-2. In the Cocos2d-x, only
This coordinate system is used only when some rectangles are captured from the texture, such as the texturerect attribute of ccsprite.
After a simple touch to the coordinate system in the Cocos2d-x, let's look at the plot-related properties that ccsprite has. With these attributes, We can precisely control the way the essence is presented.
Ccrect contentsize: Get or set the content size of this node. Any node must determine its content size for graphic transformation. For
For the genie, contentsize is the size of the texture display part. For large nodes such as layers or scenes in full screen mode, contentsize is the screen size. Ccpointanchorpoint and ccpointposition: anchorpoint are used to set an anchorpoint to precisely control the node position and transformation. The two parameters X and Y of anchorpoint are usually real numbers between 0 and 1, indicating the position of the anchorpoint relative to the node length and width. For example, you can use the lower-left corner of a node as the anchor, and set the value to (0.5, 0.5). You can use the lower-right corner of a node as the anchor, the value is (1, 0 ). The default anchorpoint value of the genie is (0.5, 0.5), and the default value of other nodes is ). Figure 3-3 demonstrates the values and positions of the three different anchor points. Position is used to set the node position. Because position refers to the coordinate value of the anchor in the parent node, the position displayed on the node is usually related to the anchor. Therefore, if the layer and the scenario keep the default position, you only need to set the genie position in the layer to half of the window width to display it in the center of the screen.
For large nodes such as scenes or layers, their ignoreanchorpointforposition attribute is true. In this case, the engine considers anchorpoint to always be );
This attribute of other nodes is flase, and their anchors are not ignored.
? & Nbsp; float rotation: gets or sets the Rotation Angle of a node. The node rotates clockwise for a certain amount based on its own anchor. The unit is angle. The rotation angle can be any real number.
? & Nbsp; floatscale (and floatscalex and floatscaley): scale is used to obtain or set the scaling ratio of nodes. Nodes are scaled at the center of the anchor. The scale value represents the overall scaling ratio, while scalex and scaley represent the zooming ratio in the X and Y directions, respectively. By default, the values of these three attributes are 1, indicating that the node is not scaled. If the scale attribute is set, scalex and scaley both change to the same value. Of course, we can also set different values for scalex and scaley, so that the value of the scale attribute is meaningless.
? & Nbsp; boolvisible: gets or sets the node visibility. When visible is true, the node is displayed, and the node is not displayed. When the node is not displayed, the plotting method (visit and draw) is not called ). What makes this attribute different is that its accessors do not follow the naming rules of the attribute. The following is the method of its accessors: ccnode attribute
| |
|
Ccarray * Children |
? Obtains the array that stores all sub-references of the node. |
? Ccnode * parent |
? Obtains or sets the parent node of the node. |
? Cccamera * camerareturn |
? Obtains or sets the camera status of the node. Camera? (Cccamera) defines the point of view when this node is drawn ,? It is usually used to implement special effects. |
? Ccgridbase * Grid |
? Obtains or sets the grid effect status of the node. Grid applications? 3D effects such as water prints can be realized on the drawing plane. |
? Ccglprogram * shaderprogram |
? Obtains or sets the shader program of the node. Ccglprogram? Is the glprogram encapsulation of OpenGL. |
? Ccactionmanager * actionmanager |
? Obtains or sets the Action Manager used by the node. When it is a section ? Click the action that is being executed when a new Action Manager is set. ? Will be discarded. The relevant content of the Action Manager will be introduced in chapter 4th |
46
Cocos2d-x advanced development tutorial
? Ccscheduler * Scheduler |
? Gets or sets the timer manager used by the node. ? When a new timer manager is set for the node, ? All running timers are discarded. |
Node Organization
? Method |
? Description |
? Addchild (ccnode * child) |
? ADD child to the current node |
? Removefromparentandcleanup? (Bool cleanup) |
? Remove the current node from its parent node. If? If cleanup is true, the clean method is executed. |
? Removechild (ccnode * child ,? Bool cleanup) |
? Remove the child node from the current node. If ? If cleanup is true, the clean method of child is called. |
? Removechildbytag (Int? Tag, bool cleanup) |
? Remove a tag-based node from the current node |
? Removeallchildrenwithcleanup? (Bool cleanup) |
? Remove all child nodes of the current node |
? Getchildbytag (INT tag) |
? Returns the tag-based node of the current node. |
? Cleanup |
? Stop all actions and timers on this node |