- Learning Cocos2d-x Game Development
- Siddharth Shekar
- 475字
- 2021-08-05 18:00:20
Coordinate system
Coordinate systems are used to determine the position of the objects on the screen. Cocos2d-x uses a rectangular coordinate system with the bottom-left corner of the screen being the origin in landscape mode and top-left corner in portrait mode.
From the bottom-left corner of the screen, imagine a line going straight towards the bottom-right corner, which would be the x axis, and a line going up from the origin to the top-left corner, which would be the y axis. There is also a z axis that is coming out of the screen from the origin. This is irrespective of whether you are holding the device in the landscape or the portrait position. Refer to the following figure:

Since Cocos2d-x is the 2D game development framework, we will be mostly dealing with the x and y coordinates. The z axis is used mainly for placing objects in front or behind other objects. To decide which image is above another image, Cocos2d-x has something called a Z-order. The higher the Z-order, the further away from the screen that image will be.
A positive z value means that you are placing the object in front of other objects and a negative z value means that you are placing it behind other objects. For example, the background image would usually have a Z-order of 0 or -1. And you would place other objects at a value that is higher than that value since you would want the background to be behind all the other objects on the screen.
Also, if you don't specify the Z-order while adding a layer or sprite, the next available Z-order will be taken by default. For example, if you add a background sprite and then immediately add the player sprite, the player sprite will be drawn above the background and you will be able to see both the player and the background. If you add them the other way around, you won't be able to see the player as the background is at a higher Z-order than the player and hence the player will be drawn beneath the background and you will be able to see only the background. You might think the player is not drawn but in fact the player is being drawn but under the background, so you don't see it.
The distance is measured in pixels. So assume you have a Nokia 820, which has a screen resolution of 800 x 480 when viewing the screen in landscape mode, which means the width of the screen is 800 pixels and the height is 480 pixels. So if you wanted to place something on the middle of the screen, you would move 400 pixels from the right of the origin and then go up 240 pixels from the bottom of the screen to place the object at (400, 240).
- ATmega16單片機項目驅動教程
- Windows phone 7.5 application development with F#
- 3ds Max Speed Modeling for 3D Artists
- 從零開始學51單片機C語言
- 電腦維護365問
- 計算機組裝與維修技術
- Practical Machine Learning with R
- 深入理解序列化與反序列化
- 單片機技術及應用
- RISC-V處理器與片上系統設計:基于FPGA與云平臺的實驗教程
- IP網絡視頻傳輸:技術、標準和應用
- Arduino項目案例:游戲開發
- 微服務實戰(Dubbox +Spring Boot+Docker)
- 微服務實戰
- 筆記本電腦的結構、原理與維修