pull/2/head
jaysunxiao 2022-01-22 14:05:17 +08:00
parent 2e9cdc2c58
commit 0588b17389
6 changed files with 100 additions and 14 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 267 KiB

View File

@ -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

View File

@ -1,4 +1,4 @@
# 1. 深入坐标系
# 1. 屏幕坐标
![Image text](image/坐标系.png)
![Image text](image/坐标系-godot-1.png)
@ -17,6 +17,30 @@ unity的2d坐标系虽然在左下角但是unity的屏幕坐标系依然在
因为单论平面内容制作左上原点更符合视觉习惯也更符合设计常识比如ps。
```
- 世界坐标系又称为全局坐标系以场景树的root节点为坐标系原点
- 相对坐标系又称为局部坐标系或者本地坐标系相对于父节点的坐标godot的坐标都是相对坐标
- 屏幕坐标:屏幕的左上角为坐标系原点
- 屏幕分辨率屏幕分辨率是指纵横向上的像素点数单位是px4:3 是最常见屏幕比例
![Image text](image/pixel.jpg)
- 屏幕像素和图片像素有什么关系
```
在屏幕显示图片时,如果屏幕的长宽比、像素数和图片一致,只需要每个屏幕像素用子像素的敏感组合表示出图片上的像素就可以了。
那如果图片像素数和屏幕像素数不一样呢?
当图片像素大于屏幕像素时,屏幕也是进行合并显示的。
比如一张1200W像素的图片要在300W像素的显示器长宽比一致上显示那么系统就需要将图片像素进行四合一计算然后再显示。
当图片像素数大于屏幕像素数时,高像素图片和低像素图片的显示精细度是一样的!
```
- 在godot中一般position的1个单位长度等于1个图片像素
# 2. 全局和相对坐标的相互转化
- 全局坐标和局部坐标(相对坐标)可以相互转化

View File

@ -8,32 +8,32 @@ script = ExtResource( 2 )
[node name="icon" type="Sprite" parent="."]
modulate = Color( 0.964706, 0.0313726, 0.0313726, 1 )
position = Vector2( -470.777, 240.836 )
position = Vector2( -512, 300 )
texture = ExtResource( 1 )
[node name="icon2" type="Sprite" parent="."]
modulate = Color( 0.882353, 0.796078, 0.0901961, 1 )
position = Vector2( 713.424, 294.807 )
position = Vector2( 512, 300 )
texture = ExtResource( 1 )
[node name="icon3" type="Sprite" parent="."]
modulate = Color( 0.0588235, 0.152941, 0.584314, 1 )
position = Vector2( -469.983, 848.017 )
position = Vector2( -512, 900 )
texture = ExtResource( 1 )
[node name="icon4" type="Sprite" parent="."]
modulate = Color( 0.0705882, 0.92549, 0.666667, 1 )
position = Vector2( 733.267, 888.495 )
position = Vector2( 512, 900 )
texture = ExtResource( 1 )
[node name="Camera2D1" type="Camera2D" parent="."]
position = Vector2( -514.899, 305.125 )
position = Vector2( -512, 300 )
[node name="Camera2D2" type="Camera2D" parent="."]
position = Vector2( 509.602, 305.125 )
position = Vector2( 512, 300 )
[node name="Camera2D3" type="Camera2D" parent="."]
position = Vector2( -511.721, 903.722 )
position = Vector2( -512, 900 )
[node name="Camera2D4" type="Camera2D" parent="."]
position = Vector2( 513.839, 898.425 )
position = Vector2( 512, 900 )

View File

@ -1,5 +1,7 @@
extends Sprite
const StringUtils = preload("res://zfoo/util/StringUtils.gd")
var gameWidth: int
var gameHeight: int
@ -9,11 +11,23 @@ var spriteHeight: int
func _enter_tree():
windowPositionTest()
# textureTest()
# positionTest()
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():
print(position)

View File

@ -1,5 +1,7 @@
extends Node2D
const StringUtils = preload("res://zfoo/util/StringUtils.gd")
var camera1: Camera2D
var camera2: Camera2D
var camera3: Camera2D
@ -15,14 +17,14 @@ func _ready() -> void:
func _physics_process(delta: float) -> void:
timerCounter += delta
if(int(timerCounter) == 1):
timerCounter += 1
if(timerCounter == 100):
switchCamera1()
if(int(timerCounter) == 2):
if(timerCounter == 200):
switchCamera2()
if(int(timerCounter) == 3):
if(timerCounter == 300):
switchCamera3()
if(int(timerCounter) == 4):
if(timerCounter == 400):
switchCamera4()
timerCounter = 0
@ -30,12 +32,24 @@ func _physics_process(delta: float) -> void:
func switchCamera1() -> void:
camera1.current = true;
print("camera1---------------------------")
postionTest()
func switchCamera2() -> void:
camera2.current = true;
print("camera2---------------------------")
postionTest()
func switchCamera3() -> void:
camera3.current = true;
print("camera3---------------------------")
postionTest()
func switchCamera4() -> void:
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()]))