Cocos2d-x Learning (3)-cocos2d coordinate system, Anchor point

Source: Internet
Author: User


1. OpenGL coordinate system

Cocos2d is based on OpenGL, so the coordinate system of COCOS2D and OpenGL is consistent, all in the direction of the diagram. is consistent with the most common coordinate system we normally have.



2. Screen coordinate system

The screen coordinate system is a very common coordinate system in interface programming. It specifies that the upper-left corner of the screen is the coordinate origin, the right is the x-axis positive direction, and the downward is the y-axis positive direction. In contrast to the OpenGL coordinate system, the x-axis direction is actually the same, and the difference is in the y-axis direction.



3, the position of the element
The coordinate system of each element is relative to its parent node, that is, if the parent node moves, the coordinate of the element under the parent node is also relatively moving. Like a person sitting on a boat, the ship is the parent node, the person is a child node, the movement of the ship will naturally lead to the movement of people.


4. Anchor Point of Element

The anchor point is a very important concept that can be understood as the equivalent centroid of an object in physics. In other words, the placement, movement, rotation, etc. of the elements are based on the anchor point. In some interface programming also have the concept of Anchor point, such as C # WinForm programming, control placement is also controlled by an anchor point.

The anchor settings for elements in Cocos2d can be set through functions:

Setanchorpoint (CCP (0, 0))
to set it up.

The values of the two parameters in CPP () are [0, 1]. The meaning of its expression can be expressed in the following diagram:

that is, setting CPP (0, 0) indicates that the anchor point is the lower-left position of the element. By default, the element's anchor point is in the CPP (0.5, 0.5) position, which is the positive center position of the element. (As with images, the bounding envelope of a rectangle must be a rectangle, regardless of whether the element is a rule, and the position of the anchor point is at the center of the rectangle).








Cocos2d-x Learning (3)-cocos2d coordinate system, Anchor point

Related Article

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.