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