Study Notes for cocos2d-x (11)-Coordinate System

Source: Internet
Author: User

Study Notes for cocos2d-x (11)-Coordinate System
There are four coordinates in the cocos2d-x:
(1) screen Coordinate System
In windows, the default origin is in the upper left corner of the screen, and the X axis is right and the Y axis is down.

(2) GL Coordinate System
The origin is in the lower left corner, the X axis is right, and the Y axis is up. Since the cocos2d-x uses the open gl rendering engine, rather than the directx 3d engine, the GL coordinate system does not overlap with the screen coordinate system, which is worth noting. Therefore, when we call a screen RESPONSE event, such as ccTouchEnded (CCTouch * touch, CCEvent * event );
In this case, CCPoint location = touch-> locationInView (touch-> View) returns the position in the screen coordinate system instead of the GL coordinate system. Therefore, there are functions that convert the screen coordinate system to the GL coordinate system.
CCPoing convertedLocation = CCDirector: sharedDirector ()-> convertToGL (location );
 
(3) Local Coordinate System
In the game, each object has its own coordinate system, which is called the local coordinate system.
Relative to the coordinate system of the parent object, the origin is in the lower left corner, the X axis is right, and the Y axis is up. For example, if I use myself as the coordinate origin, objects near me (within my coordinate system) are sub-objects, and I am a parent object, these sub-objects are located in the local coordinate system, which is relative to me (parent object. Here is a code example:
..........
CCLayer * layer = new CCLayer ();
CCSprite * player = CCSprite: spriteWithFile ("player.png ");
Layer-> addChild (player, 1 );
................
Here, the player object is the sub-object, and the layer is the parent object. The position of the player relative to the layer is the position in the local coordinate system. If the layer (parent object) moves, that is, the background is moved, then the player (sub-object) moves, but the position of the sub-object remains unchanged in the local coordinate system, the position of the sub-object in the world coordinate system is changed.
(4) World coordinate system
World coordinates are the so-called absolute coordinates. Although all objects have their own local coordinate systems, these objects also have a coordinate system in the world coordinate system. For example, the whole earth is a world coordinate system, and everyone on the earth
Author: wen294299195

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.