doc
parent
2e9cdc2c58
commit
0588b17389
Binary file not shown.
After Width: | Height: | Size: 267 KiB |
|
@ -0,0 +1,34 @@
|
||||||
|
[remap]
|
||||||
|
|
||||||
|
importer="texture"
|
||||||
|
type="StreamTexture"
|
||||||
|
path="res://.import/pixel.jpg-9d6064018f1a1e5ef0964994fe2aa119.stex"
|
||||||
|
metadata={
|
||||||
|
"vram_texture": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[deps]
|
||||||
|
|
||||||
|
source_file="res://doc/demo05_scene_node/image/pixel.jpg"
|
||||||
|
dest_files=[ "res://.import/pixel.jpg-9d6064018f1a1e5ef0964994fe2aa119.stex" ]
|
||||||
|
|
||||||
|
[params]
|
||||||
|
|
||||||
|
compress/mode=0
|
||||||
|
compress/lossy_quality=0.7
|
||||||
|
compress/hdr_mode=0
|
||||||
|
compress/bptc_ldr=0
|
||||||
|
compress/normal_map=0
|
||||||
|
flags/repeat=0
|
||||||
|
flags/filter=true
|
||||||
|
flags/mipmaps=false
|
||||||
|
flags/anisotropic=false
|
||||||
|
flags/srgb=2
|
||||||
|
process/fix_alpha_border=true
|
||||||
|
process/premult_alpha=false
|
||||||
|
process/HDR_as_SRGB=false
|
||||||
|
process/invert_color=false
|
||||||
|
stream=false
|
||||||
|
size_limit=0
|
||||||
|
detect_3d=true
|
||||||
|
svg/scale=1.0
|
|
@ -1,4 +1,4 @@
|
||||||
# 1. 深入坐标系
|
# 1. 屏幕坐标
|
||||||
|
|
||||||
![Image text](image/坐标系.png)
|
![Image text](image/坐标系.png)
|
||||||
![Image text](image/坐标系-godot-1.png)
|
![Image text](image/坐标系-godot-1.png)
|
||||||
|
@ -17,6 +17,30 @@ unity的2d坐标系虽然在左下角,但是unity的屏幕坐标系依然在
|
||||||
因为单论平面内容制作,左上原点更符合视觉习惯,也更符合设计常识,比如ps。
|
因为单论平面内容制作,左上原点更符合视觉习惯,也更符合设计常识,比如ps。
|
||||||
```
|
```
|
||||||
|
|
||||||
|
- 世界坐标系:又称为全局坐标系,以场景树的root节点为坐标系原点
|
||||||
|
- 相对坐标系:又称为局部坐标系或者本地坐标系,相对于父节点的坐标,godot的坐标都是相对坐标
|
||||||
|
- 屏幕坐标:屏幕的左上角为坐标系原点
|
||||||
|
|
||||||
|
|
||||||
|
- 屏幕分辨率,屏幕分辨率是指纵横向上的像素点数,单位是px,4:3 是最常见屏幕比例
|
||||||
|
![Image text](image/pixel.jpg)
|
||||||
|
|
||||||
|
|
||||||
|
- 屏幕像素和图片像素有什么关系
|
||||||
|
|
||||||
|
```
|
||||||
|
在屏幕显示图片时,如果屏幕的长宽比、像素数和图片一致,只需要每个屏幕像素用子像素的敏感组合表示出图片上的像素就可以了。
|
||||||
|
那如果图片像素数和屏幕像素数不一样呢?
|
||||||
|
|
||||||
|
当图片像素大于屏幕像素时,屏幕也是进行合并显示的。
|
||||||
|
比如一张1200W像素的图片,要在300W像素的显示器(长宽比一致)上显示,那么系统就需要将图片像素进行四合一计算然后再显示。
|
||||||
|
当图片像素数大于屏幕像素数时,高像素图片和低像素图片的显示精细度是一样的!
|
||||||
|
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
- 在godot中,一般position的1个单位长度等于1个图片像素
|
||||||
|
|
||||||
# 2. 全局和相对坐标的相互转化
|
# 2. 全局和相对坐标的相互转化
|
||||||
|
|
||||||
- 全局坐标和局部坐标(相对坐标)可以相互转化
|
- 全局坐标和局部坐标(相对坐标)可以相互转化
|
||||||
|
|
|
@ -8,32 +8,32 @@ script = ExtResource( 2 )
|
||||||
|
|
||||||
[node name="icon" type="Sprite" parent="."]
|
[node name="icon" type="Sprite" parent="."]
|
||||||
modulate = Color( 0.964706, 0.0313726, 0.0313726, 1 )
|
modulate = Color( 0.964706, 0.0313726, 0.0313726, 1 )
|
||||||
position = Vector2( -470.777, 240.836 )
|
position = Vector2( -512, 300 )
|
||||||
texture = ExtResource( 1 )
|
texture = ExtResource( 1 )
|
||||||
|
|
||||||
[node name="icon2" type="Sprite" parent="."]
|
[node name="icon2" type="Sprite" parent="."]
|
||||||
modulate = Color( 0.882353, 0.796078, 0.0901961, 1 )
|
modulate = Color( 0.882353, 0.796078, 0.0901961, 1 )
|
||||||
position = Vector2( 713.424, 294.807 )
|
position = Vector2( 512, 300 )
|
||||||
texture = ExtResource( 1 )
|
texture = ExtResource( 1 )
|
||||||
|
|
||||||
[node name="icon3" type="Sprite" parent="."]
|
[node name="icon3" type="Sprite" parent="."]
|
||||||
modulate = Color( 0.0588235, 0.152941, 0.584314, 1 )
|
modulate = Color( 0.0588235, 0.152941, 0.584314, 1 )
|
||||||
position = Vector2( -469.983, 848.017 )
|
position = Vector2( -512, 900 )
|
||||||
texture = ExtResource( 1 )
|
texture = ExtResource( 1 )
|
||||||
|
|
||||||
[node name="icon4" type="Sprite" parent="."]
|
[node name="icon4" type="Sprite" parent="."]
|
||||||
modulate = Color( 0.0705882, 0.92549, 0.666667, 1 )
|
modulate = Color( 0.0705882, 0.92549, 0.666667, 1 )
|
||||||
position = Vector2( 733.267, 888.495 )
|
position = Vector2( 512, 900 )
|
||||||
texture = ExtResource( 1 )
|
texture = ExtResource( 1 )
|
||||||
|
|
||||||
[node name="Camera2D1" type="Camera2D" parent="."]
|
[node name="Camera2D1" type="Camera2D" parent="."]
|
||||||
position = Vector2( -514.899, 305.125 )
|
position = Vector2( -512, 300 )
|
||||||
|
|
||||||
[node name="Camera2D2" type="Camera2D" parent="."]
|
[node name="Camera2D2" type="Camera2D" parent="."]
|
||||||
position = Vector2( 509.602, 305.125 )
|
position = Vector2( 512, 300 )
|
||||||
|
|
||||||
[node name="Camera2D3" type="Camera2D" parent="."]
|
[node name="Camera2D3" type="Camera2D" parent="."]
|
||||||
position = Vector2( -511.721, 903.722 )
|
position = Vector2( -512, 900 )
|
||||||
|
|
||||||
[node name="Camera2D4" type="Camera2D" parent="."]
|
[node name="Camera2D4" type="Camera2D" parent="."]
|
||||||
position = Vector2( 513.839, 898.425 )
|
position = Vector2( 512, 900 )
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
extends Sprite
|
extends Sprite
|
||||||
|
|
||||||
|
const StringUtils = preload("res://zfoo/util/StringUtils.gd")
|
||||||
|
|
||||||
|
|
||||||
var gameWidth: int
|
var gameWidth: int
|
||||||
var gameHeight: int
|
var gameHeight: int
|
||||||
|
@ -9,11 +11,23 @@ var spriteHeight: int
|
||||||
|
|
||||||
|
|
||||||
func _enter_tree():
|
func _enter_tree():
|
||||||
|
windowPositionTest()
|
||||||
# textureTest()
|
# textureTest()
|
||||||
# positionTest()
|
# positionTest()
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
# 屏幕坐标系
|
||||||
|
func windowPositionTest():
|
||||||
|
print(StringUtils.format("屏幕大小[{}]", [OS.window_size]))
|
||||||
|
print(StringUtils.format("屏幕位置[{}]", [OS.window_position]))
|
||||||
|
|
||||||
|
OS.window_position = Vector2(100, 100)
|
||||||
|
# OS.window_fullscreen = true
|
||||||
|
print(get_global_transform_with_canvas().get_origin())
|
||||||
|
print(global_position)
|
||||||
|
pass
|
||||||
|
|
||||||
# 坐标点测试用例
|
# 坐标点测试用例
|
||||||
func positionTest():
|
func positionTest():
|
||||||
print(position)
|
print(position)
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
extends Node2D
|
extends Node2D
|
||||||
|
|
||||||
|
const StringUtils = preload("res://zfoo/util/StringUtils.gd")
|
||||||
|
|
||||||
var camera1: Camera2D
|
var camera1: Camera2D
|
||||||
var camera2: Camera2D
|
var camera2: Camera2D
|
||||||
var camera3: Camera2D
|
var camera3: Camera2D
|
||||||
|
@ -15,14 +17,14 @@ func _ready() -> void:
|
||||||
|
|
||||||
|
|
||||||
func _physics_process(delta: float) -> void:
|
func _physics_process(delta: float) -> void:
|
||||||
timerCounter += delta
|
timerCounter += 1
|
||||||
if(int(timerCounter) == 1):
|
if(timerCounter == 100):
|
||||||
switchCamera1()
|
switchCamera1()
|
||||||
if(int(timerCounter) == 2):
|
if(timerCounter == 200):
|
||||||
switchCamera2()
|
switchCamera2()
|
||||||
if(int(timerCounter) == 3):
|
if(timerCounter == 300):
|
||||||
switchCamera3()
|
switchCamera3()
|
||||||
if(int(timerCounter) == 4):
|
if(timerCounter == 400):
|
||||||
switchCamera4()
|
switchCamera4()
|
||||||
timerCounter = 0
|
timerCounter = 0
|
||||||
|
|
||||||
|
@ -30,12 +32,24 @@ func _physics_process(delta: float) -> void:
|
||||||
|
|
||||||
func switchCamera1() -> void:
|
func switchCamera1() -> void:
|
||||||
camera1.current = true;
|
camera1.current = true;
|
||||||
|
print("camera1---------------------------")
|
||||||
|
postionTest()
|
||||||
|
|
||||||
func switchCamera2() -> void:
|
func switchCamera2() -> void:
|
||||||
camera2.current = true;
|
camera2.current = true;
|
||||||
|
print("camera2---------------------------")
|
||||||
|
postionTest()
|
||||||
|
|
||||||
func switchCamera3() -> void:
|
func switchCamera3() -> void:
|
||||||
camera3.current = true;
|
camera3.current = true;
|
||||||
|
print("camera3---------------------------")
|
||||||
|
postionTest()
|
||||||
|
|
||||||
func switchCamera4() -> void:
|
func switchCamera4() -> void:
|
||||||
camera4.current = true;
|
camera4.current = true;
|
||||||
|
print("camera4---------------------------")
|
||||||
|
postionTest()
|
||||||
|
|
||||||
|
func postionTest():
|
||||||
|
print(StringUtils.format("全局坐标[{}]", [$icon.global_position]))
|
||||||
|
print(StringUtils.format("屏幕坐标[{}]", [$icon.get_global_transform_with_canvas().get_origin()]))
|
||||||
|
|
Loading…
Reference in New Issue