Cocos2d-x v3.1 coordinate system (5)

Source: Internet
Author: User

Cocos2d-x cocos2d-x Coordinate System

Cocos2d-x v3.1 coordinate system (5)

 

In order to better layout and understand the object location, we must have a detailed understanding of the coordinates in the Cocos2d-x, this article is mainly to understand Cocos used in the coordinate system. Anyone who has studied mathematics knows the "flute Coordinate System", which is also divided into the left-hand coordinate system and the right-hand coordinate system. We know that direct3d and OpenGL respectively use the "left-hand Coordinate System" and "right-hand Coordinate System", then what kind of coordinate system is used by the Cocos2d-x? Since Cocos2d-x is developed based on OpenGL, right-hand coordinate systems are used. Since the Cocos2d-x is a 2D game engine all we use only X and Y axes.

In front of just popularized the concept of the Kazakhstan coordinate system, then there are several coordinate systems in the Cocos2d-x?

 

1.OpenGL Coordinate System

The coordinate origin is at the bottom left of the screen, the X axis is right, and the Y axis is positive. For example:

 

Figure. 1

2. World coordinate system

It is also called the absolute coordinate system. The origin is the same as the OpenGL coordinate system origin. "World" refers to the game world, which establishes the reference standards required to describe other coordinate systems .. 1

3. Screen Coordinate System

It is also called the UI coordinate system. It is mainly used when we touch the screen. The touch point is the incoming screen coordinate. The X-axis at the top left corner is positive to the right, and the y-axis is positive downward.

Figure 2

4. Local Coordinate System

It is also called Relative Coordinate System, which is relative to the parent node. Its coordinate origin is in the lower left corner of the parent object. Suppose we have two objects, node1 and node2.node1, which are the parent nodes of node2 and the position of node1 is vec2 (200,200 ). The position of node2 is VEC (0.5) and the anchpoint is vec2 (0.5,). In this case, the position of node2 is relative to node1. Result 3:

Figure 3

Anchor

An anchor is an anchor point of an object (node and derived object). The orientation and rotation of an object are based on anchor points. The default object's anchpoint is vec2 (0.5, 0.5), that is, in the center of the object. As shown in. 4:

Figure 4

The red dot in the middle is the anchor. Of course, I can also set the anchor to another position. For example, we can set its anchor to vec2 (0, 0 ). That is, the lower left corner of the object .. 5:

Figure 5

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.